account.js 1.81 KB
/**
 * [个人中心]个人设置-账号安全部分
 * @author: jiangmin
 * @date: 2016/07/13
 */

'use strict';
const accountModel = require('../models/account');

/**
 * 修改密码
 * @param req
 * @param res
 * @param next
 */
const changePwd = (req, res, next) => {
    let uid = req.user.uid;
    let pwd = req.body.password;

    accountModel.changePwd(uid, pwd).then(result=> {
        res.send(result);
    }).catch(next);
};

/**
 * 验证手机号码
 * @param req
 * @param res
 * @param next
 */
const checkVerifyMobile = (req, res, next)=> {
    let uid = req.user.uid;
    let mobile = req.body.mobile;
    let area = req.body.area || '86';

    accountModel.checkVerifyMobile(uid, mobile, area).then(result=> {
        res.send(result);
    }).catch(next);
};

/**
 * 发送短信
 * @param req
 * @param res
 * @param next
 */
const sendMobileMsg = (req, res, next)=> {
    let uid = req.user.uid;
    let mobile = req.body.mobile;
    let area = req.body.area || '86';

    accountModel.sendMobileMsg(uid, mobile, area).then(result=> {
        res.send(result);
    }).catch(next);
};


/**
 * 验证短信
 * @param req
 * @param res
 * @param next
 */
const checkVerifyMsg = (req, res, next)=> {
    let code = req.body.code;
    let mobile = req.body.mobile;
    let area = req.body.area || '86';

    accountModel.checkVerifyMsg(code, mobile, area).then(result=> {
        res.send(result);
    }).catch(next);
};

/**
 * 发送验证邮件
 * @param req
 * @param res
 * @param next
 */
const sendVerifyEmail = (req, res, next)=> {
    let uid = req.user.uid;
    let email = req.body.email;

    accountModel.sendVerifyEmail(uid, email).then(result=> {
        res.send(result);
    }).catch(next);
};


module.exports = {
    changePwd,
    sendMobileMsg,
    checkVerifyMsg,
    sendVerifyEmail,
    checkVerifyMobile
};