-
-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify email #47
Verify email #47
Changes from all commits
bb90900
c677342
0187e35
d761cdc
3174d2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// @flow | ||
|
||
import { isString, isPlainObject } from 'lodash'; | ||
import { isString, isPlainObject, find } from 'lodash'; | ||
import jwt from 'jsonwebtoken'; | ||
import { | ||
AccountsError, | ||
|
@@ -242,8 +242,27 @@ export class AccountsServer { | |
removeEmail(userId: string, email: string): Promise<void> { | ||
return this.db.removeEmail(userId, email); | ||
} | ||
verifyEmail(userId: string, email: string): Promise<void> { | ||
return this.db.verifyEmail(userId, email); | ||
async verifyEmail(token: string): Promise<void> { | ||
const user = await this.db.findUserByEmailVerificationToken(); | ||
if (!user) { | ||
throw new AccountsError({ | ||
message: 'Verify email link expired', | ||
}); | ||
} | ||
const tokenRecord = find(user.services.email.verificationTokens, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TimMikeladze will all dbInterfaces return the user object formatted in the same way ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes they should. |
||
(t: Object) => t.token === token); | ||
if (!tokenRecord) { | ||
throw new AccountsError({ | ||
message: 'Verify email link expired', | ||
}); | ||
} | ||
const emailRecord = find(user.emails, (e: Object) => e.address === tokenRecord.address); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to make another modification to the UserObjecType and the places it is returned at, since it has a string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be the only place we will need this function, I don't think it's necessary to make a special function. |
||
if (!emailRecord) { | ||
throw new AccountsError({ | ||
message: 'Verify email link is for unknown address', | ||
}); | ||
} | ||
await this.db.verifyEmail(user.id, emailRecord); | ||
} | ||
setPassword(userId: string, newPassword: string): Promise<void> { | ||
return this.db.setPasssword(userId, newPassword); | ||
|
@@ -303,8 +322,8 @@ const Accounts = { | |
removeEmail(userId: string, newEmail: string): Promise<void> { | ||
return this.instance.removeEmail(userId, newEmail); | ||
}, | ||
verifyEmail(userId: string, email: string): Promise<void> { | ||
return this.instance.verifyEmail(userId, email); | ||
verifyEmail(token: string): Promise<void> { | ||
return this.instance.verifyEmail(token); | ||
}, | ||
setPassword(userId: string, newPassword: string): Promise<void> { | ||
return this.instance.setPassword(userId, newPassword); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ export interface DBInterface { | |
findUserByEmail(email: string) : Promise<?UserObjectType>, | ||
findUserByUsername(username: string) : Promise<?UserObjectType>, | ||
findUserById(userId: string) : Promise<?UserObjectType>, | ||
findUserByEmailVerificationToken(token: string) : Promise<?UserObjectType>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the name of the function |
||
setUsername(userId: string, newUsername: string) : Promise<void>, | ||
addEmail(userId: string, newEmail: string, verified: boolean) : Promise<void>, | ||
removeEmail(userId: string, email: string) : Promise<void>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add services to the UserObjectType