(
input: {
ip: string;
userAgent: string;
demo?: boolean;
email: string;
passwordValues: PasswordValues;
dtrx?: DataTransaction;
} & UserRegistrationSchema,
)
| 49 | >; |
| 50 | |
| 51 | export async function registerUser( |
| 52 | input: { |
| 53 | ip: string; |
| 54 | userAgent: string; |
| 55 | |
| 56 | demo?: boolean; |
| 57 | |
| 58 | email: string; |
| 59 | |
| 60 | passwordValues: PasswordValues; |
| 61 | |
| 62 | dtrx?: DataTransaction; |
| 63 | } & UserRegistrationSchema, |
| 64 | ) { |
| 65 | const emailVerificationCode = nanoid(); |
| 66 | |
| 67 | await UserModel.query(input.dtrx?.trx) |
| 68 | .where('email_hash', Buffer.from(hashUserEmail(input.email))) |
| 69 | .delete(); |
| 70 | |
| 71 | const userModel = { |
| 72 | id: input.userId, |
| 73 | |
| 74 | encrypted_email: encryptUserEmail(input.email), |
| 75 | email_hash: hashUserEmail(input.email), |
| 76 | |
| 77 | encrypted_rehashed_login_hash: input.demo |
| 78 | ? new Uint8Array() |
| 79 | : encryptUserRehashedLoginHash( |
| 80 | encodePasswordHash( |
| 81 | input.passwordValues.hash, |
| 82 | input.passwordValues.salt, |
| 83 | 2, |
| 84 | 32, |
| 85 | ), |
| 86 | ), |
| 87 | |
| 88 | demo: !!input.demo, |
| 89 | |
| 90 | email_verified: false, |
| 91 | ...(!input.demo |
| 92 | ? { |
| 93 | encrypted_new_email: encryptUserEmail(input.email), |
| 94 | email_verification_code: emailVerificationCode, |
| 95 | email_verification_expiration_date: addHours(new Date(), 1), |
| 96 | } |
| 97 | : {}), |
| 98 | |
| 99 | personal_group_id: input.groupId, |
| 100 | |
| 101 | starting_page_id: input.pageId, |
| 102 | recent_page_ids: [input.pageId], |
| 103 | recent_group_ids: [input.groupId], |
| 104 | |
| 105 | public_keyring: input.userPublicKeyring, |
| 106 | encrypted_private_keyring: createPrivateKeyring( |
| 107 | input.userEncryptedPrivateKeyring, |
| 108 | ).wrapSymmetric(input.passwordValues.key, { |
no test coverage detected