reg-service.js 3.44 KB
/**
 * 注册数据接口
 *
 * @author JiangFeng<jeff.jiang@yoho.cn>
 * @date 2016/06/21
 */

'use strict';

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

const RegService = {
    getAreaData() {
        return [
            {
                areaCode: '+61',
                selected: false,
                name: '澳大利亚'
            }, {
                areaCode: '+82',
                selected: false,
                name: '韩国'
            }, {
                areaCode: '+1',
                selected: false,
                name: '加拿大'
            }, {
                areaCode: '+60',
                selected: false,
                name: '马来西亚'
            }, {
                areaCode: '+1',
                selected: false,
                name: '美国'
            }, {
                areaCode: '+81',
                selected: false,
                name: '日本'
            }, {
                areaCode: '+65',
                selected: false,
                name: '新加坡'
            }, {
                areaCode: '+44',
                selected: false,
                name: '英国'
            }, {
                areaCode: '+86',
                selected: true, // default choose
                name: '中国'
            }, {
                areaCode: '+853',
                selected: false,
                name: '中国澳门'
            }, {
                areaCode: '+886',
                selected: false,
                name: '中国台湾'
            }, {
                areaCode: '+852',
                selected: false,
                name: '中国香港'
            }];
    },
    sendCodeToMobile(area, mobile) {
        let params = {
            method: 'app.register.sendRegCodeToMobile',
            area: area,
            mobile: mobile
        };

        return api.post('', params);
    },
    validMobileCode(area, mobile, code) {
        let params = {
            method: 'app.register.validRegCode',
            area: area,
            mobile: mobile,
            code: code
        };

        return api.post('', params);
    },
    regMobile(area, mobile, password, shoppingKey) {
        let params = {
            method: 'app.passport.register',
            area: area,
            profile: mobile,
            password: password
        };

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

        return api.post('', params);
    },
    regMobileAes(area, mobile, password, shoppingKey, smsCode, inviteCode, isFromMy, clientIp, from) {
        isFromMy = isFromMy || '0';

        let params = {
            method: 'app.passport.registerAES',
            area: area,
            profile: mobile,
            password: aes.aesPwd(password),
            verifyCode: smsCode,
            inviteCode: inviteCode,
            isFromMy,
            business_line: FROM[from]
        };

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

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

    /**
    * 好友邀请信息
    */
    inviteUserInfo(inviteCode) {
        return api.get('', {
            method: 'app.invitecode.userinfo',
            inviteCode: inviteCode
        });
    }
};

module.exports = RegService;