passport-helper.js 2.6 KB
/**
 * Created by TaoHuang on 2016/6/20.
 */


'use strict';

const Cache = require(library + '/cache');
const helpers = require(library + '/helpers');
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');

const indexService = require('./index-service');

const KEY_WEB_LOGIN_LEFT_BANNER = 'key_web_login_left_banner'; // 登录页左侧的广告图

module.exports.getLeftBannerAsync = (resourceCode) => {
    const DEFAULT_VALUE = {
        img: 'http://img12.static.yhbimg.com/' +
        'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
        url: ''
    };

    return co(function * () {
        let key = KEY_WEB_LOGIN_LEFT_BANNER + "_" + resourceCode;

        let value = yield Cache.get(key);

        if (!_.isEmpty(value)) {
            return value;
        }

        let resource = yield indexService.getResourceAsync(resourceCode);

        if (_.isEmpty(resource)) {
            return DEFAULT_VALUE;
        }

        // 有点问题 // passport model 58
        value.img = helpers.image(resource.data[0].data.src, 252, 190);
        value.url = resource.data[0].data.url;

        Cache.set(key, value).then(()=> console.log('cache value ok')); // async
        return value;
    })();
};

module.exports.getCountry = () => {
    return [
        {
            areaCode: '+61',
            selected: false,
            name: '澳大利亚'
        },
        {
            areaCode: '+82',
            selected: false,
            name: '韩国'
        },
        {
            areaCode: '+1',
            selected: false,
            name: '加拿大'
        },
        {
            areaCode: '+60',
            selected: false,
            name: '马来西亚'
        },
        {
            areaCode: '+1',
            selected: false,
            name: '美国'
        },
        {
            areaCode: '+81',
            selected: false,
            name: '日本'
        },
        {
            areaCode: '+65',
            selected: false,
            name: '新加坡'
        },
        {
            areaCode: '+44',
            selected: false,
            name: '英国'
        },
        {
            areaCode: '+86',
            selected: true,
            name: '中国'
        },
        {
            areaCode: '+853',
            selected: false,
            name: '中国澳门'
        },
        {
            areaCode: '+886',
            selected: false,
            name: '中国台湾'
        },
        {
            areaCode: '+852',
            selected: false,
            name: '中国香港'
        }
    ];
};