Skip to content

Commit

Permalink
Added front end for paswordless feature 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 59e2edb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 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
34 changes: 34 additions & 0 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,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
13 changes: 13 additions & 0 deletions views/account/login.pug
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
extends ../layout

block content
.pb-2.mt-2.mb-4.border-bottom
h3 Sign in with Magic Link
form(method='POST', action='/lomagic')
input(type='hidden', name='_csrf', value=_csrf)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='email') Email
.col-md-7
input.form-control(type='email', name='email', id='magic-email', placeholder='Email', autofocus, autocomplete='email', required)
.form-group
.offset-md-3.col-md-7.pl-2
button.col-md-3.btn.btn-primary(type='submit')
i.far.fa-user.fa-sm
| Login
.pb-2.mt-2.mb-4.border-bottom
h3 Sign in
form(method='POST')
Expand Down
55 changes: 35 additions & 20 deletions views/account/signup.pug
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
extends ../layout

block content
.pb-2.mt-2.mb-4.border-bottom
h3 Sign up
form(id='signup-form', method='POST')
input(type='hidden', name='_csrf', value=_csrf)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='email') Email
.col-md-7
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, autocomplete='email', required)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='password') Password
.col-md-7
input.form-control(type='password', name='password', id='password', placeholder='Password', autocomplete='new-password', minlength='8', required)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='confirmPassword') Confirm Password
.col-md-7
input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password', autocomplete='new-password', minlength='8', required)
.form-group.offset-sm-3.col-md-7.pl-2
button.btn.btn-success(type='submit')
i.fas.fa-user-plus.fa-sm
| Signup
.row
.col-sm
.pb-2.mt-2.mb-4.border-bottom
h3 Magic Link
form(id='magic-form', method='POST', action='magic')
input(type='hidden', name='_csrf', value=_csrf)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='email') Email
.col-md-7
input.form-control(type='email', name='email', id='magic-email', placeholder='Magic Email', autofocus, autocomplete='email', required)
.form-group.offset-sm-3.col-md-7.pl-2
button.btn.btn-success(type='submit')
i.fas.fa-user-plus.fa-sm
| Signup
.col-sm
.pb-2.mt-2.mb-4.border-bottom
h3 Sign up
form(id='signup-form', method='POST')
input(type='hidden', name='_csrf', value=_csrf)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='email') Email
.col-md-7
input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, autocomplete='email', required)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='password') Password
.col-md-7
input.form-control(type='password', name='password', id='password', placeholder='Password', autocomplete='new-password', minlength='8', required)
.form-group.row
label.col-md-3.col-form-label.font-weight-bold.text-right(for='confirmPassword') Confirm Password
.col-md-7
input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password', autocomplete='new-password', minlength='8', required)
.form-group.offset-sm-3.col-md-7.pl-2
button.btn.btn-success(type='submit')
i.fas.fa-user-plus.fa-sm
| Signup

0 comments on commit 59e2edb

Please sign in to comment.