login-api.js 2.6 KB
/**
 * Created by TaoHuang on 2016/10/21.
 */

'use strict';

const aes = require('./aes-pwd');
const api = global.yoho.API;
const logger = global.yoho.logger;

const signinByPasswordWithAes = (area, profile, password, shoppingKey, clientIp) => {
    let param = {
        method: 'sesame.flowering.higher',
        area: area,
        profile: profile,
        password: aes.aesPwd(password)
    };

    if (shoppingKey) {
        param.shopping_key = shoppingKey;
    }

    logger.info('login successfully by password from', clientIp);

    return api.post('', param, {
        headers: {
            'user-agent': 'yoho/nodejs',
            'X-YOHO-IP': clientIp
        }
    });
};

const signinBySMS = (area, mobile, token, shoppingKey) => {
    let param = {
        method: 'app.passport.autoSignin',
        area: area,
        profile: mobile,
        code: token
    };

    if (shoppingKey) {
        param.shopping_key = shoppingKey;
    }

    return api.post('', param);
};

const signinByQrCode = (__1, __2, code, shoppingKey) => { // eslint-disable-line
    let param = {
        method: 'app.twoDimen.qrCodeLogin',
        code: code.substring(code.indexOf('=') + 1)
    };

    if (shoppingKey) {
        param.shopping_key = shoppingKey;
    }

    return api.post('', param);
};

const checkByQrCode = (code) => {
    let param = {
        method: 'app.twoDimen.loginCheck',
        code: code
    };

    return api.post('', param);
};

const sendPasswordBySMS = (area, mobile) => {
    let param = {
        method: 'app.message.sendSms',
        area: area,
        mobile: mobile,
        type: 1 // 手机快捷登录短信验证码
    };

    return api.get('', param);
};

const checkUserExitBySMS = (area, mobile) => {
    return api.get('', {
        method: 'app.passport.checkUserExist',
        area: area,
        mobile: mobile
    });
};

const verifyPasswordBySMS = (area, mobile, code) => {
    return api.get('', {
        method: 'app.message.verifySmsCode',
        area: area,
        mobile: mobile,
        code: code,
        type: 1 // 手机快捷登录短信验证码
    });
};

const signinByOpenID = (nickname, openId, sourceType, shoppingKey) => {
    let param = {
        nickname: nickname,
        openId: openId,
        source_type: sourceType,
        method: 'app.passport.signinByOpenID'
    };

    if (shoppingKey) {
        param.shopping_key = shoppingKey;
    }

    return api.get('', param);
};

module.exports = {
    signinByPasswordWithAes,
    signinBySMS,
    signinByQrCode,
    checkByQrCode,
    sendPasswordBySMS,
    checkUserExitBySMS,
    verifyPasswordBySMS,
    signinByOpenID
};