React-based /account endpoint for editing a user profile
This commit is contained in:
parent
09fe27fe2b
commit
fbb8f5799e
14 changed files with 386 additions and 51 deletions
59
routes/account.js
Normal file
59
routes/account.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
'use strict';
|
||||
|
||||
const passport = require('../lib/passport');
|
||||
const router = require('../lib/router-async').create();
|
||||
const _ = require('../lib/translate')._;
|
||||
const users = require('../models/users');
|
||||
const interoperableErrors = require('../shared/interoperable-errors');
|
||||
|
||||
|
||||
router.all('/rest/*', (req, res, next) => {
|
||||
req.needsJSONResponse = true;
|
||||
|
||||
if (!req.user) {
|
||||
throw new interoperableErrors.NotLoggedInError();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
router.getAsync('/rest/account', async (req, res) => {
|
||||
const user = await users.getById(req.user.id);
|
||||
return res.json(user);
|
||||
});
|
||||
|
||||
router.postAsync('/rest/account', passport.csrfProtection, async (req, res) => {
|
||||
const data = req.body;
|
||||
data.id = req.user.id;
|
||||
|
||||
await users.updateWithConsistencyCheck(req.body, true);
|
||||
return res.json();
|
||||
});
|
||||
|
||||
router.postAsync('/rest/account-validate', async (req, res) => {
|
||||
const data = req.body;
|
||||
data.id = req.user.id;
|
||||
|
||||
return res.json(await users.serverValidate(data, true));
|
||||
});
|
||||
|
||||
|
||||
router.all('/*', (req, res, next) => {
|
||||
if (!req.user) {
|
||||
req.flash('danger', _('Need to be logged in to access restricted content'));
|
||||
return res.redirect('/users/login?next=' + encodeURIComponent(req.originalUrl));
|
||||
}
|
||||
// res.setSelectedMenu('users'); FIXME
|
||||
next();
|
||||
});
|
||||
|
||||
router.getAsync('/*', passport.csrfProtection, async (req, res) => {
|
||||
res.render('react-root', {
|
||||
title: _('Account'),
|
||||
reactEntryPoint: 'account',
|
||||
reactCsrfToken: req.csrfToken()
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
|
@ -39,7 +39,7 @@ router.deleteAsync('/rest/namespaces/:nsId', passport.csrfProtection, async (req
|
|||
return res.json();
|
||||
});
|
||||
|
||||
router.getAsync('/rest/namespacesTree', async (req, res) => {
|
||||
router.getAsync('/rest/namespaces-tree', async (req, res) => {
|
||||
const entries = {};
|
||||
let root; // Only the Root namespace is without a parent
|
||||
const rows = await namespaces.list();
|
||||
|
|
|
@ -40,16 +40,15 @@ router.deleteAsync('/rest/users/:userId', passport.csrfProtection, async (req, r
|
|||
return res.json();
|
||||
});
|
||||
|
||||
router.postAsync('/rest/validate', async (req, res) => {
|
||||
router.postAsync('/rest/users-validate', async (req, res) => {
|
||||
return res.json(await users.serverValidate(req.body));
|
||||
});
|
||||
|
||||
router.postAsync('/rest/usersTable', async (req, res) => {
|
||||
router.postAsync('/rest/users-table', async (req, res) => {
|
||||
return res.json(await users.listDTAjax(req.body));
|
||||
});
|
||||
|
||||
|
||||
|
||||
router.all('/*', (req, res, next) => {
|
||||
if (!req.user) {
|
||||
req.flash('danger', _('Need to be logged in to access restricted content'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue