reg.js 1.13 KB
/**
* 注册控制器
*/
'use strict';
const passportHelper = require('../models/passport-helper');
const regService = require('../models/reg-service');

let helpers = global.yoho.helpers;

let index = (req, res, next) => {
    // 设置注册有效时间30分钟, 防机器刷
    req.session._REG_EXPIRE = Date.now() + 1800000;

    let refer = req.query.refer;

    refer && res.cookie('refer', encodeURI(refer), {
        domain: 'yohobuy.com'
    });

    regService.getRegData().then((result) => {
        res.render('reg/index', {
            title: '新用户注册',
            passport: {
                region: passportHelper.getCountry(),
                location: '+86',
                captchaUrl: helpers.urlFormat('/passport/images', {t: Date.now()}),
                itemUrl: helpers.urlFormat('/help/', {category_id: 9}),
                referUrl: refer,
                loginUrl: helpers.urlFormat('/signin.html', {refer: refer}),
                coverHref: result.url,
                coverImg: result.img,
                regBtnText: '立即注册'
            }
        });
    }).catch(next);
};

module.exports = {
    index
};