@@ -9,8 +9,8 @@ import { Users } from '../../models/users';
99import { AppError } from '../app-error' ;
1010import { config } from '../config' ;
1111import { redisClient } from '../utils/connections' ;
12+ import { passwordVerifySync , randToken , md5 , passwordHashSync } from '../utils/security' ;
1213
13- const security = require ( '../utils/security' ) ;
1414const EmailManager = require ( './email-manager' ) ;
1515
1616const loginLimitPre = 'LOGIN_LIMIT_PRE_' ;
@@ -132,7 +132,7 @@ class AccountManager {
132132 return users ;
133133 } )
134134 . then ( ( users ) => {
135- if ( ! security . passwordVerifySync ( password , users . password ) ) {
135+ if ( ! passwordVerifySync ( password , users . password ) ) {
136136 if ( tryLoginTimes > 0 ) {
137137 const loginKey = `${ loginLimitPre } ${ users . id } ` ;
138138 redisClient . exists ( loginKey ) . then ( ( isExists ) => {
@@ -163,9 +163,9 @@ class AccountManager {
163163 } )
164164 . then ( ( ) => {
165165 // 将token临时存储到redis
166- const token = security . randToken ( 40 ) ;
166+ const token = randToken ( 40 ) ;
167167 return redisClient
168- . setEx ( `${ registerCode } ${ security . md5 ( email ) } ` , expired , token )
168+ . setEx ( `${ registerCode } ${ md5 ( email ) } ` , expired , token )
169169 . then ( ( ) => {
170170 return token ;
171171 } ) ;
@@ -185,7 +185,7 @@ class AccountManager {
185185 }
186186 } )
187187 . then ( ( ) => {
188- const registerKey = `${ registerCode } ${ security . md5 ( email ) } ` ;
188+ const registerKey = `${ registerCode } ${ md5 ( email ) } ` ;
189189 return redisClient . get ( registerKey ) . then ( ( storageToken ) => {
190190 if ( _ . isEmpty ( storageToken ) ) {
191191 throw new AppError ( `验证码已经失效,请您重新获取` ) ;
@@ -211,10 +211,10 @@ class AccountManager {
211211 }
212212 } )
213213 . then ( ( ) => {
214- const identical = security . randToken ( 9 ) ;
214+ const identical = randToken ( 9 ) ;
215215 return Users . create ( {
216216 email,
217- password : security . passwordHashSync ( password ) ,
217+ password : passwordHashSync ( password ) ,
218218 identical,
219219 } ) ;
220220 } ) ;
@@ -232,12 +232,12 @@ class AccountManager {
232232 return u ;
233233 } )
234234 . then ( ( u ) => {
235- const isEq = security . passwordVerifySync ( oldPassword , u . get ( 'password' ) ) ;
235+ const isEq = passwordVerifySync ( oldPassword , u . get ( 'password' ) ) ;
236236 if ( ! isEq ) {
237237 throw new AppError ( `您输入的旧密码不正确,请重新输入` ) ;
238238 }
239- u . set ( 'password' , security . passwordHashSync ( newPassword ) ) ;
240- u . set ( 'ack_code' , security . randToken ( 5 ) ) ;
239+ u . set ( 'password' , passwordHashSync ( newPassword ) ) ;
240+ u . set ( 'ack_code' , randToken ( 5 ) ) ;
241241 return u . save ( ) ;
242242 } ) ;
243243 }
0 commit comments