user-service.js 1.04 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 = '//img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';

/**
 * 第三方登录 根据手机号获取用户相关信息
 */
const getUserInfoAsync = (area, mobile) => {
    return 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', {bindMobile: mobile, bindArea: area})
        };
    });
};

module.exports = Object.assign(api, {getUserInfoAsync});