aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-05-06 22:13:15 +0200
committerMateja <mail@matejamaric.com>2021-05-06 22:13:46 +0200
commit143755e5e8a53eeee9f5b2fa7e3b76866c9673d7 (patch)
tree631f4319d56faea06c76e64728e62cc68162a057 /controllers
parentad5d861561e4f55289d55c61c71c14958659aea4 (diff)
downloadnode-playground-143755e5e8a53eeee9f5b2fa7e3b76866c9673d7.tar.gz
node-playground-143755e5e8a53eeee9f5b2fa7e3b76866c9673d7.zip
Adding new users without validation.
Also set input type to password in `login.handlebars`.
Diffstat (limited to 'controllers')
-rw-r--r--controllers/user.js32
1 files changed, 28 insertions, 4 deletions
diff --git a/controllers/user.js b/controllers/user.js
index e25abf8..54b8161 100644
--- a/controllers/user.js
+++ b/controllers/user.js
@@ -1,8 +1,24 @@
+const User = require('../models/user');
+
module.exports = {
register(req, res) {
- console.log(req.body);
- res.redirect('/register');
+ if (req.body.password === req.body.confirmPassword) {
+ const newUser = new User({
+ firstname: req.body.firstname,
+ lastname: req.body.lastname,
+ email: req.body.email,
+ password: req.body.password
+ });
+ newUser.save().then(() => {
+ req.flash('msg', 'You successfully registered.');
+ res.redirect('/login');
+ });
+ }
+ else {
+ req.flash('msg', 'Validation errors...');
+ res.redirect('/register');
+ }
},
login(req, res) {
@@ -15,11 +31,19 @@ module.exports = {
},
registerView(req, res) {
- res.render('register', {title: 'Register', register: true});
+ res.render('register', {
+ title: 'Register',
+ register: true,
+ msg: req.flash('msg')
+ });
},
loginView(req, res) {
- res.render('login', {title: 'Login', login: true});
+ res.render('login', {
+ title: 'Login',
+ login: true,
+ msg: req.flash('msg')
+ });
}
};