Blame view

apps/passport/models/back-api.js 4.12 KB
htoooth authored
1 2 3 4 5 6
/**
 * Created by TaoHuang on 2016/6/15.
 */

'use strict';
htoooth authored
7
const api = global.yoho.API;
王水玲 authored
8
const aes = require('./aes-pwd');
周少峰 authored
9
const YOHOBUY_URL = 'https//www.yohobuy.com/';
htoooth authored
10 11 12 13

/**
 * 获取地区数据
 */
htoooth authored
14 15
const getAreaDataAsync = () => {
    return api.get('', {
htoooth authored
16
        method: 'app.passport.getArea'
htoooth authored
17
    }).then(result => {
htoooth authored
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        result.data = result.data.map(value => {
            value.areaCode = `+${value.area}`;

            if (value.areaCode === '+86') {
                value.selected = true;
            } else {
                value.selected = false;
            }

            delete value.area;
            return value;
        });

        return result;
    });
};

/**
 * 通过邮箱找回密码
 *
 * @param  string  mail  邮箱地址
 */
htoooth authored
40 41
const sendCodeToEmailAsync = (email) => {
    return api.get('', {
htoooth authored
42
        method: 'app.register.backpwdByEmail',
htoooth authored
43
        email: email
htoooth authored
44
    });
htoooth authored
45 46 47 48 49 50 51 52
};

/**
 * 根据邮箱验证码修改密码(调用www.yohobuy.com接口)
 *
 * @param  string  pwd       新密码
 * @param  string  code    邮箱验证码
 */
htoooth authored
53
const modifyPasswordByEmailAsync = (pwd, code) => {
htoooth authored
54
    const options = {
htoooth authored
55 56 57
        url: `${YOHOBUY_URL}passport/back/update`,
        form: {
            pwd: pwd,
htoooth authored
58
            're-input': pwd,
htoooth authored
59
            code: code
htoooth authored
60 61 62 63 64 65 66 67 68 69 70 71 72
        },
        timeout: 3000
    };

    return api._requestFromAPI(options);
};

/**
 * 通过手机找回密码
 *
 * @param  string  mobile 手机号
 * @param  integer area   地区码ID
 */
htoooth authored
73 74
const sendCodeToMobileAsync = (mobile, area) => {
    return api.get('', {
htoooth authored
75
        mobile: mobile,
htoooth authored
76
        area: area,
htoooth authored
77
        method: 'app.register.sendBackpwdCodeToMobile'
htoooth authored
78
    });
htoooth authored
79 80 81 82 83 84 85 86 87
};

/**
 * 校验密码修改手机验证码
 *
 * @param  string  mobile 手机号
 * @param  string  code   验证码
 * @param  integer area   地区码ID
 */
htoooth authored
88
const validateMobileCodeAsync = (mobile, code, area) => {
htoooth authored
89
    area = area || 86;
htoooth authored
90
    return api.get('', {
htoooth authored
91
        mobile: mobile,
htoooth authored
92 93
        code: code,
        area: area,
htoooth authored
94
        method: 'app.register.validBackpwdCode'
htoooth authored
95
    });
htoooth authored
96 97 98 99 100 101 102 103 104
};

/**
 * 根据手机验证码修改密码
 *
 * @param  string  mobile 手机号
 * @param  string  token   验证手机验证码返回的token
 * @param  integer area   地区码ID
 */
htoooth authored
105 106
const modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> {
    return api.get('', {
htoooth authored
107
        mobile: mobile,
htoooth authored
108
        token: token,
htoooth authored
109
        newpwd: newpwd,
htoooth authored
110
        area: area,
htoooth authored
111
        method: 'app.register.changepwdByMobileCode'
htoooth authored
112
    });
htoooth authored
113 114 115
};

/**
王水玲 authored
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
 * 根据手机验证码修改密码(密码AES加密)
 *
 * @param  string  mobile 手机号
 * @param  string  token   验证手机验证码返回的token
 * @param  integer area   地区码ID
 */
const modifyPasswordByMobileAsyncAes = (mobile, token, newpwd, area)=> {
    return api.get('', {
        mobile: mobile,
        token: token,
        newpwd: aes.aesPwd(newpwd),
        area: area,
        method: 'app.register.changepwdByMobileCodeAES'
    });
};

/**
htoooth authored
133 134
 * 验证找回邮件code
 */
htoooth authored
135 136
const checkEmailCodeAsync = (code) => {
    return api.get('', {
htoooth authored
137
        code: code,
htoooth authored
138
        method: 'web.passport.checkCodeValid'
htoooth authored
139
    });
htoooth authored
140 141 142 143 144
};

/**
 * 根据邮箱code修改密码
 */
htoooth authored
145 146
const modifyPasswordByEmailCodeAsync = (code, password) => {
    return api.get('', {
htoooth authored
147
        code: code,
htoooth authored
148 149
        newPwd: password,
        method: 'app.register.resetPwdByCode'
htoooth authored
150 151 152
    });
};
王水玲 authored
153 154 155 156 157 158 159 160 161 162 163
/**
 * 根据邮箱code修改密码(AES密码加密)
 */
const modifyPasswordByEmailCodeAsyncAes = (code, password) => {
    return api.get('', {
        code: code,
        newPwd: aes.aesPwd(password),
        method: 'app.register.resetPwdByCodeAES'
    });
};
郝肖肖 authored
164
const modPwdByCodeAsync = (params) => {
165 166 167 168 169
    return api.get('', Object.assign(params, {
        method: 'app.password.modPwdByCode',
        oldPwd: aes.aesPwd(params.oldPwd),
        newPwd: aes.aesPwd(params.newPwd)
    }));
郝肖肖 authored
170 171
};
htoooth authored
172 173 174 175 176 177 178
module.exports = {
    getAreaDataAsync,
    sendCodeToEmailAsync,
    modifyPasswordByEmailAsync,
    sendCodeToMobileAsync,
    validateMobileCodeAsync,
    modifyPasswordByMobileAsync,
王水玲 authored
179
    modifyPasswordByMobileAsyncAes,
htoooth authored
180
    checkEmailCodeAsync,
王水玲 authored
181
    modifyPasswordByEmailCodeAsync,
郝肖肖 authored
182 183
    modifyPasswordByEmailCodeAsyncAes,
    modPwdByCodeAsync
htoooth authored
184
};