Skip to content
Snippets Groups Projects
Commit 0c46361f authored by Elferink, A.S. (Amber)'s avatar Elferink, A.S. (Amber)
Browse files

Merge branch 'Amber' into 'master'

Amber

See merge request a.s.elferink/fastdiningshop!14
parents a759a8f1 8e69dbb8
No related branches found
No related tags found
No related merge requests found
No preview for this file type
function get(product) {
function register() {
$.ajax({
type: 'POST',
url: '/api/addusername=',
url: '/api/register',
dataType: 'json',
data: {
"firstname": $('#firstname').value,
"surname": $('#surname').value,
"emailaddress": $('#email').value,
"username": $('#username').value,
"password": $('#password').value
"firstname": $('#firstname').val(),
"surname": $('#surname').val(),
"emailaddress": $('#email').val(),
"username": $('#username').val(),
"password": $('#password').val()
}
})
console.log("doet dit het?")
//als deze asynchronous ajax call klaar is, is het of gefaald, of goed gegaan.
//als het goed is gegaan, callt hij de .done hieronder.
.done(function (data) {
console.log(data);
//deze done functie logt het naar de javascript console en print het op de pagina als txt
console.log('GET response:', JSON.stringify(data, "", 2));
$('#getResponse').html(JSON.stringify(data, "", 2));
alert("register succesful, please log in to continue");
window.location.replace("/login");
})
//als het niet goed is gegaan, doet hij de fail hieronder
.fail(function (jqXHR, textStatus, err) {
......
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('register', { title: 'Register', layout: 'layoutRegister', success: false, errors: req.session.errors });
req.session.errors = null;
});
router.post('/submit', function(req, res, next){
req.check('email', 'Invalid email address').isEmail();
req.check('password', 'Invalid password').isLength({min: 4}).equals(req.body.confirmPassword);
var errors = req.validationErrors();
if (errors){
req.session.error = errors;
req.session.succes = false;
} else {
req.session.succes = true;
}
res.redirect('/register')
});
module.exports = router;
\ No newline at end of file
......@@ -50,16 +50,18 @@ function addRegistryToDatabase(callback, registerData) {
db.serialize(function () {
// insert one row into the langs table
db.run(`INSERT INTO Persons(firstname, surname, username, password, emailaddress) VALUES(?, ?, ?, ?, ?)`, [registerData.firstname, registerData.surname, registerData.username, registerData.password, registerData.email], function (err) {
db.run(`INSERT INTO Persons(firstname, surname, username, password, emailaddress) VALUES(?, ?, ?, ?, ?)`, [registerData.firstname, registerData.surname, registerData.username, registerData.password, registerData.emailaddress], function (err) {
if (err) {
return console.log(err.message);
}
// get the last insert id
console.log(`A row has been inserted with rowid ${this.lastID}`);
console.log(registerData);
});
});
db.all("SELECT * FROM Persons", function (err, row) {
console.log(row);
for(var i = 0; i < row.length; i++) {
if (err) {
return callback(err);
......
......@@ -16,22 +16,22 @@
</ul>
</section>
{{/if}}
<form name="login" action="/api/register" method="post">
<section> <!-- form cannot be used since it will place the inserted values in the link. Using action will send user to the link. Instead it is handled with ajax in javascripts/register.js-->
<div class="input">
<label>First Name</label>
<input type="text" id="firstname" name="firstname" placeholder="your first name">
<input type="text" id="firstname" placeholder="your first name">
</div>
<div class="input">
<label>SurName</label>
<input type="text" id="surname" name="surname" placeholder="your surname">
<input type="text" id="surname" placeholder="your surname">
</div>
<div class="input">
<label>Email</label>
<input type="text" id="email" name="email" placeholder="your email address">
<input type="text" id="email" placeholder="your email address">
</div>
<div class="input">
<label>Username</label>
<input type="text" id="username" name="username" placeholder="your login name">
<input type="text" id="username" placeholder="your login name">
</div>
<div class="input">
<label>Password</label>
......@@ -42,6 +42,6 @@
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="confirm your password">
</div>
<button type="submit" >Sign up</button>
</form>
<button onclick="register()">Sign up</button>
</section>
{{/if}}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment