back.js 2.28 KB
/**
 * 找回密码
 * Created by Tao.Huang on 2016/6/12.
 */

'use strict';

const library = '../../../library';
const helpers = require(`${library}/helpers`);

const service = require('../models/back-service');

// 本地地址 localhost
helpers.urlFormat = helpers.fakeUrlFormat;

const SIGN_IN_URL = helpers.urlFormat('/signin.html');


/**
 * 找回密码主页面
 */
module.exports.indexPage = (req, res) => {
    service.indexPageDataAsync().then(result => {
        res.render('back/index', Object.assign({
            module: 'back',
            page: 'index',
            title: '找回密码'
        }, result));
    });
};

/**
 * 校验用户输入信息,是否是已经注册的用户
 */
module.exports.identifyUserByInputAPI = (req, res) => {
    let userInput = req.body.phoneNum || '';

    let areaCode = req.body.area || '86';

    service.identifyUserByEmailOrMobileAsync(userInput, areaCode)
        .then(result => {
            res.json(result);
        });
};

module.exports.sendCodeAPI = (req, res, next) => {
    let userInput = req.body.phoneNum || '';

    let areaCode = req.body.area || '86';

    service.sendCodeToUserAsync(userInput, areaCode).then(result => {
        switch (result) {
            case 'mobile':
                {
                    res.redirect('/passport/back/sendemail.html');
                    break;
                }
            case 'email':
                {
                    res.redirect('/passport/back/verification.html');
                    break;
                }
            default:
                {
                    res.redirect('./passport/back/index.html');
                }
        }
    }).catch(next);
};

module.exports.verifyCodeByMobilePage = (req, res, next) => {

    service.getVerifyCodeByMobilePageDataAsync()
        .then(result => {
            res.render('back/verification', Object.assign({
                module: 'back',
                page: 'verification',
                title: '手机验证'
            }, {
                verification: {
                    coverHref: result.url,
                    coverImg: result.img,
                    mobile: result.mobile,
                    area: result.area,
                    verifyCode: result.verifyCode
                }
            }));
        }).catch(next);
};