back-api.js 2.76 KB
/**
 * Created by Tao.Huang on 2016/6/14.
 */

'use strict';

var API = require('../../../library/api').API;
const library = '../../../library';
const sign = require(`${library}/sign`);

var api = new API();

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

/**
 * 获取地区数据
 */
module.exports.getAreaDataAsync = () => {
    return api.get('', sign.apiSign({
        method: 'app.passport.getArea'
    }));
};

/**
 * 通过邮箱找回密码
 *
 * @param  string  mail  邮箱地址
 */
module.exports.sendCodeToEmailAsync = (email) => {
    return api.get('', sign.apiSign({
        method: 'app.register.backpwdByEmail',
        email: email
    }));
};

/**
 * 根据邮箱验证码修改密码(调用www.yohobuy.com接口)
 *
 * @param  string  pwd       新密码
 * @param  string  code    邮箱验证码
 */
module.exports.modifyPasswordByEmailAsync = (pwd, code) => {
    const options = {
        url: `${YOHOBUY_URL}passport/back/update`,
        form: {
            pwd: pwd,
            're-input': pwd,
            code: code
        },
        timeout: 3000
    };

    return api._requestFromAPI(options);
};

/**
 * 通过手机找回密码
 *
 * @param  string  mobile 手机号
 * @param  integer area   地区码ID
 */
module.exports.sendCodeToMobileAsync = (mobile, area) => {
    area = area || 86;

    return api.get('', sign.apiSign({
        mobile: mobile,
        area: area,
        method: 'app.register.sendBackpwdCodeToMobile'
    }));
};

/**
 * 校验密码修改手机验证码
 *
 * @param  string  mobile 手机号
 * @param  string  code   验证码
 * @param  integer area   地区码ID
 */
module.exports.validateMobileCodeAsync = (mobile, code, area) => {
    area = area || 86;
    return api.get('', sign.apiSign({
        mobile: mobile,
        code: code,
        area: area,
        method: 'app.register.validBackpwdCode'
    }));
};

/**
 * 根据手机验证码修改密码
 *
 * @param  string  mobile 手机号
 * @param  string  token   验证手机验证码返回的token
 * @param  integer area   地区码ID
 */
module.exports.modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> {
    area = area || 86;
    return api.get('', sign.apiSign({
        mobile: mobile,
        token: token,
        newpwd: newpwd,
        area: area,
        method: 'app.register.changepwdByMobileCode'
    }));
};

/**
 * 验证找回邮件code
 */
module.exports.checkEmailCodeAsync = (code) => {
    return api.get('', sign.apiSign({
        code: code,
        method: 'web.passport.checkCodeValid'
    }));
};

/**
 * 根据邮箱code修改密码
 */
module.exports.modifyPasswordByEmailCodeAsync = (code, password) => {
    return api.get('', sign.apiSign({
        code: code,
        newPwd: password,
        method: 'app.register.resetPwdByCode'
    }));
};