feature: signup and login work
This commit is contained in:
parent
a4a750b35c
commit
3d42591ee5
18 changed files with 956 additions and 65 deletions
|
@ -6,28 +6,27 @@ import { hash } from 'jsr:@stdext/crypto/hash';
|
|||
import lurid from 'jsr:@andyburke/lurid';
|
||||
import { encodeBase64 } from 'jsr:@std/encoding';
|
||||
import parse_body from '../../../utils/bodyparser.ts';
|
||||
import { get_session, SESSION_RESULT } from '../auth/index.ts';
|
||||
import { create_new_session, SESSION_RESULT } from '../auth/index.ts';
|
||||
import { PRECHECKS } from './me/index.ts';
|
||||
import { get_session, get_user, require_user } from '../../../utils/prechecks.ts';
|
||||
import { CANNED_RESPONSES } from '../../../utils/canned_responses.ts';
|
||||
|
||||
// TODO: figure out a better solution for doling out permissions
|
||||
const DEFAULT_USER_PERMISSIONS: string[] = [
|
||||
'self.read',
|
||||
'self.write',
|
||||
'checklists.read',
|
||||
'checklists.write',
|
||||
'checklists.events.read',
|
||||
'checklists.events.write'
|
||||
'self.write'
|
||||
];
|
||||
|
||||
export const PERMISSIONS: Record<string, (req: Request, meta: Record<string, any>) => Promise<boolean>> = {};
|
||||
|
||||
// GET /api/users - get users
|
||||
// query parameters:
|
||||
// partial_id: the partial id subset you would like to match (remember, lurids are lexigraphically sorted)
|
||||
PERMISSIONS.GET = (_req: Request, meta: Record<string, any>): Promise<boolean> => {
|
||||
PRECHECKS.GET = [get_session, get_user, require_user, (_req: Request, meta: Record<string, any>): Response | undefined => {
|
||||
const can_read_others = meta.user_permissions?.permissions?.includes('users.read');
|
||||
|
||||
return can_read_others;
|
||||
};
|
||||
if (!can_read_others) {
|
||||
return CANNED_RESPONSES.permission_denied();
|
||||
}
|
||||
}];
|
||||
export async function GET(_req: Request, meta: Record<string, any>): Promise<Response> {
|
||||
const query: URLSearchParams = meta.query;
|
||||
const partial_id: string | undefined = query.get('partial_id')?.toLowerCase().trim();
|
||||
|
@ -132,7 +131,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
|
|||
|
||||
await PERMISSIONS_STORE.create(user_permissions);
|
||||
|
||||
const session_result: SESSION_RESULT = await get_session({
|
||||
const session_result: SESSION_RESULT = await create_new_session({
|
||||
user,
|
||||
expires: undefined
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue