mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 16:45:35 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into dev
# Conflicts: # pages/api/account/index.js
This commit is contained in:
commit
d784b2a8db
31 changed files with 178 additions and 149 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { getAccounts } from 'queries';
|
||||
import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'next-basics';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, unauthorized, methodNotAllowed } from 'next-basics';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { createAccount, getAccountByUsername, getAccounts } from 'queries';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
|
@ -17,5 +18,29 @@ export default async (req, res) => {
|
|||
return ok(res, accounts);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (!req.auth.is_admin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { username, password } = req.body;
|
||||
|
||||
const accountByUsername = await getAccountByUsername(username);
|
||||
|
||||
if (accountByUsername) {
|
||||
return badRequest(res, 'Account already exists');
|
||||
}
|
||||
|
||||
const created = await createAccount({
|
||||
username,
|
||||
password: hashPassword(password),
|
||||
account_uuid: uuid(),
|
||||
});
|
||||
|
||||
return ok(res, created);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue