Authored by 郭成尧

RegServiceModel

@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 'use strict'; 8 'use strict';
9 9
10 const helpers = global.yoho.helpers; 10 const helpers = global.yoho.helpers;
11 -const RegService = require('../models/reg-service'); 11 +const RegServiceModel = require('../models/reg-service');
12 const BindService = require('../models/bind-service'); 12 const BindService = require('../models/bind-service');
13 const AuthHelper = require('../models/auth-helper'); 13 const AuthHelper = require('../models/auth-helper');
14 const _ = require('lodash'); 14 const _ = require('lodash');
@@ -49,7 +49,7 @@ const bind = { @@ -49,7 +49,7 @@ const bind = {
49 isWechatLogin: sourceType === 'wechat', 49 isWechatLogin: sourceType === 'wechat',
50 openId: openId, // openId 50 openId: openId, // openId
51 areaCode: '+86', // 默认区号 51 areaCode: '+86', // 默认区号
52 - countrys: RegService.getAreaData(), // 国别码 52 + countrys: req.ctx(RegServiceModel).getAreaData(), // 国别码
53 serviceUrl: serviceUrl, // 在线客服 53 serviceUrl: serviceUrl, // 在线客服
54 module: 'passport', 54 module: 'passport',
55 page: 'bind', 55 page: 'bind',
1 const _ = require('lodash'); 1 const _ = require('lodash');
2 const co = Promise.coroutine; 2 const co = Promise.coroutine;
3 -const RegService = require('../models/reg-service'); 3 +const RegServiceModel = require('../models/reg-service');
4 const LoginNewModel = require('../models/login-new'); 4 const LoginNewModel = require('../models/login-new');
5 5
6 class Login { 6 class Login {
@@ -64,7 +64,7 @@ class Login { @@ -64,7 +64,7 @@ class Login {
64 localCss: true, 64 localCss: true,
65 width750: true, 65 width750: true,
66 captchaShow: req.yoho.captchaShow, 66 captchaShow: req.yoho.captchaShow,
67 - countrys: RegService.getAreaData() 67 + countrys: req.ctx(RegServiceModel).getAreaData()
68 }); 68 });
69 } 69 }
70 } 70 }
1 const _ = require('lodash'); 1 const _ = require('lodash');
2 const url = require('url'); 2 const url = require('url');
3 const helpers = global.yoho.helpers; 3 const helpers = global.yoho.helpers;
4 -const RegService = require('../models/reg-service'); 4 +const RegServiceModel = require('../models/reg-service');
5 const utils = require(global.utils); 5 const utils = require(global.utils);
6 const sign = global.yoho.sign; 6 const sign = global.yoho.sign;
7 const co = require('bluebird').coroutine; 7 const co = require('bluebird').coroutine;
@@ -54,7 +54,7 @@ class Reg { @@ -54,7 +54,7 @@ class Reg {
54 let inviteCode = req.query.inviteCode; 54 let inviteCode = req.query.inviteCode;
55 55
56 if (inviteCode) { 56 if (inviteCode) {
57 - let inviteUserInfo = yield RegService.inviteUserInfo(inviteCode); 57 + let inviteUserInfo = yield req.ctx(RegServiceModel).inviteUserInfo(inviteCode);
58 58
59 inviteValue = _.get(inviteUserInfo, 'data.trendWord', inviteCode); 59 inviteValue = _.get(inviteUserInfo, 'data.trendWord', inviteCode);
60 } 60 }
@@ -65,7 +65,7 @@ class Reg { @@ -65,7 +65,7 @@ class Reg {
65 localCss: true, 65 localCss: true,
66 width750: true, 66 width750: true,
67 inviteValue: inviteValue, 67 inviteValue: inviteValue,
68 - countrys: RegService.getAreaData() // 地区信息列表 68 + countrys: req.ctx(RegServiceModel).getAreaData() // 地区信息列表
69 }); 69 });
70 })().catch(next); 70 })().catch(next);
71 } 71 }
@@ -109,7 +109,7 @@ class Reg { @@ -109,7 +109,7 @@ class Reg {
109 } 109 }
110 110
111 co(function* () { 111 co(function* () {
112 - let validMobileCodeResult = yield RegService.validMobileCode(area, mobile, smsCode); 112 + let validMobileCodeResult = yield req.ctx(RegServiceModel).validMobileCode(area, mobile, smsCode);
113 113
114 if (!validMobileCodeResult.code) { 114 if (!validMobileCodeResult.code) {
115 return res.json(validMobileCodeResult); 115 return res.json(validMobileCodeResult);
@@ -121,7 +121,7 @@ class Reg { @@ -121,7 +121,7 @@ class Reg {
121 return res.json(validMobileCodeResult); 121 return res.json(validMobileCodeResult);
122 } 122 }
123 123
124 - let regMobileAesResult = yield RegService.regMobileAes(area, mobile, password, 124 + let regMobileAesResult = yield req.ctx(RegServiceModel).regMobileAes(area, mobile, password,
125 shoppingKey, smsCode, inviteCode, isFromMy, from); 125 shoppingKey, smsCode, inviteCode, isFromMy, from);
126 126
127 if (regMobileAesResult.code !== 200 || !regMobileAesResult.data || 127 if (regMobileAesResult.code !== 200 || !regMobileAesResult.data ||
@@ -192,7 +192,7 @@ class Reg { @@ -192,7 +192,7 @@ class Reg {
192 192
193 193
194 // 向手机发送注册验证码 194 // 向手机发送注册验证码
195 - RegService.sendCodeToMobile(area, mobile).then((result) => { 195 + req.ctx(RegServiceModel).sendCodeToMobile(area, mobile).then((result) => {
196 if (result.code !== 200) { 196 if (result.code !== 200) {
197 data.message = result.message; 197 data.message = result.message;
198 return res.json(data); 198 return res.json(data);
@@ -6,7 +6,7 @@ const moment = require('moment'); @@ -6,7 +6,7 @@ const moment = require('moment');
6 const cookie = global.yoho.cookie; 6 const cookie = global.yoho.cookie;
7 const EventEmitter = require('events'); 7 const EventEmitter = require('events');
8 const utils = require(global.utils); 8 const utils = require(global.utils);
9 -const RegService = require('../models/reg-service'); 9 +const RegServiceModel = require('../models/reg-service');
10 const PhoneService = require('../models/phone-service'); 10 const PhoneService = require('../models/phone-service');
11 const AuthHelper = require('../models/auth-helper'); 11 const AuthHelper = require('../models/auth-helper');
12 const LoginNewModel = require('../models/login-new'); 12 const LoginNewModel = require('../models/login-new');
@@ -41,7 +41,7 @@ class SmsLogin { @@ -41,7 +41,7 @@ class SmsLogin {
41 width750: true, 41 width750: true,
42 localCss: true, 42 localCss: true,
43 banner: banner, 43 banner: banner,
44 - countrys: RegService.getAreaData(), // 地区信息列表 44 + countrys: req.ctx(RegServiceModel).getAreaData(), // 地区信息列表
45 backUrl: 'javascript:history.go(-1)', // eslint-disable-line 45 backUrl: 'javascript:history.go(-1)', // eslint-disable-line
46 loginUrl: '/passport/login', 46 loginUrl: '/passport/login',
47 registerUrl: '/passport/reg/index', // 注册的URL链接 47 registerUrl: '/passport/reg/index', // 注册的URL链接
@@ -334,7 +334,7 @@ class SmsLogin { @@ -334,7 +334,7 @@ class SmsLogin {
334 // 验证注册的标识码是否有效 334 // 验证注册的标识码是否有效
335 let resultCopy = null; 335 let resultCopy = null;
336 336
337 - RegService.regMobileAes(area, mobile, password, 337 + req.ctx(RegServiceModel).regMobileAes(area, mobile, password,
338 shoppingKey, registerCode, null, clientIp, from).then(result => { 338 shoppingKey, registerCode, null, clientIp, from).then(result => {
339 if (!result.code || result.code !== 200) { 339 if (!result.code || result.code !== 200) {
340 return res.send(result); 340 return res.send(result);
@@ -6,12 +6,14 @@ @@ -6,12 +6,14 @@
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
9 -  
10 -const api = global.yoho.API;  
11 const aes = require('./aes-pwd'); 9 const aes = require('./aes-pwd');
12 const FROM = require('../../../config/from'); 10 const FROM = require('../../../config/from');
13 11
14 -const RegService = { 12 +class RegServiceModel extends global.yoho.BaseModel {
  13 + constructor(ctx) {
  14 + super(ctx);
  15 + }
  16 +
15 getAreaData() { 17 getAreaData() {
16 return [ 18 return [
17 { 19 {
@@ -63,26 +65,27 @@ const RegService = { @@ -63,26 +65,27 @@ const RegService = {
63 selected: false, 65 selected: false,
64 name: '中国香港' 66 name: '中国香港'
65 }]; 67 }];
66 - }, 68 + }
  69 +
67 sendCodeToMobile(area, mobile) { 70 sendCodeToMobile(area, mobile) {
68 - let params = { 71 + return this.post({data: {
69 method: 'app.register.sendRegCodeToMobile', 72 method: 'app.register.sendRegCodeToMobile',
70 area: area, 73 area: area,
71 mobile: mobile 74 mobile: mobile
72 - }; 75 + }});
  76 + }
73 77
74 - return api.post('', params);  
75 - },  
76 validMobileCode(area, mobile, code) { 78 validMobileCode(area, mobile, code) {
77 - let params = {  
78 - method: 'app.register.validRegCode',  
79 - area: area,  
80 - mobile: mobile,  
81 - code: code  
82 - }; 79 + return this.post({
  80 + data: {
  81 + method: 'app.register.validRegCode',
  82 + area: area,
  83 + mobile: mobile,
  84 + code: code
  85 + }
  86 + });
  87 + }
83 88
84 - return api.post('', params);  
85 - },  
86 regMobile(area, mobile, password, shoppingKey) { 89 regMobile(area, mobile, password, shoppingKey) {
87 let params = { 90 let params = {
88 method: 'app.passport.register', 91 method: 'app.passport.register',
@@ -95,8 +98,9 @@ const RegService = { @@ -95,8 +98,9 @@ const RegService = {
95 params.shopping_key = shoppingKey; 98 params.shopping_key = shoppingKey;
96 } 99 }
97 100
98 - return api.post('', params);  
99 - }, 101 + return this.post({ data: params});
  102 + }
  103 +
100 regMobileAes(area, mobile, password, shoppingKey, smsCode, inviteCode, isFromMy, clientIp, from) { 104 regMobileAes(area, mobile, password, shoppingKey, smsCode, inviteCode, isFromMy, clientIp, from) {
101 isFromMy = isFromMy || '0'; 105 isFromMy = isFromMy || '0';
102 106
@@ -115,24 +119,22 @@ const RegService = { @@ -115,24 +119,22 @@ const RegService = {
115 params.shopping_key = shoppingKey; 119 params.shopping_key = shoppingKey;
116 } 120 }
117 121
118 - return api.post('', params, {  
119 - headers: {  
120 - 'user-agent': 'yoho/nodejs',  
121 - 'X-YOHO-IP': clientIp,  
122 - 'X-Forwarded-For': clientIp  
123 - } 122 + return this.post({
  123 + data: params
124 }); 124 });
125 - }, 125 + }
126 126
127 /** 127 /**
128 * 好友邀请信息 128 * 好友邀请信息
129 */ 129 */
130 inviteUserInfo(inviteCode) { 130 inviteUserInfo(inviteCode) {
131 - return api.get('', {  
132 - method: 'app.invitecode.userinfo',  
133 - inviteCode: inviteCode 131 + return this.get({
  132 + data: {
  133 + method: 'app.invitecode.userinfo',
  134 + inviteCode: inviteCode
  135 + }
134 }); 136 });
135 } 137 }
136 -}; 138 +}
137 139
138 -module.exports = RegService; 140 +module.exports = RegServiceModel;