Skip to content

Commit

Permalink
beginning of Magick link implementation from issue sahat#998
Browse files Browse the repository at this point in the history
  • Loading branch information
Tubaleviao committed Oct 29, 2020
1 parent d477880 commit 628b336
Show file tree
Hide file tree
Showing 5 changed files with 9,199 additions and 44 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ app.use('/webfonts', express.static(path.join(__dirname, 'node_modules/@fortawes
app.get('/', homeController.index);
app.get('/login', userController.getLogin);
app.post('/login', userController.postLogin);
app.post('/lomagic', userController.postLoginMagic);
app.get('/logout', userController.logout);
app.get('/forgot', userController.getForgot);
app.post('/forgot', userController.postForgot);
app.get('/reset/:token', userController.getReset);
app.post('/reset/:token', userController.postReset);
app.get('/signup', userController.getSignup);
app.post('/signup', userController.postSignup);
app.post('/magic', userController.postSignupMagic);
app.get('/contact', contactController.getContact);
app.post('/contact', contactController.postContact);
app.get('/account/verify', passportConfig.isAuthenticated, userController.getVerifyEmail);
Expand Down
42 changes: 36 additions & 6 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,8 @@ exports.postSignup = (req, res, next) => {
}
user.save((err) => {
if (err) { return next(err); }
req.logIn(user, (err) => {
if (err) {
return next(err);
}
res.redirect('/');
});
req.flash('success', {msg: 'An email with the authentication link was sent.'})

});
});
};
Expand Down Expand Up @@ -386,6 +382,40 @@ exports.getVerifyEmail = (req, res, next) => {
.catch(next);
};

/**
* POST /lomagic
* Send login email
*/

exports.postLoginMagic = (req, res, next) => {
const validationErrors = [];
if (!validator.isEmail(req.body.email)) validationErrors.push({ msg: 'Please enter a valid email address.' });

req.body.email = validator.normalizeEmail(req.body.email, { gmail_remove_dots: false });

req.flash('errors', {msg: 'Not implemented yet'});
return res.redirect('/login');
};

/**
* POST /magic
* Send signup email
*/

exports.postSignupMagic = (req, res, next) => {
const validationErrors = [];
if (!validator.isEmail(req.body.email)) validationErrors.push({ msg: 'Please enter a valid email address.' });

if (validationErrors.length) {
req.flash('errors', validationErrors);
return res.redirect('/signup');
}
req.body.email = validator.normalizeEmail(req.body.email, { gmail_remove_dots: false });

req.flash('errors', {msg: 'Not implemented yet'});
return res.redirect('/signup');
};

/**
* POST /reset/:token
* Process the reset password request.
Expand Down
Loading

0 comments on commit 628b336

Please sign in to comment.