CoreID/app/services/Vue.service.js

82 lines
2.2 KiB
JavaScript
Raw Normal View History

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']
}
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,
username: req.user.uid,
email: req.user.email,
tagline: req.user.tagline,
user_id: req.user.id,
has_mfa: req.user.mfa_enabled,
},
}, merge)
}
}
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,
}
],
})
})
}
}
module.exports = exports = VueService