2020-04-22 14:19:25 +00:00
|
|
|
const { Service } = require('flitter-di')
|
|
|
|
|
|
|
|
class VueService extends Service {
|
|
|
|
static get services() {
|
2020-05-04 01:16:54 +00:00
|
|
|
return [...super.services, 'configs', 'utility']
|
2020-04-22 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data(merge = {}) {
|
|
|
|
return {
|
|
|
|
vue_state: {
|
|
|
|
app_name: this.configs.get('app.name'),
|
|
|
|
app_url: this.configs.get('app.url'),
|
|
|
|
...merge
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-22 21:56:39 +00:00
|
|
|
|
2020-05-04 01:16:54 +00:00
|
|
|
session(req, merge = {}) {
|
|
|
|
return {
|
|
|
|
vue_session: this.utility.deep_merge({
|
|
|
|
app: {
|
|
|
|
name: this.configs.get('app.name'),
|
|
|
|
url: this.configs.get('app.url'),
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
first_name: req.user.first_name,
|
|
|
|
last_name: req.user.last_name,
|
2020-10-19 04:27:23 +00:00
|
|
|
username: req.user.uid.toLowerCase(),
|
2020-05-04 01:16:54 +00:00
|
|
|
email: req.user.email,
|
|
|
|
tagline: req.user.tagline,
|
|
|
|
user_id: req.user.id,
|
|
|
|
has_mfa: req.user.mfa_enabled,
|
|
|
|
},
|
|
|
|
}, merge)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 02:13:38 +00:00
|
|
|
invoke_action(res, action) {
|
|
|
|
return res.page('public:action', {
|
|
|
|
...this.data({ action })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-22 21:56:39 +00:00
|
|
|
auth_message(res, {message, next_destination, ...args}) {
|
|
|
|
const text = args.button_text || 'Continue'
|
|
|
|
return res.page('public:message', {
|
|
|
|
...this.data({
|
|
|
|
message,
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
text,
|
|
|
|
action: 'redirect',
|
|
|
|
next: next_destination,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-05-04 01:16:54 +00:00
|
|
|
|
|
|
|
confirm(res, {message, yes, no, yes_text = 'Yes', no_text = 'No'}) {
|
|
|
|
return res.page('public:message', {
|
|
|
|
...this.data({
|
|
|
|
message,
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
text: no_text,
|
|
|
|
action: 'redirect',
|
|
|
|
next: no,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: yes_text,
|
|
|
|
action: 'redirect',
|
|
|
|
next: yes,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-04-22 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = VueService
|