Skip to content

Commit 0492e13

Browse files
committed
error tips
1 parent a4c2254 commit 0492e13

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

core/services/account-manager.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ const LOGIN_LIMIT_PRE = 'LOGIN_LIMIT_PRE_';
9393

9494
proto.login = function (account, password) {
9595
if (_.isEmpty(account)) {
96-
return Promise.reject(new Error("Please input Account."))
96+
return Promise.reject(new Error("请您输入邮箱地址"))
9797
}
9898
if (_.isEmpty(password)) {
99-
return Promise.reject(new Error("Please input Password."))
99+
return Promise.reject(new Error("请您输入密码"))
100100
}
101101
var where = {};
102102
if (validator.isEmail(account)) {
@@ -108,7 +108,7 @@ proto.login = function (account, password) {
108108
return models.Users.findOne({where: where})
109109
.then(function(users) {
110110
if (_.isEmpty(users)) {
111-
throw new Error("account or password error.");
111+
throw new Error("您输入的邮箱或密码有误");
112112
}
113113
return users;
114114
})
@@ -144,7 +144,7 @@ proto.login = function (account, password) {
144144
return client.incrAsync(loginKey);
145145
});
146146
}
147-
throw new Error("account or password error.");
147+
throw new Error("您输入的邮箱或密码有误");
148148
} else {
149149
return users;
150150
}
@@ -157,12 +157,12 @@ const EXPIRED_SPEED = 10;
157157

158158
proto.sendRegisterCode = function (email) {
159159
if (_.isEmpty(email)) {
160-
return Promise.reject({message: 'please input email'});
160+
return Promise.reject({message: '请您输入邮箱地址'});
161161
}
162162
return models.Users.findOne({where: {email: email}})
163163
.then(function (u) {
164164
if (u) {
165-
throw new Error(`"${email}" already register`);
165+
throw new Error(`"${email}" 已经注册,请跟换邮箱注册`);
166166
}
167167
})
168168
.then(function () {
@@ -184,7 +184,7 @@ proto.checkRegisterCode = function (email, token) {
184184
return models.Users.findOne({where: {email: email}})
185185
.then(function (u) {
186186
if (u) {
187-
throw new Error(`"${email}" already register`);
187+
throw new Error(`"${email}" 已经注册过,请更换邮箱注册`);
188188
}
189189
})
190190
.then(function () {
@@ -193,7 +193,7 @@ proto.checkRegisterCode = function (email, token) {
193193
return client.getAsync(registerKey)
194194
.then(function (storageToken) {
195195
if (_.isEmpty(storageToken)) {
196-
throw new Error(`token expired, please get new one`);
196+
throw new Error(`验证码已经失效,请您重新获取`);
197197
}
198198
if (!_.eq(token, storageToken)) {
199199
client.ttlAsync(registerKey)
@@ -203,7 +203,7 @@ proto.checkRegisterCode = function (email, token) {
203203
}
204204
return ttl;
205205
})
206-
throw new Error(`token did not matches`);
206+
throw new Error(`您输入的验证码不正确,请重新输入`);
207207
}
208208
return storageToken;
209209
})
@@ -214,7 +214,7 @@ proto.register = function (email, password) {
214214
return models.Users.findOne({where: {email: email}})
215215
.then(function (u) {
216216
if (u) {
217-
throw new Error(`"${email}" already register`);
217+
throw new Error(`"${email}" 已经注册过,请更换邮箱注册`);
218218
}
219219
})
220220
.then(function () {

routes/users.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ router.post('/', function (req, res, next) {
1717
var accountManager = new AccountManager();
1818
return accountManager.checkRegisterCode(email, token)
1919
.then(function (u) {
20+
console.log(password);
2021
if (_.isString(password) && password.length < 6) {
21-
throw new ERROR('password length must gt ');
22+
throw new Error('密码长度至少为6位');
2223
}
2324
return accountManager.register(email, password);
2425
})
2526
.then(function () {
2627
res.send({status: "OK"});
2728
})
2829
.catch(function (e) {
30+
console.log(e);
2931
res.send({status: "ERROR", message: e.message});
3032
});
3133

0 commit comments

Comments
 (0)