2020-04-17 00:59:48 +00:00
|
|
|
const FormController = require('flitter-auth/controllers/Forms')
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handles views and processing for auth registration/login/logout/etc.
|
|
|
|
* Most handlers are inherited from the default flitter-auth/controllers/Forms
|
|
|
|
* controller, however you can override them here as you need.
|
|
|
|
*/
|
|
|
|
class Forms extends FormController {
|
2020-04-22 14:19:25 +00:00
|
|
|
static get services() {
|
2021-05-04 16:28:55 +00:00
|
|
|
return [...super.services, 'Vue', 'models', 'jobs']
|
2020-05-20 14:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async registration_provider_get(req, res, next) {
|
2021-05-04 01:06:51 +00:00
|
|
|
if ( req.session.auth.flow ) {
|
|
|
|
req.session.registrant_flow = req.session.auth.flow
|
|
|
|
}
|
|
|
|
|
2020-05-20 14:56:03 +00:00
|
|
|
return res.page('auth:register', {
|
|
|
|
...this.Vue.data({})
|
|
|
|
})
|
2020-04-22 14:19:25 +00:00
|
|
|
}
|
2020-04-17 00:59:48 +00:00
|
|
|
|
2021-05-04 16:28:55 +00:00
|
|
|
async email_verify_keyaction(req, res, next) {
|
|
|
|
if ( !req.trap.has_trap('verify_email') ) return res.redirect(req.session.email_verify_flow || '/dash/profile')
|
|
|
|
req.user.email_verified = true
|
|
|
|
await req.user.save()
|
|
|
|
await req.trap.end()
|
|
|
|
const url = req.session.email_verify_flow || '/dash/profile'
|
|
|
|
return res.redirect(url)
|
|
|
|
}
|
|
|
|
|
|
|
|
async show_verify_email(req, res, next) {
|
|
|
|
if ( !req.trap.has_trap('verify_email') ) return res.redirect(req.session.email_verify_flow || '/dash/profile')
|
|
|
|
const verify_queue = this.jobs.queue('verifications')
|
|
|
|
await verify_queue.add('SendVerificationEmail', { user_id: req.user.id })
|
|
|
|
|
|
|
|
return res.page('public:message', {
|
|
|
|
...this.Vue.data({
|
|
|
|
message: req.T('auth.must_verify_email'),
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
text: 'Send Verification E-Mail',
|
|
|
|
action: 'redirect',
|
|
|
|
next: '/auth/verify-email/sent',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async send_verify_email(req, res, next) {
|
|
|
|
if ( !req.trap.has_trap('verify_email') ) return res.redirect(req.session.email_verify_flow || '/dash/profile')
|
|
|
|
return res.page('public:message', {
|
|
|
|
...this.Vue.data({
|
|
|
|
message: req.T('auth.verify_email_sent'),
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
text: 'Re-send Verification E-Mail',
|
|
|
|
action: 'redirect',
|
|
|
|
next: '/auth/verify-email/sent',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-04 01:06:51 +00:00
|
|
|
async finish_registration(req, res, next) {
|
|
|
|
if ( req.trap.has_trap() && req.trap.get_trap() === 'registrant_flow' ) await req.trap.end()
|
|
|
|
const dest = req.session.registrant_flow || '/dash/profile'
|
|
|
|
return res.redirect(dest)
|
|
|
|
}
|
|
|
|
|
2020-04-22 14:19:25 +00:00
|
|
|
async login_provider_get(req, res, next) {
|
2020-05-20 14:56:03 +00:00
|
|
|
const Setting = this.models.get('Setting')
|
|
|
|
|
2020-04-22 14:19:25 +00:00
|
|
|
return res.page('auth:login', {
|
|
|
|
...this.Vue.data({
|
2020-05-31 01:16:10 +00:00
|
|
|
login_message: req.session?.auth?.message || req.T('auth.sign_in_to_continue'),
|
2020-05-20 14:56:03 +00:00
|
|
|
registration_enabled: await Setting.get('auth.allow_registration')
|
2020-04-22 14:19:25 +00:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|
2020-04-22 21:56:39 +00:00
|
|
|
|
|
|
|
async logout_provider_present_success(req, res, next) {
|
|
|
|
return this.Vue.auth_message(res, {
|
2020-05-31 01:16:10 +00:00
|
|
|
message: req.T('auth.logged_out'),
|
2020-04-22 21:56:39 +00:00
|
|
|
next_destination: '/',
|
|
|
|
})
|
|
|
|
}
|
2020-08-23 19:50:00 +00:00
|
|
|
|
|
|
|
async logout_provider_clean_session(req, res, next) {
|
|
|
|
await req.user.logout(req)
|
|
|
|
return next()
|
|
|
|
}
|
2020-04-17 00:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = Forms
|