Blame view

apps/passport/models/back-api.js 3.55 KB
htoooth authored
1
/**
htoooth authored
2
 * Created by Tao.Huang on 2016/6/14.
htoooth authored
3 4 5 6 7
 */

'use strict';

姜枫 authored
8
const api = global.yoho.API;
王水玲 authored
9
const logger = global.yoho.logger;
王水玲 authored
10
const aes = require('./aes-pwd');
htoooth authored
11 12 13 14 15 16

const YOHOBUY_URL = 'http://www.yohobuy.com/';

/**
 * 获取地区数据
 */
htoooth authored
17 18
const getAreaDataAsync = () => {
    return api.get('', {
htoooth authored
19
        method: 'app.passport.getArea'
htoooth authored
20
    }).then(result => {
王水玲 authored
21 22 23
        if (result && result.code === 200) {
            result.data = result.data.map(value => {
                value.areaCode = `+${value.area}`;
htoooth authored
24
王水玲 authored
25 26 27 28 29
                if (value.areaCode === '+86') {
                    value.selected = true;
                } else {
                    value.selected = false;
                }
htoooth authored
30
王水玲 authored
31 32 33
                delete value.area;
                return value;
            });
htoooth authored
34
王水玲 authored
35 36
            return result;
        } else {
郭成尧 authored
37
            logger.error('获取地区数据返回 code no 200');
王水玲 authored
38 39
            return [];
        }
htoooth authored
40
    });
htoooth authored
41 42 43 44 45 46 47
};

/**
 * 通过邮箱找回密码
 *
 * @param  string  mail  邮箱地址
 */
htoooth authored
48 49
const sendCodeToEmailAsync = (email) => {
    return api.get('', {
htoooth authored
50 51
        method: 'app.register.backpwdByEmail',
        email: email
htoooth authored
52
    });
htoooth authored
53 54 55 56 57 58 59 60
};

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

    return api._requestFromAPI(options);
};

/**
王水玲 authored
76 77 78 79 80 81 82 83 84 85 86 87 88 89
 * 根据邮箱验证码修改密码(调用新接口 采用AES密码加密)
 *
 * @param  string  pwd       新密码
 * @param  string  code    邮箱验证码
 */
const modifyPasswordByEmailAsyncAes = (pwd, code) => {
    return api.get('', {
        code: code,
        newPwd: aes.aesPwd(pwd),
        method: 'app.register.resetPwdByCodeAES'
    });
};

/**
htoooth authored
90 91 92 93 94
 * 通过手机找回密码
 *
 * @param  string  mobile 手机号
 * @param  integer area   地区码ID
 */
htoooth authored
95 96
const sendCodeToMobileAsync = (mobile, area) => {
    return api.get('', {
htoooth authored
97 98 99
        mobile: mobile,
        area: area,
        method: 'app.register.sendBackpwdCodeToMobile'
htoooth authored
100
    });
htoooth authored
101 102 103 104 105 106 107 108 109
};

/**
 * 校验密码修改手机验证码
 *
 * @param  string  mobile 手机号
 * @param  string  code   验证码
 * @param  integer area   地区码ID
 */
htoooth authored
110
const validateMobileCodeAsync = (mobile, code, area) => {
htoooth authored
111
    area = area || 86;
htoooth authored
112
    return api.get('', {
htoooth authored
113 114 115 116
        mobile: mobile,
        code: code,
        area: area,
        method: 'app.register.validBackpwdCode'
htoooth authored
117
    });
htoooth authored
118 119 120 121 122 123 124 125 126
};

/**
 * 根据手机验证码修改密码
 *
 * @param  string  mobile 手机号
 * @param  string  token   验证手机验证码返回的token
 * @param  integer area   地区码ID
 */
127
const modifyPasswordByMobileAsync = (mobile, token, newpwd, area) => {
htoooth authored
128
    return api.get('', {
htoooth authored
129 130 131 132 133
        mobile: mobile,
        token: token,
        newpwd: newpwd,
        area: area,
        method: 'app.register.changepwdByMobileCode'
htoooth authored
134
    });
htoooth authored
135 136
};
王水玲 authored
137 138 139 140 141 142 143 144 145 146
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
147 148 149 150
module.exports = {
    getAreaDataAsync,
    sendCodeToEmailAsync,
    modifyPasswordByEmailAsync,
王水玲 authored
151
    modifyPasswordByEmailAsyncAes,
htoooth authored
152 153
    sendCodeToMobileAsync,
    validateMobileCodeAsync,
王水玲 authored
154 155
    modifyPasswordByMobileAsync,
    modifyPasswordByMobileAsyncAes
htoooth authored
156
};
htoooth authored
157