Merge branch 'feature/platform-basic' of http://git.yoho.cn/fe/yoho-activity-pla…
…tform into feature/platform-basic
Showing
6 changed files
with
62 additions
and
20 deletions
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | * @date: 2017/6/23 | 4 | * @date: 2017/6/23 |
5 | */ | 5 | */ |
6 | 'use strict'; | 6 | 'use strict'; |
7 | +const cors = require('cors'); | ||
7 | const express = require('express'); | 8 | const express = require('express'); |
8 | const config = require('./config'); | 9 | const config = require('./config'); |
9 | const bluebird = require('bluebird'); | 10 | const bluebird = require('bluebird'); |
@@ -34,7 +35,6 @@ app.use(bodyParser.urlencoded({ | @@ -34,7 +35,6 @@ app.use(bodyParser.urlencoded({ | ||
34 | })); | 35 | })); |
35 | app.use(cookieParser()); | 36 | app.use(cookieParser()); |
36 | app.use(global.yoho.httpCtx()); | 37 | app.use(global.yoho.httpCtx()); |
37 | - | ||
38 | app.use(session({ | 38 | app.use(session({ |
39 | proxy: true, | 39 | proxy: true, |
40 | resave: false, | 40 | resave: false, |
@@ -64,6 +64,9 @@ const middleware = require('./middleware'); | @@ -64,6 +64,9 @@ const middleware = require('./middleware'); | ||
64 | 64 | ||
65 | try { | 65 | try { |
66 | 66 | ||
67 | + // 允许跨域 | ||
68 | + app.use(cors()); | ||
69 | + | ||
67 | // 用户信息 | 70 | // 用户信息 |
68 | app.use(middleware.user); | 71 | app.use(middleware.user); |
69 | 72 |
@@ -5,10 +5,16 @@ | @@ -5,10 +5,16 @@ | ||
5 | */ | 5 | */ |
6 | const ArticleModel = require('../models/article'); | 6 | const ArticleModel = require('../models/article'); |
7 | 7 | ||
8 | -const GET_ARTICLES_SUCCESS = '获取文章列表成功'; | ||
9 | const ADD_ARTICLE_SUCCESS = '文章发表成功'; | 8 | const ADD_ARTICLE_SUCCESS = '文章发表成功'; |
9 | +const GET_ARTICLES_SUCCESS = '获取文章列表成功'; | ||
10 | 10 | ||
11 | -function all(req, res) { | 11 | +const article = { |
12 | + /** | ||
13 | + * 所有文章 | ||
14 | + * @param req | ||
15 | + * @param res | ||
16 | + */ | ||
17 | + all(req, res) { | ||
12 | req.ctx(ArticleModel).allArticles() | 18 | req.ctx(ArticleModel).allArticles() |
13 | .then(result => { | 19 | .then(result => { |
14 | res.json({ | 20 | res.json({ |
@@ -18,9 +24,14 @@ function all(req, res) { | @@ -18,9 +24,14 @@ function all(req, res) { | ||
18 | }); | 24 | }); |
19 | }); | 25 | }); |
20 | 26 | ||
21 | -} | 27 | + }, |
22 | 28 | ||
23 | -function add(req, res) { | 29 | + /** |
30 | + * 创建文章 | ||
31 | + * @param req | ||
32 | + * @param res | ||
33 | + */ | ||
34 | + add(req, res) { | ||
24 | const params = req.body; | 35 | const params = req.body; |
25 | 36 | ||
26 | req.ctx(ArticleModel).createArticle(params) | 37 | req.ctx(ArticleModel).createArticle(params) |
@@ -30,9 +41,8 @@ function add(req, res) { | @@ -30,9 +41,8 @@ function add(req, res) { | ||
30 | message: ADD_ARTICLE_SUCCESS | 41 | message: ADD_ARTICLE_SUCCESS |
31 | }); | 42 | }); |
32 | }); | 43 | }); |
33 | -} | ||
34 | - | ||
35 | -module.exports = { | ||
36 | - all, | ||
37 | - add | 44 | + } |
38 | }; | 45 | }; |
46 | + | ||
47 | + | ||
48 | +module.exports = article; |
1 | +/** | ||
2 | + * 短信controller | ||
3 | + * @author: leo <qi.li@yoho.cn> | ||
4 | + * @date: 2017/06/26 | ||
5 | + */ | ||
1 | 'use strict'; | 6 | 'use strict'; |
2 | const _ = require('lodash'); | 7 | const _ = require('lodash'); |
3 | const EventEmitter = require('events'); | 8 | const EventEmitter = require('events'); |
@@ -10,17 +15,14 @@ const ANONYMOUS_USER = '匿名用户'; | @@ -10,17 +15,14 @@ const ANONYMOUS_USER = '匿名用户'; | ||
10 | const CODE_REQUIRED = '请输入校验码'; | 15 | const CODE_REQUIRED = '请输入校验码'; |
11 | const GET_USER_INFO_FAILED = '获取用户信息失败'; | 16 | const GET_USER_INFO_FAILED = '获取用户信息失败'; |
12 | 17 | ||
13 | -// const BAD_PASSWORD = '密码格式不正确'; | ||
14 | -// const PASSWORD_REQUIRED = '请输入密码'; | ||
15 | -// const PASSWORD_LENGTH_ERROR = '密码6-20位,请重新输入'; | ||
16 | - | ||
17 | -/** | 18 | +const sms = { |
19 | + /** | ||
18 | * 发送短信验证码 | 20 | * 发送短信验证码 |
19 | * @param req | 21 | * @param req |
20 | * @param res | 22 | * @param res |
21 | * @returns {*|boolean} | 23 | * @returns {*|boolean} |
22 | */ | 24 | */ |
23 | -exports.send = (req, res) => { | 25 | + send(req, res) { |
24 | const em = new EventEmitter(); | 26 | const em = new EventEmitter(); |
25 | const area = (req.body.area || '').trim(); | 27 | const area = (req.body.area || '').trim(); |
26 | const mobile = (req.body.mobile || '').trim(); | 28 | const mobile = (req.body.mobile || '').trim(); |
@@ -59,9 +61,24 @@ exports.send = (req, res) => { | @@ -59,9 +61,24 @@ exports.send = (req, res) => { | ||
59 | code: 400, | 61 | code: 400, |
60 | message: '请填写手机号' | 62 | message: '请填写手机号' |
61 | }); | 63 | }); |
62 | -}; | 64 | + }, |
65 | + | ||
66 | + /** | ||
67 | + * 验证码校验 | ||
68 | + * @param req | ||
69 | + * @param res | ||
70 | + */ | ||
71 | + check(req, res) { | ||
72 | + console.log(req, res); | ||
73 | + }, | ||
63 | 74 | ||
64 | -exports.login = (req, res, next) => { | 75 | + /** |
76 | + * 验证码登录 | ||
77 | + * @param req | ||
78 | + * @param res | ||
79 | + * @param next | ||
80 | + */ | ||
81 | + login(req, res, next) { | ||
65 | const code = (req.body.code || '').trim(); | 82 | const code = (req.body.code || '').trim(); |
66 | const area = _.get(req.session, 'smsLogin.area', ''); | 83 | const area = _.get(req.session, 'smsLogin.area', ''); |
67 | const mobile = _.get(req.session, 'smsLogin.mobile', ''); | 84 | const mobile = _.get(req.session, 'smsLogin.mobile', ''); |
@@ -160,4 +177,7 @@ exports.login = (req, res, next) => { | @@ -160,4 +177,7 @@ exports.login = (req, res, next) => { | ||
160 | 177 | ||
161 | }) | 178 | }) |
162 | .catch(next); | 179 | .catch(next); |
180 | + } | ||
163 | }; | 181 | }; |
182 | + | ||
183 | +module.exports = sms; |
@@ -14,5 +14,6 @@ const router = express.Router(); // eslint-disable-line | @@ -14,5 +14,6 @@ const router = express.Router(); // eslint-disable-line | ||
14 | // SMS 短信 | 14 | // SMS 短信 |
15 | router.post('/sms/login', sms.login); | 15 | router.post('/sms/login', sms.login); |
16 | router.post('/sms/sendCode', sms.send); | 16 | router.post('/sms/sendCode', sms.send); |
17 | +router.post('/sms/checkCode', sms.check); | ||
17 | 18 | ||
18 | module.exports = router; | 19 | module.exports = router; |
@@ -40,6 +40,7 @@ | @@ -40,6 +40,7 @@ | ||
40 | "connect-memcached": "^0.2.0", | 40 | "connect-memcached": "^0.2.0", |
41 | "connect-multiparty": "^2.0.0", | 41 | "connect-multiparty": "^2.0.0", |
42 | "cookie-parser": "^1.4.3", | 42 | "cookie-parser": "^1.4.3", |
43 | + "cors": "^2.8.3", | ||
43 | "cssnano": "^3.10.0", | 44 | "cssnano": "^3.10.0", |
44 | "express": "^4.15.3", | 45 | "express": "^4.15.3", |
45 | "fast-safe-stringify": "^1.2.0", | 46 | "fast-safe-stringify": "^1.2.0", |
@@ -1599,6 +1599,13 @@ core-util-is@~1.0.0: | @@ -1599,6 +1599,13 @@ core-util-is@~1.0.0: | ||
1599 | version "1.0.2" | 1599 | version "1.0.2" |
1600 | resolved "http://npm.yoho.cn/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" | 1600 | resolved "http://npm.yoho.cn/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" |
1601 | 1601 | ||
1602 | +cors@^2.8.3: | ||
1603 | + version "2.8.3" | ||
1604 | + resolved "http://npm.yoho.cn/cors/-/cors-2.8.3.tgz#4cf78e1d23329a7496b2fc2225b77ca5bb5eb802" | ||
1605 | + dependencies: | ||
1606 | + object-assign "^4" | ||
1607 | + vary "^1" | ||
1608 | + | ||
1602 | cosmiconfig@^2.1.0, cosmiconfig@^2.1.1: | 1609 | cosmiconfig@^2.1.0, cosmiconfig@^2.1.1: |
1603 | version "2.1.3" | 1610 | version "2.1.3" |
1604 | resolved "http://npm.yoho.cn/cosmiconfig/-/cosmiconfig-2.1.3.tgz#952771eb0dddc1cb3fa2f6fbe51a522e93b3ee0a" | 1611 | resolved "http://npm.yoho.cn/cosmiconfig/-/cosmiconfig-2.1.3.tgz#952771eb0dddc1cb3fa2f6fbe51a522e93b3ee0a" |
@@ -4943,7 +4950,7 @@ object-assign@^3.0.0: | @@ -4943,7 +4950,7 @@ object-assign@^3.0.0: | ||
4943 | version "3.0.0" | 4950 | version "3.0.0" |
4944 | resolved "http://npm.yoho.cn/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2" | 4951 | resolved "http://npm.yoho.cn/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2" |
4945 | 4952 | ||
4946 | -object-assign@^4.0.1, object-assign@^4.1.0: | 4953 | +object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0: |
4947 | version "4.1.1" | 4954 | version "4.1.1" |
4948 | resolved "http://npm.yoho.cn/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" | 4955 | resolved "http://npm.yoho.cn/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" |
4949 | 4956 | ||
@@ -7869,7 +7876,7 @@ validate-npm-package-name@^3.0.0, validate-npm-package-name@~3.0.0: | @@ -7869,7 +7876,7 @@ validate-npm-package-name@^3.0.0, validate-npm-package-name@~3.0.0: | ||
7869 | dependencies: | 7876 | dependencies: |
7870 | builtins "^1.0.3" | 7877 | builtins "^1.0.3" |
7871 | 7878 | ||
7872 | -vary@~1.1.0, vary@~1.1.1: | 7879 | +vary@^1, vary@~1.1.0, vary@~1.1.1: |
7873 | version "1.1.1" | 7880 | version "1.1.1" |
7874 | resolved "http://npm.yoho.cn/vary/-/vary-1.1.1.tgz#67535ebb694c1d52257457984665323f587e8d37" | 7881 | resolved "http://npm.yoho.cn/vary/-/vary-1.1.1.tgz#67535ebb694c1d52257457984665323f587e8d37" |
7875 | 7882 |
-
Please register or login to post a comment