mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
aceb904398
* Fixed issue with realtime page rendering. * fix auth, add pg extension (#1596) * Fixed change password issue. API refactoring. Closes #1592. * Fixed account lookup. * Fixed issue with accessing user dashboards. Closes #1590 * fix sort on dashboard (#1600) Co-authored-by: Brian Cao <brian@umami.is>
40 lines
957 B
JavaScript
40 lines
957 B
JavaScript
import { getAccount, updateAccount } from 'queries';
|
|
import { useAuth } from 'lib/middleware';
|
|
import {
|
|
badRequest,
|
|
methodNotAllowed,
|
|
ok,
|
|
unauthorized,
|
|
checkPassword,
|
|
hashPassword,
|
|
} from 'next-basics';
|
|
import { allowQuery } from 'lib/auth';
|
|
import { TYPE_ACCOUNT } from 'lib/constants';
|
|
|
|
export default async (req, res) => {
|
|
await useAuth(req, res);
|
|
|
|
const { current_password, new_password } = req.body;
|
|
const { id: accountUuid } = req.query;
|
|
|
|
if (!(await allowQuery(req, TYPE_ACCOUNT))) {
|
|
return unauthorized(res);
|
|
}
|
|
|
|
if (req.method === 'POST') {
|
|
const account = await getAccount({ accountUuid });
|
|
|
|
if (!checkPassword(current_password, account.password)) {
|
|
return badRequest(res, 'Current password is incorrect');
|
|
}
|
|
|
|
const password = hashPassword(new_password);
|
|
|
|
const updated = await updateAccount({ password }, { accountUuid });
|
|
|
|
return ok(res, updated);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|