1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00

add user account email verificiation (#977)

* add user account email verificiation

includes server and client code to:

* enable verificationRequired via custom config
* send verification email with registration
* ask for verification email
* verify via email
* prevent login if not verified and required
* conditional client links to ask for new verification email

* allow login for verified=null

these are users created when verification not required
should still be able to login when verification is enabled

* refactor email verifcation pr

* change naming from verified to emailVerified
* change naming from askVerifyEmail to askSendVerifyEmail
* undo unrelated automatic prettier formatting on api/config
* use redirectService for home
* remove redundant success notification on email verified

* revert test.yaml smpt host
This commit is contained in:
Josh Morel 2018-08-31 03:18:19 -04:00 committed by Chocobozzz
parent 04291e1ba4
commit d9eaee3939
42 changed files with 715 additions and 24 deletions

View file

@ -2,7 +2,7 @@ import * as express from 'express'
import { createClient, RedisClient } from 'redis'
import { logger } from '../helpers/logger'
import { generateRandomString } from '../helpers/utils'
import { CONFIG, USER_PASSWORD_RESET_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers'
import { CONFIG, USER_PASSWORD_RESET_LIFETIME, USER_EMAIL_VERIFY_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers'
type CachedRoute = {
body: string,
@ -60,6 +60,18 @@ class Redis {
return this.getValue(this.generateResetPasswordKey(userId))
}
async setVerifyEmailVerificationString (userId: number) {
const generatedString = await generateRandomString(32)
await this.setValue(this.generateVerifyEmailKey(userId), generatedString, USER_EMAIL_VERIFY_LIFETIME)
return generatedString
}
async getVerifyEmailLink (userId: number) {
return this.getValue(this.generateVerifyEmailKey(userId))
}
setIPVideoView (ip: string, videoUUID: string) {
return this.setValue(this.buildViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME)
}
@ -135,6 +147,10 @@ class Redis {
return 'reset-password-' + userId
}
generateVerifyEmailKey (userId: number) {
return 'verify-email-' + userId
}
buildViewKey (ip: string, videoUUID: string) {
return videoUUID + '-' + ip
}