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

'use strict';

const aes = require('./aes-pwd');

const PAGE = 'pc';

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

    signinByPasswordWithAes(area, profile, password, shoppingKey, id, captcha) {
        let param = {
            method: 'smart.forward.go',
            area: area,
            profile: profile,
            password: aes.aesPwd(password),
            udid: id,
            fromPage: PAGE,
            degrees: captcha
        };

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

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

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

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

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

    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 this.post({data: param});
    }

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

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

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

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

    checkUserExitBySMS(area, mobile) {
        return this.get({data: {
            method: 'app.passport.checkUserExist',
            area: area,
            mobile: mobile
        }});
    }

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

    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 this.get({data: param});
    }
};