stackpress
Version:
Incept is a content management framework.
39 lines (38 loc) • 1.14 kB
JavaScript
export default async function SignupPage(req, res, ctx) {
if (res.body || (res.code && res.code !== 200)) {
return;
}
const view = ctx.config.path('view', {});
const brand = ctx.config.path('brand', {});
const auth = ctx.config.path('auth');
res.data.set('view', {
base: view.base || '/',
props: view.props || {}
});
res.data.set('brand', {
name: brand.name || 'Stackpress',
logo: brand.logo || '/logo.png',
icon: brand.icon || '/icon.png',
favicon: brand.favicon || '/favicon.ico',
});
res.data.set('auth', {
roles: auth.roles || [],
username: auth.username,
email: auth.email,
phone: auth.phone,
password: auth.password
});
const redirect = req.data('redirect') || '/auth/signin';
const session = ctx.plugin('session');
const { guest } = session.load(req);
if (req.method === 'POST') {
await ctx.emit('auth-signup', req, res);
if (res.code === 200) {
res.redirect(redirect);
}
}
else if (!guest) {
res.redirect(redirect);
}
}
;