passport-helper.js
3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Created by TaoHuang on 2016/6/20.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const IndexService = require('./index-service');
/**
* 获得图片
*/
function getLeftBannerAsync(resourceCode) {
const DEFAULT_VALUE = {
img: 'https://img12.static.yhbimg.com/' +
'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
url: ''
};
let that = this;
return co(function* () {
let resource = yield that.indexService.getResourceAsync(resourceCode);
if (_.isEmpty(resource)) {
return DEFAULT_VALUE;
}
let value = {};
// 有点问题 // passport model 58
value.img = helpers.image(resource[0].data[0].src, 252, 190);
value.url = resource[0].data[0].url;
return value;
})();
}
/**
* 国家数据
*/
const 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: '中国香港'
}
];
};
/**
* 验证国际手机号是否合法
*/
const isMobile = _.toNumber;
/**
* 验证邮箱是否合法
*/
const isEmail = email => _.includes(email, '@');
/**
* 密码是否合法
*/
const isPassword = pwd => {
if (!pwd) {
return false;
}
let pwdRegexp = /^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/;
return pwdRegexp.test(_.trim(pwd));
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.indexService = new IndexService(ctx);
this.getLeftBannerAsync = getLeftBannerAsync.bind(this);
this.getCountry = getCountry;
this.validator = {
isMobile,
isEmail,
isPassword
};
}
};