user-api.js 1.59 KB
/**
 * Created by TaoHuang on 2016/6/17.
 */
'use strict';

const _ = require('lodash');
const EMPTY = {};

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     * 根据手机号获取用户信息
     */
    findByMobileAsync(area, mobile) {
        return this.get({
            data: {
                mobile: mobile,
                area: area,
                method: 'app.passport.getProfileByMobile'
            }
        }).then(result => {
            if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
                return EMPTY;
            }

            return result.data;
        }).catch(() => {
            return EMPTY;
        });
    }

    /**
     * 根据邮箱获取用户信息
     */
    findByEmailAsync(email) {
        return this.get({
            data: {
                email: email,
                method: 'app.passport.getProfileByEmail'
            }
        }).then(result => {
            if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
                return EMPTY;
            }

            return result.data;

        }).catch(() => {
            return EMPTY;
        });
    }

    profile(uid) {
        let param = {
            uid: uid,
            method: 'app.passport.profile'
        };

        return this.get({data: param});
    }


    checkNoCertEmailUser(uid) {
        let param = {
            method: 'app.passport.checkIsNeedPopupRelated',
            uid: uid
        };

        return this.get({data: param});
    }
};