@@ -5,7 +5,7 @@ import validator from 'validator';
55import { findCollaboratorsByAppNameAndUid } from '../../models/collaborators' ;
66import { UserTokens } from '../../models/user_tokens' ;
77import { Users } from '../../models/users' ;
8- import { AppError } from '../app-error' ;
8+ import { AppError , AppErrorI18n } from '../app-error' ;
99import { config } from '../config' ;
1010import { redisClient } from '../utils/connections' ;
1111import { passwordVerifySync , randToken , md5 , passwordHashSync } from '../utils/security' ;
@@ -98,10 +98,10 @@ class AccountManager {
9898
9999 login ( account : string , password : string ) {
100100 if ( _ . isEmpty ( account ) ) {
101- return Promise . reject ( new AppError ( '이메일 주소를 입력해주세요. ') ) ; // 请您输入邮箱地址
101+ return Promise . reject ( new AppErrorI18n ( 'error.input_email_required ') ) ;
102102 }
103103 if ( _ . isEmpty ( password ) ) {
104- return Promise . reject ( new AppError ( '비밀번호를 입력해주세요. ') ) ; // 请您输入密码
104+ return Promise . reject ( new AppErrorI18n ( 'error.input_password_required ') ) ;
105105 }
106106 let where = { } ;
107107 if ( validator . isEmail ( account ) ) {
@@ -113,7 +113,7 @@ class AccountManager {
113113 return Users . findOne ( { where } )
114114 . then ( ( users ) => {
115115 if ( _ . isEmpty ( users ) ) {
116- throw new AppError ( '이메일 또는 비밀번호가 올바르지 않습니다. ') ; // 您输入的邮箱或密码有误
116+ throw new AppErrorI18n ( 'error.invalid_credentials ') ;
117117 }
118118 return users ;
119119 } )
@@ -122,9 +122,7 @@ class AccountManager {
122122 const loginKey = `${ LOGIN_LIMIT_PRE } ${ users . id } ` ;
123123 return redisClient . get ( loginKey ) . then ( ( loginErrorTimes ) => {
124124 if ( Number ( loginErrorTimes ) > tryLoginTimes ) {
125- throw new AppError (
126- `비밀번호 오류 횟수가 제한을 초과하여 계정이 잠겼습니다.` ,
127- ) ; // 您输入密码错误次数超过限制,帐户已经锁定
125+ throw new AppErrorI18n ( 'error.password_retry_limit_exceeded' ) ;
128126 }
129127 return users ;
130128 } ) ;
@@ -144,7 +142,7 @@ class AccountManager {
144142 redisClient . incr ( loginKey ) ;
145143 } ) ;
146144 }
147- throw new AppError ( '이메일 또는 비밀번호가 올바르지 않습니다. ') ; // 您输入的邮箱或密码有误
145+ throw new AppErrorI18n ( 'error.invalid_credentials ') ;
148146 } else {
149147 return users ;
150148 }
@@ -153,16 +151,16 @@ class AccountManager {
153151
154152 sendRegisterCode ( email : string ) {
155153 if ( _ . isEmpty ( email ) ) {
156- return Promise . reject ( new AppError ( '请您输入邮箱地址 ') ) ;
154+ return Promise . reject ( new AppErrorI18n ( 'error.input_email_required ') ) ;
157155 }
158156 return Users . findOne ( { where : { email } } )
159157 . then ( ( u ) => {
160158 if ( u ) {
161- throw new AppError ( `" ${ email } " 已经注册过,请更换邮箱注册` ) ;
159+ throw new AppErrorI18n ( 'error.email_already_registered' , { email } ) ;
162160 }
163161 } )
164162 . then ( ( ) => {
165- // 将token临时存储到redis
163+ // Store the token temporarily in Redis
166164 const token = randToken ( 40 ) ;
167165 return redisClient
168166 . setEx ( `${ REGISTER_CODE } ${ md5 ( email ) } ` , EXPIRED , token )
@@ -171,7 +169,7 @@ class AccountManager {
171169 } ) ;
172170 } )
173171 . then ( ( token ) => {
174- // 将token发送到用户邮箱
172+ // Send the token to user's email
175173 return emailManager . sendRegisterCodeMail ( email , token ) ;
176174 } ) ;
177175 }
@@ -180,22 +178,22 @@ class AccountManager {
180178 return Users . findOne ( { where : { email } } )
181179 . then ( ( u ) => {
182180 if ( u ) {
183- throw new AppError ( `" ${ email } " 已经注册过,请更换邮箱注册` ) ;
181+ throw new AppErrorI18n ( 'error.email_already_registered' , { email } ) ;
184182 }
185183 } )
186184 . then ( ( ) => {
187185 const registerKey = `${ REGISTER_CODE } ${ md5 ( email ) } ` ;
188186 return redisClient . get ( registerKey ) . then ( ( storageToken ) => {
189187 if ( _ . isEmpty ( storageToken ) ) {
190- throw new AppError ( `验证码已经失效,请您重新获取` ) ;
188+ throw new AppErrorI18n ( 'error.verify_code_expired' ) ;
191189 }
192190 if ( ! _ . eq ( token , storageToken ) ) {
193191 redisClient . ttl ( registerKey ) . then ( ( ttl ) => {
194192 if ( ttl > 0 ) {
195193 redisClient . expire ( registerKey , ttl - EXPIRED_SPEED ) ;
196194 }
197195 } ) ;
198- throw new AppError ( `您输入的验证码不正确,请重新输入` ) ;
196+ throw new AppErrorI18n ( 'error.verify_code_invalid' ) ;
199197 }
200198 return storageToken ;
201199 } ) ;
@@ -206,7 +204,7 @@ class AccountManager {
206204 return Users . findOne ( { where : { email } } )
207205 . then ( ( u ) => {
208206 if ( u ) {
209- throw new AppError ( `" ${ email } " 已经注册过,请更换邮箱注册` ) ;
207+ throw new AppErrorI18n ( 'error.email_already_registered' , { email } ) ;
210208 }
211209 } )
212210 . then ( ( ) => {
@@ -221,19 +219,19 @@ class AccountManager {
221219
222220 changePassword ( uid : number , oldPassword : string , newPassword : string ) {
223221 if ( ! _ . isString ( newPassword ) || newPassword . length < 6 ) {
224- return Promise . reject ( new AppError ( '请您输入6~20位长度的新密码 ') ) ;
222+ return Promise . reject ( new AppErrorI18n ( 'error.new_password_length ') ) ;
225223 }
226224 return Users . findOne ( { where : { id : uid } } )
227225 . then ( ( u ) => {
228226 if ( ! u ) {
229- throw new AppError ( `未找到用户信息` ) ;
227+ throw new AppErrorI18n ( 'error.user_not_found' ) ;
230228 }
231229 return u ;
232230 } )
233231 . then ( ( u ) => {
234232 const isEq = passwordVerifySync ( oldPassword , u . get ( 'password' ) ) ;
235233 if ( ! isEq ) {
236- throw new AppError ( `您输入的旧密码不正确,请重新输入` ) ;
234+ throw new AppErrorI18n ( 'error.old_password_incorrect' ) ;
237235 }
238236 u . set ( 'password' , passwordHashSync ( newPassword ) ) ;
239237 u . set ( 'ack_code' , randToken ( 5 ) ) ;
0 commit comments