user-service.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Created by TaoHuang on 2016/6/17.
*/
'use strict';
const Api = require('./user-api');
const helpers = global.yoho.helpers;
const DEFAULT_HEAD_IMG_ICO = 'https://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api(ctx);
this.findByMobileAsync = this.api.findByMobileAsync.bind(this.api);
this.findByEmailAsync = this.api.findByEmailAsync.bind(this.api);
this.profile = this.api.profile.bind(this.api);
this.checkNoCertEmailUser = this.api.checkNoCertEmailUser.bind(this.api);
}
/**
* 第三方登录 根据手机号获取用户相关信息
*/
getUserInfo(area, mobile) {
return this.api.findByMobileAsync(area, mobile).then(user => {
let profile = (user.profile_name || mobile).toString();
if ((profile.length === 11 && profile.indexOf('*') < 0) || (profile.indexOf('-') >= 0 &&
profile.indexOf('*') < 0)) {
profile = profile.substring(0, 3) + '****' + profile.substring(7, 11);
}
return {
username: profile,
headImg: user.head_ico ? helpers.image(user.head_ico, 100, 100, 2) : DEFAULT_HEAD_IMG_ICO,
bindLogin: helpers.urlFormat('/signin.html', {bindMobile: mobile, bindArea: area})
};
});
}
};