C++14 regex_search 0 matches - c++

I am trying to match a regex in a website that I scrape using curl, this is my code:
#include <regex>
#include "curl_easy.h"
#include "curl_form.h"
int main(int argc, const char **argv) {
std::ostringstream response;
curl::curl_ios<std::ostringstream> writer (response);
curl::curl_easy easy(writer);
// Add some option to the curl_easy object.
easy.add<CURLOPT_SSL_VERIFYHOST>(false);
easy.add<CURLOPT_SSL_VERIFYPEER>(false);
easy.add<CURLOPT_URL>("https://minecraft.net/login");
easy.add<CURLOPT_FOLLOWLOCATION>(1L);
try {
// Execute the request.
easy.perform();
} catch (curl::curl_easy_exception error) {
// If you want to get the entire error stack we can do:
curl::curlcpp_traceback errors = error.get_traceback();
// Otherwise we could print the stack like this:
error.print_traceback();
// Note that the printing the stack will erase it
}
std::regex pattern("alue=\"\\w{40}");
const char* responseArray = response.str().c_str();
std::cout << response.str();
std::smatch match;
if(std::regex_search(responseArray, pattern)){
std::cout << "Found the proper value!" << std::endl;
} else {
std::cout << "Did not find the proper value" << std::endl;
}
return 0;
}
The response that I get when printing the response is this:
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Minecraft</title>
<meta name="description" content="Minecraft is a game about placing blocks to build anything you can imagine. At
night monsters come out, make sure to build a shelter before that happens.">
<meta name="author" content="Mojang AB">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.png">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="/stylesheets/style.css?b=b_965">
<link rel="stylesheet" media="handheld" href="/stylesheets/handheld.css?b=b_965">
<!--[if !IE 7]>
<style type="text/css">
#wrap {display:table;height:100%}
</style>
<![endif]-->
<script src="/javascripts/libs/modernizr.min.js"></script>
<script>
function recordOutboundLink(link, category, action, label, value) {
try {
ga('send', 'event', category, action, label, value);
setTimeout('document.location = "' + link.href + '"', 100);
}catch(err){}
}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-9482675-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="wrap">
<header>
<div id="header_container" class="clearfix">
<a id="logo" href="/">Minecraft</a>
<ul id="menu">
<li>Home</li>
<li>
Game
<ul>
<li>What is Minecraft?</li>
<li>Getting started</li>
<li>Credits</li>
</ul>
</li>
<li>Community</li>
<li>Store</li>
<li>Profile</li>
<li>Help</li>
</ul>
<div id="userbox">
<span class="logged-out"><a href="/login" >Log i
n</a> | <a href="/register" onclick="recordOutboundLink(this, 'Sales2', 'Purchase-interest', 'Register-link')">Register<
/a></span>
</div>
</div>
</header>
<noscript>
<div id="javascript-warning" class="warning warning-yellow">
Please, please enable JavaScript to use this site.
</div>
</noscript>
<div id="main" role="main" class="clearfix controller-Secure action-login">
<h1>Login</h1>
<div id="login">
<h1></h1>
<form action="https://minecraft.net/login" method="post" accept-charset="utf-8" enctype="application/x-www-form-urle
ncoded" id="loginForm" class="spacious" id="loginForm" class="spacious"><input type="hidden" name="authenticityToken" v
alue="d2edcaa6bcc0fb19bf299b381212f59a194b8884">
<p>When logging in with a Mojang account, use your e-mail address as username.</p>
<p id="username-field">
<label for="username">Username:</label>
<input tabindex="1" type="text" name="username" id="username" value="" />
Forgot username?
</p>
<p id="password-field">
<label for="password">Password:</label>
<input tabindex="2" type="password" name="password" id="password" value="" />
Forgot password?
</p>
<p id="remember-field">
<input type="checkbox" name="remember" id="remember" value="true" />
<label for="remember">Remember me</label>
</p>
<p id="signin-field">
<input type="submit" id="signin" value="Sign in" />
</p>
</form></div>
</div>
</div>
<footer>
Mojang © 2009-. "Minecraft" is a trademark of Mojang Synergies AB — <a href="/terms">Terms of Use
</a> — Privacy Policy — b_965 r_bb50ffaf2f187302eb1bb
937f03df44f30b7d465
</footer>
<script src="/javascripts/libs/json2.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="/javascripts/libs/jquery-1.5.1.min.js"%3E%3C/s
cript%3E'))</script>
<script src="/javascripts/libs/jquery.dataTables.min.js"></script>
<script src="/javascripts/libs/jquery.timeago.js"></script>
<script src="/javascripts/jquery.scrollTo-1.4.2-min.js?b=b_965"></script>
<script src="/javascripts/plugins.js?b=b_965"></script>
<script src="/javascripts/main.js?b=b_965"></script>
</body>
</html>
When I run this code I always get the "Did not find the proper value!" output. But if I run the same regex through regexr I have no issues at all and it manages to find one match.
The match I am looking for in this case is:
alue="d2edcaa6bcc0fb19bf299b381212f59a194b8884
What am I doing wrong here?

const char* responseArray = response.str().c_str(); — binds responseArray to temporary value. String returned by str() is destroyed after this expression.
Better solution will save results in std::string and use it:
std::string responseArray = response.str();
std::cout << responseArray;
std::smatch match;
if(std::regex_search(responseArray, pattern)){
std::cout << "Found the proper value!" << std::endl;
} else {
std::cout << "Did not find the proper value" << std::endl;
}

Related

Issue with marking of checkboxes in the list of items

I have a Vue app: it is To Do List, where after adding some notes by clicking button Add Task we receive a list of items to do. On the front of each item we have button Delete and checkbox to have opportunity to mark it as done. The bug is when I for example mark one of the items in the list as checked and after that delete it-marker that it was checked goes to the other item which was not marked as checked initially. Can you please advice how it can be solved using Vue.js or any other option? Below is my code:
Vue.createApp({
data(){
return{
placeholder: 'Start typing',
inputvalue: '',
notes: []
}
},
mounted() {
this.notes = JSON.parse(localStorage.getItem('note')) || [];
},
watch: {
notes: {
handler: function() {
localStorage.setItem('note', JSON.stringify(this.notes));
},
deep: true
}
},
methods: {
addnewtask(){
if (this.inputvalue !== ''){
this.notes.push(this.inputvalue)
this.inputvalue=''
}
},
removetask(index){
if (confirm('Do you really want to delete?'))
this.notes.splice(index, 1)
}
}
}).mount(app)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To Do List</title>
</head>
<link rel="stylesheet" href="style.css">
<body>
<div class="container" id="app">
<div class="card">
<h1>To Do List</h1>
<div class="form-control">
<input
type="text"
v-bind:placeholder="placeholder"
v-model="inputvalue"
v-on:keypress.enter="addnewtask"
/>
<button class="btn" v-on:click="addnewtask">Add Task</button>
</div>
<hr />
<ul class="list" v-if="notes.length !== 0"...>
<li class="list-item" v-for="(note, index) in notes">
<div>
<input type="checkbox"/>
({{index+1}}) {{note}}
</div>
<button class="btn danger" v-on:click="removetask(index)">Delete</button>
</li>
<hr />
<li>
<strong>Total: {{notes.length}}</strong>
</li>
</ul>
<div v-else>No task exist, please add first one.</div>
</div>
</div>
<script src="https://unpkg.com/vue#next"></script>
<script src="Vue3.js"></script>
</body>
</html>
The main issue in you code is, you don't store any information about which task is checked and which one is not.let's say you checked 3rd task and then delete it, the new 3rd item from the top will be auto checked as it has no information about the task so can't differentiate between the new and the deleted task.
This can be solved many way one easy solution is, in your notes array store two types of data. One title and one is isChecked then v-model the checked value in template.
Update your addnewtask() function like this,
addnewtask() {
if (this.inputvalue !== "") {
this.notes.push({
title: this.inputvalue,
isChecked: false,
});
this.inputvalue = "";
}
},
In html use a v-modal to add a two way data binding for the note.isChecked and update note like note.title since note is currently an object now.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>To Do List</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<div class="container" id="app">
<div class="card">
<h1>To Do List</h1>
<div class="form-control">
<input
type="text"
v-bind:placeholder="placeholder"
v-model="inputvalue"
v-on:keypress.enter="addnewtask"
/>
<button class="btn" v-on:click="addnewtask">Add Task</button>
</div>
<hr />
<ul class="list" v-if="notes.length !== 0" ...>
<li class="list-item" v-for="(note, index) in notes">
<div>
<input type="checkbox" v-model="note.isChecked" />
({{index+1}}) {{note.title}}
</div>
<button class="btn danger" v-on:click="removetask(index)">
Delete
</button>
</li>
<hr />
<li>
<strong>Total: {{notes.length}}</strong>
</li>
</ul>
<div v-else>No task exist, please add first one.</div>
</div>
</div>
<script src="https://unpkg.com/vue#next"></script>
<script src="Vue3.js"></script>
</body>
</html>
Here is a vue playgroud link for your code demo.

how to send data from the view to the header or the navigationBar

I have a Django website that has a navigation bar where I need to display the user and the group that the user belongs to in the navigation bar in order to make this information visible on all pages.
Until now I am able to send these data items to a specific page but not to the header.
views.py
def home(request):
#print(User.groups.get())
print(request.session.keys())
if request.session.has_key('theUser'):
authed=request.session['theUser']
if request.session.has_key('group'):
sections=request.session['group']
return render(request,'./mainpage.html',{'sections':sections,'authed':authed})
else:
authed=None
else:
authed=None
return render(request,'./Login.html',{'authed':authed})
Where I am sending {'sections':sections,'authed':authed}
to mainpage.html
mainpage.html
<div id='left-column-Input' class="formInput" include="select()">
{{user.get_username}}|{{sections}}
What I need is to send the data to the header or the base file.
base.html
<!DOCTYPE html>
{% load static %}
<html>
<head>
<script type="text/javascript" src="{% static '/js/jquery-3.1.1.min.js' %}"></script>
<link rel= "icon" type= "image/png" href="{% static 'img/logo_title/icon-AddressBar.png'%}">
<link rel="stylesheet" type="text/css" href="{% static '/css/search.css'%}">
<link rel="stylesheet" type="text/css" href="{% static '/css/style.css'%}">
</head>
<body>
<img class="logoMM" src="{% static 'img/logoMM.png' %}" alt="Smiley face" />
<!-- <div class="wrap"> -->
<div class="wrap search Horizontal-scale">
<!-- <div class="Horizontal-scale"> -->
<button type="submit" class="searchButton">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="search" role="img" viewBox="0 -20 530 530"><path fill="currentColor" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"></path></svg>
</button>
<input type="text" class="searchTerm" placeholder="search">
<!-- <div class="Horizontal-scale"> -->
<label for="toggle">☰</label>
<input type="checkbox" id="toggle"/>
<div id="container" class="Horizontal-menu">
<ul>
<li>main</li>
<li>search</li>
{% if authed is not None %}
<li>logout</li>
<script type="text/javascript">
$(function(){
$('#logMeOut').on('click',function(){
$.ajax({
url:'/usr/logMeOut',
method:'POST',
headers:{
'X-CSRFToken':'{{csrf_token}}'
}
}).done(function(msg){
console.log(msg)
document.location='/'
}).fail(function(err){
alert(err)
})
})
})
</script>
{% endif %} </th>
</ul>
</div>
</body>
{% block body %}
{% endblock %}
</html>

Failed to instantiate module in application ionic 2

I make a simple application Ionic 2 but I find a problem that exists year screenshot
code index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link rel="manifest" href="manifest.json">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic/js/angular-ui/angular-ui-router.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- script home.js -->
<script src="js/home.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="myApp">
<ion-pane>
<!-- <ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content>
</ion-content> --><div ng-view></div>
</ion-pane>
</body>
</html>
code home.html
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>AngularJS & Firebase Web App</title>
<link rel="icon" href="http://getbootstrap.com/favicon.ico">
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/signin/signin.css" rel="stylesheet">
<link href="justified-nav.css" rel="stylesheet">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->
<link href="../lib/ionic/css/ionic.css" rel="stylesheet">
<script src="lib/ionic/js/angular-ui/angular-ui-router.js"></script>
<link href="../css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="../lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="../js/app.js"></script>
</head>
<body>
<div class="container">
<div class="jumbotron" style="padding-bottom:0px;">
<h2>AngularJS & Firebase App!</h2>
</div>
<form class="form-signin" role="form">
<input type="email" class="form-control" placeholder="Email address" required="" autofocus="">
<input type="password" class="form-control" placeholder="Password" required="">
<label class="checkbox">
Sign Up
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
</body></html>
code home.js
var app = angular.module('home', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/home', { templateUrl : 'templates/home.html',controller: 'HomeCtrl' });
}])
app.controller('HomeCtrl', [function() {
}]);
code app.js
angular.module('myApp', ['ionic','home'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.otherwise({ redirectTo: '/home' });
}]);
I added ngRoute in js files but same problem

data bind password pattern not working with paper-input

I am trying to get password pattern work with data binding. In the below jsbin, the password Pass5678 is accepted when the pattern is provided in the html. However when I bind the pattern using a property that password fails
http://jsbin.com/posojodozu/edit?html,output
code:
<!doctype html>
<head>
<meta charset="utf-8">
<base href="http://polymer-magic-server.appspot.com/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import">
<link href="iron-form/iron-form.html" rel="import">
<link href="paper-input/paper-input.html" rel="import">
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<x-example></x-example>
<dom-module id="x-example">
<style>
:host {
display: block;
padding: 36px;
}
</style>
<template>
<form is="iron-form"
id="form"
disable-native-validation-ui
action="/">
<paper-input
name="password"
required
type="password"
pattern="[[passwordPattern]]"
label="Enter Password"></paper-input>
<br>
<button type="submit">SUBMIT</button>
</form>
</template>
<script>
// only need this when both (1) in the main document and (2) on non-Chrome browsers
addEventListener('WebComponentsReady', function() {
Polymer({
is: 'x-example',
properties: {
passwordPattern: {
type: String,
value: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}'
}
}
});
});
</script>
</dom-module>
</body>
Looks like slash is got stripped somehow, so value should be:
value: '(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}'

Cookies Drive Me CrazZy! ASP - VB Script

I'm trying to work these cookies so once the user/pass is correct it will start a cookie for the user to always show the username when logging back in (remember me feature).
While this code gave the "usernameCookie" value when I checked it at the same page, it didn't pass it to the next one. It's like it doesn't exist anymore. Of course, I used buffer=true but this is driving me crazy why it doesn't work.
<%# language="VBscript"%>
<% response.buffer = True %>
<!-- #include file = "ddsn.asp" -->
<!-- #include file = "sfuncs.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<!--Initiate form validation - in this example on the login form-->
<script type="text/javascript">
$(document).ready(function() {
$("#loginform").validate();
});
</script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
msg = ""
If request.form ("password") <> "" Then
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "Select id,firstName,lastName,username,password,permissions,status FROM dispatchersTBL WHERE username='" & request.form ("username") & "' and password='" & request.form ("password") & "'"
If inStr(1,SQL,";") or inStr(1,SQL,"''") OR inStr(1,LCase(SQL)," or ") Then msg = "<strong>Wrong Username or Password</strong>" End If
rs.Open SQL,SQLDSN,3,1
If NOT rs.EOF Then
Session("login") = "True"
Session("loggedUserID") = rs("id")
Session("fullName") = rs("firstName") & " " & rs("lastName")
Session("permissions") = rs("permissions")
status = rs("status")
Session.Timeout = 1440
If status = "Inactive" Then
msg = "<p><strong>Inactive User. Please contact the administrator.</strong></p>"
Else
response.cookies("usernameCookie") = rs("username")
response.cookies("passwordCookie") = rs("password")
response.cookies("usernameCookie").expires = Date() + 30
response.cookies("passwordCookie").expires = Date() + 30
response.redirect adminSiteURL & "co-worker-sms.asp"
End If
Else
msg = "<p><strong>Wrong Username or Password</strong></p>"
End if
rs.Close
Set rs = Nothing
End if
%>
<div id="admin_wrapper">
<form action="default.asp" id="login" method="post">
<%=msg%>
<!-- TEXTBOXES -->
<label>Username</label><br />
<input name="username" type="text" value="<%=request.cookies("usernameCookie")%>" class="text large required" id="username" /><br />
<div class="clearfix"> </div>
<label>Password</label><br />
<input name="password" type="password" value="<%=request.cookies("passwordCookie")%>" class="text large required" id="password" /><br />
<div class="clearfix"> </div>
<p><input name="btnLogin" type="submit" class="submit" id="btnLogin" value="LOGIN" /></p>
</form>
</div>
</body>
</html>
What am I missing?
I haven't seen your login page but your code seems ok - are you sure you do the request.cookies when you try to retrieve it ?
try make a simple page like this
<%
' put cookie
Response.Cookies("usernameCookie") = "Superman"
Response.Cookies("usernameCookie").Expires = Date() + 10
Response.Cookies("passwordCookie") = "Batman"
response.Cookies("passwordCookie").Expires = Date() + 10
%>
<% ' Print my cookie %>
<input type="text" value="<% = request.cookies("usernameCookie") %>" name="username">
<br />
<input type="text" value="<% = request.cookies("passwordCookie") %>" name="password">
After a reload page your input fields should have "superman" an "batman"