diff --git a/app.js b/app.js index 31436fdf53..333b3b1416 100644 --- a/app.js +++ b/app.js @@ -129,6 +129,7 @@ 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); @@ -136,6 +137,7 @@ 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); diff --git a/controllers/user.js b/controllers/user.js index e18efaf48f..ceb4904a1c 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -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. diff --git a/views/account/login.pug b/views/account/login.pug index 7be22e8528..605b449472 100644 --- a/views/account/login.pug +++ b/views/account/login.pug @@ -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') diff --git a/views/account/signup.pug b/views/account/signup.pug index 094427bc9a..39a8ea172c 100644 --- a/views/account/signup.pug +++ b/views/account/signup.pug @@ -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