user-service.js 1.48 KB
/**
 * 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})
            };
        });
    }
};