router.js 8 KB
/**
 * router of sub app channel
 * @author: Bi Kai<kai.bi@yoho.cn>
 * @date: 2016/05/09
 */

'use strict';

const express = require('express');
const login = require('./controllers/login');
const back = require('./controllers/back');
const bind = require('./controllers/bind');
const reg = require('./controllers/reg');
const reset = require('./controllers/reset');

const disableBFCahce = require('../../doraemon/middleware/disable-BFCache');

const smsLogin = require('./controllers/sms');
const update = require('./controllers/update');
const agreement = require('./controllers/app-agreement');

const geetest = require('./controllers/geetest');
const validateCode = require('./controllers/validateCode');

const router = express.Router(); // eslint-disable-line

// geetest
router.get('/passport/geetest/register', geetest.register);

// 登出
router.get('/passport/signout/index', login.common.clearCookie, login.local.logout);

// 本地登录
router.post('/passport/login/auth', validateCode.check, login.local.login);

// 检查登录状态
router.get('/passport/login/check', login.common.check);
router.get('/passport/sms_login/check.json',
    smsLogin.checkBefore,
    smsLogin.check); // only ajax
router.post('/passport/sms_login/password.json', smsLogin.password);

// jsonp获取用户uid
router.get('/passport/login/user', login.user);

// // 微信登录
router.get('/passport/login/wechat', login.common.beforeLogin, login.common.isLoginUser, login.wechat.login);
router.get('/passport/login/wechat/callback', login.wechat.callback);
router.get('/passport/login/wechat/redirect', login.wechat.redirect);

// // sina登录
// router.get('/passport/login/sina', login.common.beforeLogin, login.sina.login);
// router.get('/passport/login/sina/callback', login.sina.callback);
// router.get('/passport/login/sina/redirect', login.sina.redirect);

// // qq登录
// router.get('/passport/login/qq', login.common.beforeLogin, login.qq.login);
// router.get('/passport/login/qq/callback', login.qq.callback);

// // 支付宝登录
// router.get('/passport/login/alipay', login.common.beforeLogin, login.alipay.login);
// router.get('/passport/login/alipay/callback', login.alipay.callback);

// 登录绑定
// router.get('/passport/bind/index', validateCode.load, bind.indexPage);
router.post('/passport/bind/bindCheck', bind.bindCheck);
router.get('/passport/bind/code', validateCode.load, bind.codePage);
router.post('/passport/bind/sendBindMsg',
    validateCode.check,
    bind.sendBindMsg);
router.post('/passport/bind/bindMobile', bind.bindMobile);

router.post('/passport/bind/relateMobile', bind.relateMobile);
router.get('/passport/bind/password', bind.passwordPage);
router.get('/passport/bind/success', bind.successPage);

router.post('/passport/bind/changeCheck', bind.changeCheck);
router.post('/passport/bind/changeMobile', bind.changeMobile);

router.get('/passport/password/resetpage', reset.passwordResetPage); // 重置密码页面
router.post('/passport/password/reset', reset.passwordReset); // 重置密码
router.get('/passport/password/resetsuccess', reset.passwordResetOkPage); // 重置成功

// 通过邮箱登录绑定手机号
router.get('/passport/bind/forceBindMobile', validateCode.load, bind.forceBindMobilePage);
router.post('/passport/bind/forceSendMsg',
    validateCode.check,
    bind.isCheckEmailPassword,
    bind.sendMsgApi,
    bind.forceSendMsg
);
router.post('/passport/bind/forceMobileCheck',
    bind.isCheckEmailPassword,
    bind.changeMobileCheckApi,
    bind.forceBindMobileApi
);
router.post('/passport/bind/continueMobile', bind.isCheckEmailPassword, bind.forceBindMobileApi);

// 第三方绑定手机号
router.get('/passport/bind/index', validateCode.load, bind.thirdBindMobilePage);
router.post('/passport/bind/thirdSendMsg', validateCode.check, bind.thirdSendMsgApi, bind.forceSendMsg);
router.post('/passport/bind/thirdMobileCheck',
    bind.changeMobileCheckApi,
    bind.thirdBindMobileApi
);
router.post('/passport/bind/thirdContinueMobile', bind.thirdBindMobileApi);

/**
 * 密码找回
 */
router.post('/passport/back/sendemail', back.sendCodeToEmailAPI);// 发送邮箱验证码
router.get('/passport/back/resendemail', back.resendCodeToEmailAPI);// 重新发送邮箱验证码
router.post('/passport/back/sendcode', validateCode.check, back.sendCodeToMobileAPI);// 发送手机验证码
router.post('/passport/back/sendcodeagain', back.verifySmsAllow, back.sendCodeToMobileAPI);// 重新发送手机验证码
router.post('/passport/back/verifycode', back.verifyCodeByMobileAPI);// 校验手机验证码
router.post('/passport/back/passwordbyemail', back.setNewPasswordByEmailAPI);// 依据邮箱验证码修改密码
router.post('/passport/back/passwordbymobile', back.setNewPasswordByMobileAPI);// 依据手机验证码修改密码

/**
 * 提示升级app
 */
router.get('/passport/update', update.index);

// 服务条款
router.get('/passport/privacy', agreement.privacy);// 隐私条款
router.get('/passport/newpower', agreement.newpower);// 新力传媒
router.get('/passport/yohobuy', agreement.aboutYoho);// 关于有货
router.get('/passport/agreement', agreement.agreement);// 服务条款
router.get('/passport/about', agreement.about);// 关注有货

// 验证码
let captcha = require('./controllers/captcha');

router.get('/passport/captcha/get', captcha.get);
router.get('/passport/img-check.jpg', captcha.imgCheck);
router.get('/passport/img-check-risk.jpg', captcha.imgCheckRisk);

/**
 * 注册
 */
router.use('/passport/reg/*', disableBFCahce);
router.post('/passport/reg/verifymobile', validateCode.check, reg.sendCodeBusyBoy, reg.verifyMobile);

// 新的登录注册
const LoginNew = require('./controllers/login-new');
const loginNew = new LoginNew();

router.get('/passport/login',
    login.common.clearCookie,
    login.common.wechatQuickLoginCheck,
    validateCode.load,
    login.common.beforeLogin,
    loginNew.loginPage); // 普通登录
router.get('/passport/international',
    login.common.clearCookie,
    validateCode.load,
    login.common.beforeLogin,
    loginNew.international); // 国际账号登录
router.get('/passport/reg/index',
    login.common.clearCookie,
    validateCode.load,
    reg.regPage); // 注册页面
router.post('/passport/register-new',
    reg.sendCodeBusyBoy,
    reg.register); // 注册请求
router.get('/passport/sms_login',
    login.common.clearCookie,
    login.common.wechatQuickLoginCheck,
    validateCode.load,
    smsLogin.smsLoginPage); // 短信验证码登录
router.post('/passport/sms_login/step1_check', validateCode.check, smsLogin.indexCheck);
router.get('/passport/sms_login/step1_check', (req, res, next) => {
    if (!req.query.callback) {
        return res.json({code: 400});
    }

    req.body = req.body || {};
    Object.assign(req.body, req.query);
    next();
}, validateCode.check, smsLogin.indexCheck);

// 兼容老的路由
router.get('/signin.html',
    login.common.clearCookie,
    login.common.thirdLogin,

    // login.common.weixinCheck,
    login.common.wechatQuickLoginCheck,
    validateCode.load,
    login.common.beforeLogin,
    smsLogin.smsLoginPage); // 短信验证码登录

router.get('/signin.htm',
    login.common.clearCookie,
    login.common.thirdLogin,
    login.common.wechatQuickLoginCheck,
    validateCode.load,
    login.common.beforeLogin,
    smsLogin.smsLoginPage); // 短信验证码登录

router.get('/reg.html',
    login.common.clearCookie,
    validateCode.load,
    reg.regPage); // 注册页面
router.get('/regSuccess.html', reg.regSuccessPage); // 注册成功页面
router.get('/login.html',
    login.common.clearCookie,
    validateCode.load,
    login.common.beforeLogin,
    loginNew.international); // 国际账号登录

router.get('/passport/back/mobile', validateCode.load, back.backByMobile); // 通过手机找回密码
router.post('/passport/back/passwordByMobile-new', back.setNewPasswordByMobileAPI);// 依据手机验证码修改密码
router.get('/passport/back/email', back.backByEmail); // 通过邮箱找回密码
router.get('/passport/back/success', back.backByEmailSuccess);// 邮箱找回密码-发送成功页面

module.exports = router;