aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/redis.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/redis.ts')
-rw-r--r--server/lib/redis.ts45
1 files changed, 23 insertions, 22 deletions
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index c0e9aece7..3706d2228 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -8,9 +8,8 @@ import {
8 AP_CLEANER, 8 AP_CLEANER,
9 CONTACT_FORM_LIFETIME, 9 CONTACT_FORM_LIFETIME,
10 RESUMABLE_UPLOAD_SESSION_LIFETIME, 10 RESUMABLE_UPLOAD_SESSION_LIFETIME,
11 TRACKER_RATE_LIMITS,
12 TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME, 11 TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME,
13 USER_EMAIL_VERIFY_LIFETIME, 12 EMAIL_VERIFY_LIFETIME,
14 USER_PASSWORD_CREATE_LIFETIME, 13 USER_PASSWORD_CREATE_LIFETIME,
15 USER_PASSWORD_RESET_LIFETIME, 14 USER_PASSWORD_RESET_LIFETIME,
16 VIEW_LIFETIME, 15 VIEW_LIFETIME,
@@ -125,16 +124,28 @@ class Redis {
125 124
126 /* ************ Email verification ************ */ 125 /* ************ Email verification ************ */
127 126
128 async setVerifyEmailVerificationString (userId: number) { 127 async setUserVerifyEmailVerificationString (userId: number) {
129 const generatedString = await generateRandomString(32) 128 const generatedString = await generateRandomString(32)
130 129
131 await this.setValue(this.generateVerifyEmailKey(userId), generatedString, USER_EMAIL_VERIFY_LIFETIME) 130 await this.setValue(this.generateUserVerifyEmailKey(userId), generatedString, EMAIL_VERIFY_LIFETIME)
132 131
133 return generatedString 132 return generatedString
134 } 133 }
135 134
136 async getVerifyEmailLink (userId: number) { 135 async getUserVerifyEmailLink (userId: number) {
137 return this.getValue(this.generateVerifyEmailKey(userId)) 136 return this.getValue(this.generateUserVerifyEmailKey(userId))
137 }
138
139 async setRegistrationVerifyEmailVerificationString (registrationId: number) {
140 const generatedString = await generateRandomString(32)
141
142 await this.setValue(this.generateRegistrationVerifyEmailKey(registrationId), generatedString, EMAIL_VERIFY_LIFETIME)
143
144 return generatedString
145 }
146
147 async getRegistrationVerifyEmailLink (registrationId: number) {
148 return this.getValue(this.generateRegistrationVerifyEmailKey(registrationId))
138 } 149 }
139 150
140 /* ************ Contact form per IP ************ */ 151 /* ************ Contact form per IP ************ */
@@ -157,16 +168,6 @@ class Redis {
157 return this.exists(this.generateIPViewKey(ip, videoUUID)) 168 return this.exists(this.generateIPViewKey(ip, videoUUID))
158 } 169 }
159 170
160 /* ************ Tracker IP block ************ */
161
162 setTrackerBlockIP (ip: string) {
163 return this.setValue(this.generateTrackerBlockIPKey(ip), '1', TRACKER_RATE_LIMITS.BLOCK_IP_LIFETIME)
164 }
165
166 async doesTrackerBlockIPExist (ip: string) {
167 return this.exists(this.generateTrackerBlockIPKey(ip))
168 }
169
170 /* ************ Video views stats ************ */ 171 /* ************ Video views stats ************ */
171 172
172 addVideoViewStats (videoId: number) { 173 addVideoViewStats (videoId: number) {
@@ -357,16 +358,16 @@ class Redis {
357 return 'two-factor-request-' + userId + '-' + token 358 return 'two-factor-request-' + userId + '-' + token
358 } 359 }
359 360
360 private generateVerifyEmailKey (userId: number) { 361 private generateUserVerifyEmailKey (userId: number) {
361 return 'verify-email-' + userId 362 return 'verify-email-user-' + userId
362 } 363 }
363 364
364 private generateIPViewKey (ip: string, videoUUID: string) { 365 private generateRegistrationVerifyEmailKey (registrationId: number) {
365 return `views-${videoUUID}-${ip}` 366 return 'verify-email-registration-' + registrationId
366 } 367 }
367 368
368 private generateTrackerBlockIPKey (ip: string) { 369 private generateIPViewKey (ip: string, videoUUID: string) {
369 return `tracker-block-ip-${ip}` 370 return `views-${videoUUID}-${ip}`
370 } 371 }
371 372
372 private generateContactFormKey (ip: string) { 373 private generateContactFormKey (ip: string) {