feat: add accept-invitation page
This commit is contained in:
@@ -12,9 +12,7 @@ export default async (request, response) => {
|
||||
.throwIfNotFound();
|
||||
|
||||
if (!user.isInvitationTokenValid()) {
|
||||
throw new Error(
|
||||
'Invitation link is not valid or expired. You can use reset password to get a new link.'
|
||||
);
|
||||
return response.status(422).end();
|
||||
}
|
||||
|
||||
await user.acceptInvitation(password);
|
||||
|
@@ -23,7 +23,7 @@ const createUser = async (_parent, params, context) => {
|
||||
const userPayload = {
|
||||
fullName,
|
||||
email,
|
||||
status: 'pending',
|
||||
status: 'invited',
|
||||
};
|
||||
|
||||
try {
|
||||
|
@@ -35,7 +35,7 @@ class User extends Base {
|
||||
password: { type: 'string' },
|
||||
status: {
|
||||
type: 'string',
|
||||
enum: ['active', 'pending'],
|
||||
enum: ['active', 'invited'],
|
||||
default: 'active',
|
||||
},
|
||||
resetPasswordToken: { type: ['string', 'null'] },
|
||||
@@ -234,11 +234,12 @@ class User extends Base {
|
||||
return await this.$query().patch({
|
||||
invitationToken: null,
|
||||
invitationTokenSentAt: null,
|
||||
status: 'active',
|
||||
password,
|
||||
});
|
||||
}
|
||||
|
||||
async isResetPasswordTokenValid() {
|
||||
isResetPasswordTokenValid() {
|
||||
if (!this.resetPasswordTokenSentAt) {
|
||||
return false;
|
||||
}
|
||||
@@ -250,7 +251,7 @@ class User extends Base {
|
||||
return now.getTime() - sentAt.getTime() < fourHoursInMilliseconds;
|
||||
}
|
||||
|
||||
async isInvitationTokenValid() {
|
||||
isInvitationTokenValid() {
|
||||
if (!this.invitationTokenSentAt) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ const userSerializer = (user) => {
|
||||
email: user.email,
|
||||
createdAt: user.createdAt.getTime(),
|
||||
updatedAt: user.updatedAt.getTime(),
|
||||
status: user.status,
|
||||
fullName: user.fullName,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user