add direct invitation link
All checks were successful
deploy / build-and-deploy (push) Successful in 21s
All checks were successful
deploy / build-and-deploy (push) Successful in 21s
This commit is contained in:
@@ -17,19 +17,33 @@ export const signup = {
|
||||
.max(Date.now() - 1000 * 60 * 60 * 24 * 365 * 6),
|
||||
phone: z.string().trim().nullable(),
|
||||
username: z.string().trim(),
|
||||
edition: z.enum(['java', 'bedrock'])
|
||||
edition: z.enum(['java', 'bedrock']),
|
||||
hash: z.string().nullish()
|
||||
}),
|
||||
handler: async (input) => {
|
||||
// check if hash given and if so, if it's valid and nobody has already used it
|
||||
if (input.hash) {
|
||||
const directSignup = await db.getDirectSignupByHash({ hash: input.hash });
|
||||
|
||||
if (!directSignup) {
|
||||
throw new ActionError({
|
||||
code: 'NOT_FOUND'
|
||||
});
|
||||
} else if (directSignup.user) {
|
||||
throw new ActionError({
|
||||
code: 'CONFLICT'
|
||||
});
|
||||
}
|
||||
}
|
||||
// check if signup is allowed
|
||||
if (!(await getSetting(db, SettingKey.SignupEnabled))) {
|
||||
else if (!(await getSetting(db, SettingKey.SignupEnabled))) {
|
||||
throw new ActionError({
|
||||
code: 'FORBIDDEN',
|
||||
message: 'Die Anmeldung ist derzeit deaktiviert'
|
||||
});
|
||||
}
|
||||
|
||||
// check if the user were already signed up
|
||||
if (await db.getUserByUsername({ username: input.username })) {
|
||||
else if (await db.getUserByUsername({ username: input.username })) {
|
||||
throw new ActionError({
|
||||
code: 'CONFLICT',
|
||||
message: 'Du hast dich bereits registriert'
|
||||
@@ -57,14 +71,20 @@ export const signup = {
|
||||
}
|
||||
}
|
||||
|
||||
await db.addUser({
|
||||
firstname: input.firstname,
|
||||
lastname: input.lastname,
|
||||
birthday: input.birthday,
|
||||
telephone: input.phone,
|
||||
username: input.username,
|
||||
edition: input.edition,
|
||||
uuid: uuid
|
||||
await db.transaction(async (tx) => {
|
||||
const user = await tx.addUser({
|
||||
firstname: input.firstname,
|
||||
lastname: input.lastname,
|
||||
birthday: input.birthday,
|
||||
telephone: input.phone,
|
||||
username: input.username,
|
||||
edition: input.edition,
|
||||
uuid: uuid
|
||||
});
|
||||
|
||||
if (input.hash) {
|
||||
await tx.setDirectSignupUser({ hash: input.hash, userId: user.id });
|
||||
}
|
||||
});
|
||||
|
||||
sendWebhook(WebhookAction.Signup, {
|
||||
|
||||
@@ -144,5 +144,31 @@ export const user = {
|
||||
blocked: await db.getBlockedUsers({})
|
||||
};
|
||||
}
|
||||
}),
|
||||
addDirectInvitation: defineAction({
|
||||
handler: async (_, context) => {
|
||||
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
|
||||
|
||||
return await db.addDirectSignup({});
|
||||
}
|
||||
}),
|
||||
deleteDirectInvitation: defineAction({
|
||||
input: z.object({
|
||||
hash: z.string()
|
||||
}),
|
||||
handler: async (input, context) => {
|
||||
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
|
||||
|
||||
await db.deleteDirectSignup({ hash: input.hash });
|
||||
}
|
||||
}),
|
||||
directInvitations: defineAction({
|
||||
handler: async (_, context) => {
|
||||
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
|
||||
|
||||
return {
|
||||
directInvitations: await db.getDirectSignups({})
|
||||
};
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user