JOE
2018-10-25 5ea03cabad9604f8116d25ab5b3505d01c7139d5
add authorization
16 files modified
1 files added
1 files deleted
1075 ■■■■■ changed files
config/config.js 9 ●●●● patch | view | raw | blame | history
model/taxonomy.js 50 ●●●● patch | view | raw | blame | history
package-lock.json 25 ●●●●● patch | view | raw | blame | history
package.json 3 ●●●● patch | view | raw | blame | history
routes/accounts.js 131 ●●●●● patch | view | raw | blame | history
routes/api/accounts.js 2 ●●● patch | view | raw | blame | history
routes/api/taxonomy.js 31 ●●●● patch | view | raw | blame | history
routes/index.js 63 ●●●●● patch | view | raw | blame | history
routes/modules.js 135 ●●●●● patch | view | raw | blame | history
routes/roles.js 147 ●●●●● patch | view | raw | blame | history
routes/segment.js 96 ●●●●● patch | view | raw | blame | history
routes/taxonomy.js 104 ●●●● patch | view | raw | blame | history
server.js 5 ●●●● patch | view | raw | blame | history
util/util.js 135 ●●●● patch | view | raw | blame | history
views/error.html 17 ●●●●● patch | view | raw | blame | history
views/index.html 10 ●●●●● patch | view | raw | blame | history
views/login.html 23 ●●●● patch | view | raw | blame | history
views/signup.html 89 ●●●●● patch | view | raw | blame | history
config/config.js
....@@ -1,12 +1,17 @@
11 module.exports = {
22 path: {
33 cdn: 'http://dmp.3ps.io/dmp',
4
- context: 'http://dmp.3ps.io/mobidmp',
4
+ context: 'http://localhost:3303',
55 },
66 secret: 'AMDMP_2018',
77 db: {
88 host: '127.0.0.1',
99 port: '27017',
10
- name: 'amdmp'
10
+ name: 'mobidmp'
11
+ },
12
+ redis: {
13
+ host: 'mercury.3ps.io',
14
+ port: '65100',
15
+ db: 15
1116 }
1217 };
model/taxonomy.js
....@@ -1,24 +1,46 @@
11 const mongoose = require('mongoose');
22 const Schema = mongoose.Schema;
33
4
-const rule = new Schema({
5
- type: {type: String, required: true },
6
- value: String
7
-});
4
+// const rule = new Schema({
5
+// type: {type: String, required: true },
6
+// value: String
7
+// });
88
9
-const taxonomy = new Schema({
10
- taxonomy_id: {type: String, required: true },
11
- name: {type: String, required: true },
12
- referrer_id: {type: String, required: true },
13
- rules: [rule]
9
+// const taxonomy = new Schema({
10
+// taxonomy_id: {type: String, required: true },
11
+// key_taxonomy_id: {type: String, required: true },
12
+// key_name: {type: String, required: true },
13
+// owner: {type: String, required: true },
14
+// name: {type: String, required: true },
15
+// referrer_id: {type: String, required: true },
16
+// rules: [rule]
17
+// });
18
+
19
+// const TaxonomySchema = new Schema({
20
+// account_id: {type: String, required: true},
21
+// keyname: {type: String, required: true},
22
+// accessibles: String,
23
+// taxonomies: [taxonomy]
24
+// });
25
+
26
+const rule = new Schema({
27
+ order: {type: Number, required: true },
28
+ group_operation: {type: String, required: true },
29
+ criteria_key: {type: String, required: true },
30
+ values: {type: String, required: true },
31
+ longitude: String,
32
+ latitude: String,
1433 });
1534
1635 const TaxonomySchema = new Schema({
17
- account_id: {type: String, required: true},
18
- keyname: {type: String, required: true},
19
- accessibles: String,
20
- taxonomies: [taxonomy]
21
-});
36
+ taxonomy_id: {type: String, required: true },
37
+ key_taxonomy_id: String,
38
+ key_name: String,
39
+ owner: String,
40
+ name: String,
41
+ referrer_id: String,
42
+ rules: [rule]
43
+}, { collection: 'taxonomy' });
2244
2345 // Export the model
2446 module.exports = mongoose.model('taxonomy', TaxonomySchema);
package-lock.json
....@@ -1279,6 +1279,11 @@
12791279 "is-obj": "1.0.1"
12801280 }
12811281 },
1282
+ "double-ended-queue": {
1283
+ "version": "2.1.0-0",
1284
+ "resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz",
1285
+ "integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw="
1286
+ },
12821287 "duplexer": {
12831288 "version": "0.1.1",
12841289 "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
....@@ -3833,6 +3838,26 @@
38333838 "strip-indent": "1.0.1"
38343839 }
38353840 },
3841
+ "redis": {
3842
+ "version": "2.8.0",
3843
+ "resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz",
3844
+ "integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==",
3845
+ "requires": {
3846
+ "double-ended-queue": "2.1.0-0",
3847
+ "redis-commands": "1.4.0",
3848
+ "redis-parser": "2.6.0"
3849
+ }
3850
+ },
3851
+ "redis-commands": {
3852
+ "version": "1.4.0",
3853
+ "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.4.0.tgz",
3854
+ "integrity": "sha512-cu8EF+MtkwI4DLIT0x9P8qNTLFhQD4jLfxLR0cCNkeGzs87FN6879JOJwNQR/1zD7aSYNbU0hgsV9zGY71Itvw=="
3855
+ },
3856
+ "redis-parser": {
3857
+ "version": "2.6.0",
3858
+ "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
3859
+ "integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
3860
+ },
38363861 "regex-not": {
38373862 "version": "1.0.2",
38383863 "resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz",
package.json
....@@ -18,7 +18,8 @@
1818 "mongoose-geojson-schema": "^2.1.3",
1919 "morgan": "~1.9.0",
2020 "mustache-express": "^1.2.7",
21
- "node-sass-middleware": "0.11.0"
21
+ "node-sass-middleware": "0.11.0",
22
+ "redis": "^2.8.0"
2223 },
2324 "devDependencies": {
2425 "nodemon": "^1.18.4"
routes/accounts.js
....@@ -3,6 +3,7 @@
33 const cookie = require('cookie');
44 const bcrypt = require('bcrypt');
55 const mongoose = require('mongoose');
6
+var url = require('url');
67
78 const config = require('../config/config.js');
89 const util = require('../util/util.js');
....@@ -12,73 +13,103 @@
1213 const Roles = require('../model/role');
1314
1415 router.get('/', function(req, res, next) {
15
- Account.find({}).populate('role', 'name').
16
- exec(function (err, accounts) {
17
- // param
18
- const param = util.initParam();
19
- param.accounts = accounts;
20
- res.render('accounts/list', param);
21
- });
16
+ util.verifyAuth(req).then(function (isAuth){
17
+ if(isAuth) {
18
+ Account.find({}).populate('role', 'name').
19
+ exec(function (err, accounts) {
20
+ // param
21
+ const param = util.initParam();
22
+ param.accounts = accounts;
23
+ res.render('accounts/list', param);
24
+ });
25
+ } else {
26
+ res.render('error', util.initError(406));
27
+ }
28
+ });
2229 });
2330
2431 router.get('/create', function(req, res, next) {
25
- Account.find({}).then(async function (accounts) {
26
- const param = util.initParam();
27
- param.accounts = accounts;
28
- param.roles = await Roles.find({}).exec();
29
- param.modules = await Modules.find({}).exec();
30
- res.render('accounts/create', param);
31
- }).catch(err => {
32
- util.reportError(err, res);
32
+ util.verifyAuth(req).then(function (isAuth){
33
+ if(isAuth) {
34
+ Account.find({}).then(async function (accounts) {
35
+ const param = util.initParam();
36
+ param.accounts = accounts;
37
+ param.roles = await Roles.find({}).exec();
38
+ param.modules = await Modules.find({}).exec();
39
+ res.render('accounts/create', param);
40
+ }).catch(err => {
41
+ util.reportError(err, res);
42
+ });
43
+ } else {
44
+ res.render('error', util.initError(406));
45
+ }
3346 });
3447 });
3548
3649 router.post('/create', function(req, res, next) {
37
- const data = Object.assign(req.body) || {};
38
- let hash = bcrypt.hashSync(data.passwd, 10);
39
- data.passwd = hash;
50
+ util.verifyAuth(req).then(function (isAuth){
51
+ if(isAuth) {
52
+ const data = Object.assign(req.body) || {};
53
+ let hash = bcrypt.hashSync(data.passwd, 10);
54
+ data.passwd = hash;
4055
41
- Account.create(data).then(role => {
42
- res.redirect(config.path.context + '/accounts/');
43
- }).catch(err => {
44
- Modules.find({}).then(async function (modules) {
45
- const param = util.initParam();
46
- param.error = util.errorJson(err).result_msg;
47
- param.roles = await Roles.find({}).exec();
48
- param.modules = await Modules.find({}).exec();
49
- param.data = data;
50
- res.render('accounts/create', param);
51
- }).catch(err => {
52
- util.reportError(err, res);
53
- });
56
+ Account.create(data).then(role => {
57
+ res.redirect(config.path.context + '/accounts/');
58
+ }).catch(err => {
59
+ Modules.find({}).then(async function (modules) {
60
+ const param = util.initParam();
61
+ param.error = util.errorJson(err).result_msg;
62
+ param.roles = await Roles.find({}).exec();
63
+ param.modules = await Modules.find({}).exec();
64
+ param.data = data;
65
+ res.render('accounts/create', param);
66
+ }).catch(err => {
67
+ util.reportError(err, res);
68
+ });
69
+ });
70
+ } else {
71
+ res.render('error', util.initError(406));
72
+ }
5473 });
5574 });
5675
5776
5877 router.get('/:account_id', function(req, res, next) {
59
- Account.findOne({_id: req.params.account_id}).then(async function (account) {
60
- const param = util.initParam();
61
- param.roles = await Roles.find({}).exec();
62
- param.modules = await Modules.find({}).exec();
63
- param.account = account;
64
- res.render('accounts/update', param);
65
- }).catch(err => {
66
- util.reportError(err, res);
78
+ util.verifyAuth(req).then(function (isAuth){
79
+ if(isAuth) {
80
+ Account.findOne({_id: req.params.account_id}).then(async function (account) {
81
+ const param = util.initParam();
82
+ param.roles = await Roles.find({}).exec();
83
+ param.modules = await Modules.find({}).exec();
84
+ param.account = account;
85
+ res.render('accounts/update', param);
86
+ }).catch(err => {
87
+ util.reportError(err, res);
88
+ });
89
+ } else {
90
+ res.render('error', util.initError(406));
91
+ }
6792 });
6893 });
6994
7095 router.post('/:account_id', function(req, res, next) {
71
- const data = Object.assign(req.body) || {};
72
- Account.updateOne({_id: req.body.id}, { $set: data}, async function(err, response) {
73
- const param = util.initParam();
74
- if(err) {
75
- param.error = util.errorJson(err).result_msg;
76
- param.roles = await Roles.find({}).exec();
77
- param.modules = await Modules.find({}).exec();
78
- param.account = data;
79
- res.render('accounts/update', param);
80
- } else {
81
- res.redirect(config.path.context + '/accounts/');
96
+ util.verifyAuth(req).then(function (isAuth){
97
+ if(isAuth) {
98
+ const data = Object.assign(req.body) || {};
99
+ Account.updateOne({_id: req.body.id}, { $set: data}, async function(err, response) {
100
+ const param = util.initParam();
101
+ if(err) {
102
+ param.error = util.errorJson(err).result_msg;
103
+ param.roles = await Roles.find({}).exec();
104
+ param.modules = await Modules.find({}).exec();
105
+ param.account = data;
106
+ res.render('accounts/update', param);
107
+ } else {
108
+ res.redirect(config.path.context + '/accounts/');
109
+ }
110
+ });
111
+ } else {
112
+ res.render('error', util.initError(406));
82113 }
83114 });
84115 });
routes/api/accounts.js
....@@ -21,7 +21,7 @@
2121 });
2222 });
2323
24
-router.get('/', function(req, res, next) {
24
+router.get('/', async function(req, res, next) {
2525 Account.find({}).then(function (accounts) {
2626 res.json(accounts);
2727 }).catch(err => {
routes/api/taxonomy.js
....@@ -9,7 +9,6 @@
99
1010 router.get('/:key_taxonomy_id', function(req, res, next) {
1111 Taxonomy.findOne({_id: req.params.key_taxonomy_id}).then(function (taxonomy) {
12
- console.log(taxonomy);
1312 res.json(taxonomy);
1413 }).catch(err => {
1514 util.reportError(err, res);
....@@ -17,15 +16,15 @@
1716 });
1817
1918 router.get('/', function(req, res, next) {
20
- Taxonomy.find({}).then(function (taxonomys) {
21
- res.json(taxonomys);
22
- }).catch(err => {
19
+ Taxonomy.find({}).limit(100).then(function (taxonomys) {
20
+ res.json(taxonomys);
21
+ }).catch(err => {
2322 util.reportError(err, res);
2423 });
2524 });
2625
2726 router.get('/search/name', function(req, res, next) {
28
- Taxonomy.find({keyname: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
27
+ Taxonomy.find({key_name: new RegExp(req.query.keyname, 'i')}).limit(100).then(function (taxonomys) {
2928 res.json(taxonomys);
3029 }).catch(err => {
3130 util.reportError(err, res);
....@@ -33,16 +32,20 @@
3332 });
3433
3534 router.get('/search/location', function(req, res, next) {
36
- const filter = {};
37
- filter.loc = req.query.lon;
38
- filter.lat = req.query.lat;
39
- filter.radius = req.query.radius;
40
- filter.datetime = req.query.datetime;
41
- // Taxonomy.find({keyname: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
42
- res.json(filter);
43
- // });
35
+ // const filter = {};
36
+ // filter.rules = {};
37
+ // filter.rules.longitude = req.query.lon;
38
+ // filter.rules.latitude = req.query.lat;
39
+ // filter.radius = req.query.radius;
40
+ // filter.datetime = req.query.datetime;
41
+ // Taxonomy.find({key_name: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
42
+ Taxonomy.find({
43
+ "rules.longitude" : req.query.lon,
44
+ "rules.latitude" : req.query.lat
45
+ }).then(function (taxonomys) {
46
+ res.json(taxonomys);
47
+ });
4448 });
45
-
4649
4750 router.post('/', function(req, res, next) {
4851 const data = Object.assign(req.body) || {};
routes/index.js
....@@ -8,28 +8,32 @@
88 const util = require('../util/util.js');
99
1010 const Account = require('../model/account');
11
-const Role = require('../model/role');
11
+const Roles = require('../model/role');
12
+const Modules = require('../model/module');
1213
1314 router.get('/', function(req, res, next) {
14
- let result = {cdnRoot: config.path.cdn};
15
+ let param = util.initParam();
1516 let token;
1617 try{
1718 token = cookie.parse(req.headers.cookie).mobi_dmp;
1819 } catch(error) {
1920 token = '';
2021 }
22
+ console.log(token);
2123 if(token == '') {
22
- res.render('login', result);
24
+ res.render('login', param);
2325 } else {
24
- res.render('boards/dashboard', result);
26
+ res.render('boards/dashboard', param);
2527 }
2628 });
2729
2830 router.get('/signup', function(req, res, next) {
29
- let param = {cdnRoot: config.path.cdn};
30
- Role.find({}).then(function (roles) {
31
- param.roles = roles;
32
- res.render('signup', param);
31
+ Account.find({}).then(async function (accounts) {
32
+ const param = util.initParam();
33
+ param.accounts = accounts;
34
+ param.roles = await Roles.find({}).exec();
35
+ param.modules = await Modules.find({}).exec();
36
+ res.render('signup', param);
3337 }).catch(err => {
3438 util.reportError(err, res);
3539 });
....@@ -39,41 +43,62 @@
3943 const data = Object.assign(req.body) || {};
4044 let hash = bcrypt.hashSync(data.passwd, 10);
4145 data.passwd = hash;
46
+
4247 Account.create(data).then(account => {
43
- res.json({'account_id': account._id});
48
+ util.clearToken(req, res);
4449 }).catch(err => {
45
- util.reportError(err, res);
50
+ Modules.find({}).then(async function (modules) {
51
+ const param = util.initParam();
52
+ param.error = util.errorJson(err).result_msg;
53
+ param.roles = await Roles.find({}).exec();
54
+ param.modules = await Modules.find({}).exec();
55
+ param.data = data;
56
+ res.render('signup', param);
57
+ }).catch(err => {
58
+ util.reportError(err, res);
59
+ });
4660 });
4761 });
4862
4963 router.post('/login', function(req, res, next) {
50
- Account.findOne({login_id:req.body.loginId}).then(function (user) {
64
+ const loginId = req.body.login_id;
65
+ Account.findOne({login_id:loginId}).then(function (user) {
5166 let result = {cdnRoot: config.path.cdn};
5267 if(user == null) {
5368 result.invalidUser = true;
5469 res.render('login', result);
5570 } else if(!bcrypt.compareSync(req.body.password, user.passwd)) {
56
- result.email = req.body.loginId;
71
+ result.email = loginId;
5772 result.invalidPasswd = true;
5873 res.render('login', result);
5974 } else {
6075 const token = util.createToken({
61
- sessionData: req.body.loginId,
76
+ sessionData: loginId,
6277 maxAge: 3600
6378 });
6479
65
- res.setHeader('Set-Cookie', cookie.serialize('mobi_dmp', token, {
66
- maxAge: 60 * 60 * 24 * 7 // 1 week
67
- }));
68
-
69
- res.setHeader('Location', '/');
70
- res.end();
80
+ if(token) {
81
+ const redisKey = util.encrypt(loginId);
82
+ util.createAuth(redisKey, user, req).then(function() {
83
+ res.setHeader('Set-Cookie', cookie.serialize('mobi_dmp', token, {
84
+ maxAge: 60 * 60 * 24 * 7 // 1 week
85
+ }));
86
+ res.redirect(config.path.context + '/');
87
+ });
88
+ } else {
89
+ result.email = loginId;
90
+ result.invalidTokken = true;
91
+ res.render('login', result);
92
+ }
7193 }
7294 }).catch(err => {
7395 util.reportError(err, res);
7496 });
7597 });
7698
99
+router.get('/logout', function(req, res){
100
+ util.clearToken(req, res);
101
+});
77102
78103 // import web router
79104 router.use('/segment', require('./segment'));
routes/modules.js
....@@ -9,74 +9,103 @@
99 const Roles = require('../model/role');
1010
1111 router.get('/', function(req, res, next) {
12
- Modules.find({}).then(function (modules) {
13
- const param = util.initParam();
14
- param.modules = modules;
15
- res.render('modules/list', param);
16
- }).catch(err => {
17
- util.reportError(err, res);
18
- });
12
+ util.verifyAuth(req).then(function (isAuth){
13
+ if(isAuth) {
14
+ Modules.find({}).then(function (modules) {
15
+ const param = util.initParam();
16
+ param.modules = modules;
17
+ res.render('modules/list', param);
18
+ }).catch(err => {
19
+ util.reportError(err, res);
20
+ });
21
+ } else {
22
+ res.render('error', util.initError(406));
23
+ }
24
+ });
1925 });
2026
2127 router.get('/create', function(req, res, next) {
22
- Modules.find({}).then(function (modules) {
23
- const param = util.initParam();
24
- param.modules = modules;
25
- res.render('modules/create', param);
26
- }).catch(err => {
27
- util.reportError(err, res);
28
- });
28
+ util.verifyAuth(req).then(function (isAuth){
29
+ if(isAuth) {
30
+ Modules.find({}).then(function (modules) {
31
+ const param = util.initParam();
32
+ param.modules = modules;
33
+ res.render('modules/create', param);
34
+ }).catch(err => {
35
+ util.reportError(err, res);
36
+ });
37
+ } else {
38
+ res.render('error', util.initError(406));
39
+ }
40
+ });
2941 });
3042
3143 router.post('/create', function(req, res, next) {
32
- const data = Object.assign(req.body) || {};
33
- Modules.create(data).then(role => {
34
- res.redirect(config.path.context + '/modules/');
35
- }).catch(err => {
36
- Modules.find({}).then(function (modules) {
37
- const param = util.initParam();
38
- param.error = util.errorJson(err).result_msg;
39
- param.modules = modules;
40
- param.data = data;
41
- res.render('modules/create', param);
42
- }).catch(err => {
43
- util.reportError(err, res);
44
- });
45
- });
44
+ util.verifyAuth(req).then(function (isAuth){
45
+ if(isAuth) {
46
+ const data = Object.assign(req.body) || {};
47
+ Modules.create(data).then(role => {
48
+ res.redirect(config.path.context + '/modules/');
49
+ }).catch(err => {
50
+ Modules.find({}).then(function (modules) {
51
+ const param = util.initParam();
52
+ param.error = util.errorJson(err).result_msg;
53
+ param.modules = modules;
54
+ param.data = data;
55
+ res.render('modules/create', param);
56
+ }).catch(err => {
57
+ util.reportError(err, res);
58
+ });
59
+ });
60
+ } else {
61
+ res.render('error', util.initError(406));
62
+ }
63
+ });
4664 });
4765
48
-
4966 router.get('/:role_id', function(req, res, next) {
50
- Modules.find({}).then(function (modules) {
51
- const param = util.initParam();
52
- param.modules = modules;
53
- Modules.findOne({_id: req.params.role_id}).then(function (module) {
54
- param.module = module;
55
- res.render('modules/update', param);
56
- }).catch(err => {
57
- util.reportError(err, res);
58
- });
59
- }).catch(err => {
60
- util.reportError(err, res);
61
- });
67
+ util.verifyAuth(req).then(function (isAuth){
68
+ if(isAuth) {
69
+ Modules.find({}).then(function (modules) {
70
+ const param = util.initParam();
71
+ param.modules = modules;
72
+ Modules.findOne({_id: req.params.role_id}).then(function (module) {
73
+ param.module = module;
74
+ res.render('modules/update', param);
75
+ }).catch(err => {
76
+ util.reportError(err, res);
77
+ });
78
+ }).catch(err => {
79
+ util.reportError(err, res);
80
+ });
81
+ } else {
82
+ res.render('error', util.initError(406));
83
+ }
84
+ });
6285 });
6386
6487 router.post('/:module_id', function(req, res, next) {
65
- const data = Object.assign(req.body) || {};
66
- Modules.updateMany({_id: req.params.module_id}, { $set: data}, function(err, response) {
67
- const param = util.initParam();
68
- if(err) {
69
- param.error = util.errorJson(err).result_msg;
70
- Modules.find({}).then(function (modules) {
71
- param.modules = modules;
72
- res.render('modules/update', param);
73
- }).catch(err => {
74
- res.render('modules/update', param);
88
+ util.verifyAuth(req).then(function (isAuth){
89
+ if(isAuth) {
90
+ const data = Object.assign(req.body) || {};
91
+ Modules.updateMany({_id: req.params.module_id}, { $set: data}, function(err, response) {
92
+ const param = util.initParam();
93
+ if(err) {
94
+ param.error = util.errorJson(err).result_msg;
95
+ Modules.find({}).then(function (modules) {
96
+ param.modules = modules;
97
+ res.render('modules/update', param);
98
+ }).catch(err => {
99
+ res.render('modules/update', param);
100
+ });
101
+ } else {
102
+ res.redirect(config.path.context + '/modules/');
103
+ }
75104 });
76105 } else {
77
- res.redirect(config.path.context + '/modules/');
106
+ res.render('error', util.initError(406));
78107 }
79
- });
108
+ });
80109 });
81110
82111 module.exports = router;
routes/roles.js
....@@ -9,81 +9,114 @@
99 const Modules = require('../model/module');
1010
1111 router.get('/', function(req, res, next) {
12
- Roles.find({}).then(function (roles) {
13
- const param = util.initParam();
14
- param.roles = roles;
15
- res.render('roles/list', param);
16
- }).catch(err => {
17
- util.reportError(err, res);
18
- });
12
+ util.verifyAuth(req).then(function (isAuth){
13
+ if(isAuth) {
14
+ Roles.find({}).then(function (roles) {
15
+ const param = util.initParam();
16
+ param.roles = roles;
17
+ res.render('roles/list', param);
18
+ }).catch(err => {
19
+ util.reportError(err, res);
20
+ });
21
+ } else {
22
+ res.render('error', util.initError(406));
23
+ }
24
+ });
1925 });
2026
2127 router.get('/create', function(req, res, next) {
22
- Modules.find({}).then(function (modules) {
23
- const param = util.initParam();
24
- param.modules = modules;
25
- res.render('roles/create', param);
26
- }).catch(err => {
27
- util.reportError(err, res);
28
- });
28
+ util.verifyAuth(req).then(function (isAuth){
29
+ if(isAuth) {
30
+ Modules.find({}).then(function (modules) {
31
+ const param = util.initParam();
32
+ param.modules = modules;
33
+ res.render('roles/create', param);
34
+ }).catch(err => {
35
+ util.reportError(err, res);
36
+ });
37
+ } else {
38
+ res.render('error', util.initError(406));
39
+ }
40
+ });
2941 });
3042
3143 router.post('/create', function(req, res, next) {
32
- const data = Object.assign(req.body) || {};
33
- data.welcome_page_modile = util.generatePath(data.welcome_page_modile);
34
- Roles.create(data).then(role => {
35
- res.redirect(config.path.context + '/roles/');
36
- }).catch(err => {
37
- Modules.find({}).then(function (modules) {
38
- const param = util.initParam();
39
- param.modules = modules;
40
- param.error = util.errorJson(err).result_msg;
41
- param.data = data;
42
- res.render('roles/create', param);
43
- }).catch(err => {
44
- util.reportError(err, res);
45
- });
46
- });
44
+ util.verifyAuth(req).then(function (isAuth){
45
+ if(isAuth) {
46
+ const data = Object.assign(req.body) || {};
47
+ data.welcome_page_modile = util.generatePath(data.welcome_page_modile);
48
+ Roles.create(data).then(role => {
49
+ res.redirect(config.path.context + '/roles/');
50
+ }).catch(err => {
51
+ Modules.find({}).then(function (modules) {
52
+ const param = util.initParam();
53
+ param.modules = modules;
54
+ param.error = util.errorJson(err).result_msg;
55
+ param.data = data;
56
+ res.render('roles/create', param);
57
+ }).catch(err => {
58
+ util.reportError(err, res);
59
+ });
60
+ });
61
+ } else {
62
+ res.render('error', util.initError(406));
63
+ }
64
+ });
4765 });
4866
4967 router.get('/:role_id', function(req, res, next) {
50
- Modules.find({}).then(function (modules) {
51
- const param = util.initParam();
52
- param.modules = modules;
53
- Roles.findOne({_id: req.params.role_id}).then(function (role) {
54
- param.role = role;
55
- res.render('roles/update', param);
56
- }).catch(err => {
57
- util.reportError(err, res);
58
- });
59
- }).catch(err => {
60
- util.reportError(err, res);
61
- });
68
+ util.verifyAuth(req).then(function (isAuth){
69
+ if(isAuth) {
70
+ Modules.find({}).then(function (modules) {
71
+ const param = util.initParam();
72
+ param.modules = modules;
73
+ Roles.findOne({_id: req.params.role_id}).then(function (role) {
74
+ param.role = role;
75
+ res.render('roles/update', param);
76
+ }).catch(err => {
77
+ util.reportError(err, res);
78
+ });
79
+ }).catch(err => {
80
+ util.reportError(err, res);
81
+ });
82
+ } else {
83
+ res.render('error', util.initError(406));
84
+ }
85
+ });
6286 });
6387
6488 router.post('/:role_id', function(req, res, next) {
65
- const data = Object.assign(req.body) || {};
66
- Roles.updateMany({_id: req.params.role_id}, { $set: data}, function(err, response) {
67
- const param = util.initParam();
68
- if(err) {
69
- param.error = util.errorJson(err).result_msg;
70
- Modules.find({}).then(function (modules) {
71
- param.modules = modules;
72
- res.render('roles/update', param);
73
- }).catch(err => {
74
- res.render('roles/update', param);
89
+ util.verifyAuth(req).then(function (isAuth){
90
+ if(isAuth) {
91
+ const data = Object.assign(req.body) || {};
92
+ Roles.updateMany({_id: req.params.role_id}, { $set: data}, function(err, response) {
93
+ const param = util.initParam();
94
+ if(err) {
95
+ param.error = util.errorJson(err).result_msg;
96
+ Modules.find({}).then(function (modules) {
97
+ param.modules = modules;
98
+ res.render('roles/update', param);
99
+ }).catch(err => {
100
+ res.render('roles/update', param);
101
+ });
102
+ } else {
103
+ res.redirect(config.path.context + '/roles/');
104
+ }
75105 });
76106 } else {
77
- res.redirect(config.path.context + '/roles/');
107
+ res.render('error', util.initError(406));
78108 }
79
- });
109
+ });
80110 });
81111
82112 router.delete('/:role_id', function(req, res, next) {
83
- res.json(res);
84
- // Roles.deleteMany({ _id: req.params.role_id }, function (err, response) {
85
- // err?util.reportError(err, res):res.json({'deleted': response.n});
86
- // });
113
+ util.verifyAuth(req).then(function (isAuth){
114
+ if(isAuth) {
115
+ res.json(res);
116
+ } else {
117
+ res.json(util.initError());
118
+ }
119
+ });
87120 });
88121
89122 module.exports = router;
routes/segment.js
....@@ -8,42 +8,72 @@
88
99 const Segment = require('../model/segmentation');
1010
11
-router.get('/:segment_id', function(req, res, next) {
12
- Segment.findOne({_id: req.params.segment_id}).then(function (segment) {
13
- res.json(segment);
14
- }).catch(err => {
15
- util.reportError(err, res);
16
- });
17
-});
11
+// router.get('/:segment_id', function(req, res, next) {
12
+// util.verifyAuth(req).then(function (isAuth){
13
+// if(isAuth) {
14
+// Segment.findOne({_id: req.params.segment_id}).then(function (segment) {
15
+// res.json(segment);
16
+// }).catch(err => {
17
+// util.reportError(err, res);
18
+// });
19
+// } else {
20
+// res.render('error', util.initError(406));
21
+// }
22
+// });
23
+// });
1824
19
-router.get('/', function(req, res, next) {
20
- Segment.find({}).then(function (segments) {
21
- res.json(segments);
22
- }).catch(err => {
23
- util.reportError(err, res);
24
- });
25
-});
25
+// router.get('/', function(req, res, next) {
26
+// util.verifyAuth(req).then(function (isAuth){
27
+// if(isAuth) {
28
+// Segment.find({}).then(function (segments) {
29
+// res.json(segments);
30
+// }).catch(err => {
31
+// util.reportError(err, res);
32
+// });
33
+// } else {
34
+// res.render('error', util.initError(406));
35
+// }
36
+// });
37
+// });
2638
27
-router.post('/', function(req, res, next) {
28
- const data = Object.assign(req.body) || {};
29
- Segment.create(data).then(segment => {
30
- res.json({'segment_id': segment._id});
31
- }).catch(err => {
32
- util.reportError(err, res);
33
- });
34
-});
39
+// router.post('/', function(req, res, next) {
40
+// util.verifyAuth(req).then(function (isAuth){
41
+// if(isAuth) {
42
+// const data = Object.assign(req.body) || {};
43
+// Segment.create(data).then(segment => {
44
+// res.json({'segment_id': segment._id});
45
+// }).catch(err => {
46
+// util.reportError(err, res);
47
+// });
48
+// } else {
49
+// res.render('error', util.initError(406));
50
+// }
51
+// });
52
+// });
3553
36
-router.put('/:segment_id', function(req, res, next) {
37
- const data = Object.assign(req.body) || {};
38
- Segment.updateMany({_id: req.params.segment_id}, { $set: data}, function(err, response) {
39
- err?util.reportError(err, res):res.json({'updated': response.n});
40
- });
41
-});
54
+// router.put('/:segment_id', function(req, res, next) {
55
+// util.verifyAuth(req).then(function (isAuth){
56
+// if(isAuth) {
57
+// const data = Object.assign(req.body) || {};
58
+// Segment.updateMany({_id: req.params.segment_id}, { $set: data}, function(err, response) {
59
+// err?util.reportError(err, res):res.json({'updated': response.n});
60
+// });
61
+// } else {
62
+// res.render('error', util.initError(406));
63
+// }
64
+// });
65
+// });
4266
43
-router.delete('/:segment_id', function(req, res, next) {
44
- Segment.deleteMany({_id: req.params.segment_id}, function (err, response) {
45
- err?util.reportError(err, res):res.json({'deleted': response.n});
46
- });
47
-});
67
+// router.delete('/:segment_id', function(req, res, next) {
68
+// util.verifyAuth(req).then(function (isAuth){
69
+// if(isAuth) {
70
+// Segment.deleteMany({_id: req.params.segment_id}, function (err, response) {
71
+// err?util.reportError(err, res):res.json({'deleted': response.n});
72
+// });
73
+// } else {
74
+// res.render('error', util.initError(406));
75
+// }
76
+// });
77
+// });
4878
4979 module.exports = router;
routes/taxonomy.js
....@@ -5,65 +5,65 @@
55 const config = require('../config/config.js');
66 const util = require('../util/util.js');
77
8
-const Taxonomy = require('../model/taxonomy');
8
+// const Taxonomy = require('../model/taxonomy');
99
10
-router.get('/:key_taxonomy_id', function(req, res, next) {
11
- Taxonomy.findOne({_id: req.params.key_taxonomy_id}).then(function (taxonomy) {
12
- console.log(taxonomy);
13
- res.json(taxonomy);
14
- }).catch(err => {
15
- util.reportError(err, res);
16
- });
17
-});
10
+// router.get('/:key_taxonomy_id', function(req, res, next) {
11
+// Taxonomy.findOne({_id: req.params.key_taxonomy_id}).then(function (taxonomy) {
12
+// console.log(taxonomy);
13
+// res.json(taxonomy);
14
+// }).catch(err => {
15
+// util.reportError(err, res);
16
+// });
17
+// });
1818
19
-router.get('/', function(req, res, next) {
20
- Taxonomy.find({}).then(function (taxonomys) {
21
- res.json(taxonomys);
22
- }).catch(err => {
23
- util.reportError(err, res);
24
- });
25
-});
19
+// router.get('/', function(req, res, next) {
20
+// Taxonomy.find({}).then(function (taxonomys) {
21
+// res.json(taxonomys);
22
+// }).catch(err => {
23
+// util.reportError(err, res);
24
+// });
25
+// });
2626
27
-router.get('/search/name', function(req, res, next) {
28
- Taxonomy.find({keyname: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
29
- res.json(taxonomys);
30
- }).catch(err => {
31
- util.reportError(err, res);
32
- });
33
-});
27
+// router.get('/search/name', function(req, res, next) {
28
+// Taxonomy.find({keyname: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
29
+// res.json(taxonomys);
30
+// }).catch(err => {
31
+// util.reportError(err, res);
32
+// });
33
+// });
3434
35
-router.get('/search/location', function(req, res, next) {
36
- const filter = {};
37
- filter.loc = req.query.lon;
38
- filter.lat = req.query.lat;
39
- filter.radius = req.query.radius;
40
- filter.datetime = req.query.datetime;
41
- // Taxonomy.find({keyname: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
42
- res.json(filter);
43
- // });
44
-});
35
+// router.get('/search/location', function(req, res, next) {
36
+// const filter = {};
37
+// filter.loc = req.query.lon;
38
+// filter.lat = req.query.lat;
39
+// filter.radius = req.query.radius;
40
+// filter.datetime = req.query.datetime;
41
+// // Taxonomy.find({keyname: new RegExp(req.query.keyname, 'i')}).then(function (taxonomys) {
42
+// res.json(filter);
43
+// // });
44
+// });
4545
4646
47
-router.post('/', function(req, res, next) {
48
- const data = Object.assign(req.body) || {};
49
- Taxonomy.create(data).then(taxonomy => {
50
- res.json({'key_taxonomy_id': taxonomy._id});
51
- }).catch(err => {
52
- util.reportError(err, res);
53
- });
54
-});
47
+// router.post('/', function(req, res, next) {
48
+// const data = Object.assign(req.body) || {};
49
+// Taxonomy.create(data).then(taxonomy => {
50
+// res.json({'key_taxonomy_id': taxonomy._id});
51
+// }).catch(err => {
52
+// util.reportError(err, res);
53
+// });
54
+// });
5555
56
-router.put('/:key_taxonomy_id', function(req, res, next) {
57
- const data = Object.assign(req.body) || {};
58
- Taxonomy.updateMany({_id: req.params.key_taxonomy_id}, { $set: data}, function(err, response) {
59
- err?util.reportError(err, res):res.json({'updated': response.n});
60
- });
61
-});
56
+// router.put('/:key_taxonomy_id', function(req, res, next) {
57
+// const data = Object.assign(req.body) || {};
58
+// Taxonomy.updateMany({_id: req.params.key_taxonomy_id}, { $set: data}, function(err, response) {
59
+// err?util.reportError(err, res):res.json({'updated': response.n});
60
+// });
61
+// });
6262
63
-router.delete('/:key_taxonomy_id', function(req, res, next) {
64
- Taxonomy.deleteMany({ _id: req.params.key_taxonomy_id }, function (err, response) {
65
- err?util.reportError(err, res):res.json({'deleted': response.n});
66
- });
67
-});
63
+// router.delete('/:key_taxonomy_id', function(req, res, next) {
64
+// Taxonomy.deleteMany({ _id: req.params.key_taxonomy_id }, function (err, response) {
65
+// err?util.reportError(err, res):res.json({'deleted': response.n});
66
+// });
67
+// });
6868
6969 module.exports = router;
server.js
....@@ -22,16 +22,13 @@
2222 const db = mongoose.connection;
2323 db.on('error', console.error.bind(console, 'MongoDB connection error:'));
2424
25
-var app = express();
25
+const app = express();
2626
2727 // view engine setup
2828 app.engine('html', mustacheExpress());
2929
3030 app.set('view engine', 'html');
3131 app.set('views', path.join(__dirname, 'views'));
32
-
33
-// app.set('views', path.join(__dirname, 'views'));
34
-// app.set('view engine', 'pug');
3532 app.use(logger('dev'));
3633 app.use(express.json());
3734 app.use(express.urlencoded({ extended: false }));
util/util.js
....@@ -1,11 +1,19 @@
11 const _ = require('lodash');
22 const jwt = require('jsonwebtoken');
3
+const cookie = require('cookie');
4
+const crypto = require('crypto');
5
+const mongoose = require('mongoose');
36
47 const config = require('../config/config.js');
8
+const redis = require('redis');
9
+const client = redis.createClient(config.redis);
510
11
+const Modules = require('../model/module');
12
+const Roles = require('../model/role');
13
+// const {promisify} = require('util');
14
+// const getAsync = promisify(client.get('test', cb)).bind(client);
615
716 function generatePath(path){
8
- console.log(path);
917 path = path.replace(/\s/g,'');
1018 if (path.indexOf("/") != 0) {
1119 path = "/" + path;
....@@ -21,6 +29,27 @@
2129 const param = {};
2230 param.cdnRoot = config.path.cdn;
2331 param.context = config.path.context;
32
+ return param;
33
+}
34
+
35
+function initError(errorCode) {
36
+ const param = {};
37
+ param.cdnRoot = config.path.cdn;
38
+ param.context = config.path.context;
39
+
40
+ // UNAUTHORIZED = 401
41
+ // NOT_ACCEPTABLE = 406
42
+ if(errorCode == 401) {
43
+ param.error = "Unauthorized";
44
+ param.message = "You have to log in first.";
45
+ } else if(errorCode == 406) {
46
+ param.error = "Not Accetable";
47
+ param.message = "You don't have any permission to access.";
48
+ } else {
49
+ param.error = "Internal Server Error";
50
+ param.message = "An error occurred, please try again.";
51
+ }
52
+
2453 return param;
2554 }
2655
....@@ -77,24 +106,21 @@
77106 /****************************************
78107 ***************** AUTH ******************
79108 *****************************************/
109
+function encrypt(text){
110
+ const cipher = crypto.createCipher('aes128',config.secret);
111
+ let crypted = cipher.update(text,'utf8','hex');
112
+ crypted += cipher.final('hex');
113
+ return crypted;
114
+}
115
+
116
+function decrypt(text){
117
+ const decipher = crypto.createDecipher('aes128', config.secret);
118
+ let dec = decipher.update(text,'hex','utf8');
119
+ dec += decipher.final('utf8');
120
+ return dec;
121
+}
122
+
80123 function createToken(details) {
81
- if (typeof details !== 'object') {
82
- details = {};
83
- }
84
-
85
- if (!details.maxAge || typeof details.maxAge !== 'number') {
86
- details.maxAge = 3600;
87
- }
88
-
89
- details.sessionData = _.reduce(details.sessionData || {}, (memo, val, key) => {
90
- // if (typeof val !== "function" && key !== "password") {
91
- if (typeof val !== "function" ) {
92
- memo[key] = val;
93
- }
94
- return memo;
95
- }, {});
96
-
97
-
98124 let token = jwt.sign({
99125 data: details.sessionData
100126 }, config.secret, {
....@@ -116,14 +142,87 @@
116142 });
117143 }
118144
145
+function clearToken(req, res) {
146
+ try{
147
+ const token = cookie.parse(req.headers.cookie).mobi_dmp;
148
+ res.clearCookie("mobi_dmp");
149
+ const jwtData = jwt.verify(token, config.secret);
150
+ client.del(encrypt(jwtData.data), function(err, response) {
151
+ res.redirect(config.path.context);
152
+ });
153
+ } catch (error) {
154
+ res.redirect(config.path.context);
155
+ }
156
+}
157
+
158
+function createAuth(token, account, req) {
159
+ return new Promise(resolve => {
160
+ const data = {};
161
+ data.name = account.name;
162
+ data.login_id = account.login_id;
163
+ data.role = String(account.role);
164
+ data.position = account.position;
165
+ data.account_type = account.account_type;
166
+ data.accessibles = String(account.accessibles);
167
+
168
+ client.hmset(token, data, function(err, res){
169
+ resolve(res=='OK'?200:err);
170
+ });
171
+ });
172
+}
173
+
174
+function verifyAuth(req) {
175
+ return new Promise(resolve => {
176
+ let token;
177
+ try{
178
+ token = cookie.parse(req.headers.cookie).mobi_dmp;
179
+ const jwtData = jwt.verify(token, config.secret);
180
+
181
+ client.hgetall(encrypt(jwtData.data), async function (err, data) {
182
+ let result = '';
183
+
184
+ if(data.account_type == 'admin') {
185
+ resolve(true);
186
+ } else {
187
+ const url = generatePath(req.originalUrl);
188
+
189
+ Modules.findOne({path: url}).then(function (module) {
190
+ // res.json(module);
191
+ const moduleId = module._id;
192
+ if(-1 < data.accessibles.indexOf(moduleId)) {
193
+ resolve(true);
194
+ } else {
195
+ Roles.findOne({_id: data.role,accessibles: moduleId}).then(function (module) {
196
+ if(module) {
197
+ resolve(true);
198
+ } else {
199
+ resolve(false);
200
+ }
201
+ });
202
+ }
203
+ });
204
+ }
205
+ });
206
+ } catch(error) {
207
+ resolve(false);
208
+ }
209
+ });
210
+}
211
+
119212 module.exports = {
120213 generatePath: generatePath,
121214 initParam: initParam,
215
+ initError: initError,
122216 info: info,
123217 infoObj: infoObj,
124218 error: error,
219
+ decrypt: decrypt,
220
+ encrypt: encrypt,
125221 createToken: createToken,
126222 verifyToken: verifyToken,
223
+ clearToken: clearToken,
224
+ createAuth: createAuth,
225
+ verifyAuth: verifyAuth,
127226 errorJson: errorJson,
128227 reportError: reportError
129228 };
views/error.html
....@@ -1 +1,16 @@
1
-{{error.stack}}
1
+<!DOCTYPE HTML>
2
+<html lang="en">
3
+<head>
4
+ <title>Mobithru DMP</title>
5
+ <link rel="stylesheet" href="{{context}}/css/style.css"/>
6
+ <script src="{{cdnRoot}}/jquery-plugins/jquery-3.3.1.min.js"></script>
7
+</head>
8
+<body>
9
+<div class="content">
10
+ <h2>{{error}}</h2>
11
+ <h3>
12
+ {{message}}
13
+ </h3>
14
+ <input type="button" value="back" onclick="javascript:history.back()" />
15
+</div>
16
+{{>layout/footer}}
views/index.html
deleted file mode 100644
....@@ -1,10 +0,0 @@
1
-<html>
2
-<head>
3
- <link rel="stylesheet" type="text/css" href="css/style.css">
4
- <link rel="stylesheet" type="text/css" href="css/test.css">
5
-</head>
6
-<body>
7
- {{title}}
8
- <div>hello222!!aa!</div>
9
-</body>
10
-</html>
views/login.html
....@@ -20,11 +20,6 @@
2020 </style>
2121 </head>
2222 <body>
23
-<!-- Todo Things.
24
-{{#logout}}
25
-<h3>You have been logged out.</h3>
26
-{{/logout}}
27
--->
2823 <div class="lcell">
2924 <div class="logo-bg">
3025 <span class="logo-image"></span>
....@@ -35,7 +30,7 @@
3530 <form class="login-account" method="post" accept-charset="utf-8">
3631 <div class="input-form">
3732 <span class="label">E-mail address</span>
38
- <input class="email-input" type="text" name="loginId" id="loginId" placeholder="E-mail address" autocomplete="on" tabindex="1" value="{{email}}">
33
+ <input class="email-input" type="text" name="login_id" id="login_id" placeholder="E-mail address" autocomplete="on" tabindex="1" value="{{email}}">
3934 <div class="password">
4035 <span class="label">Password</span>
4136 <a class="forgot-password" href="#" tabindex="3">Forgot Password?</a>
....@@ -47,7 +42,7 @@
4742 </form>
4843 <div class="divider-login-lcell"></div>
4944
50
- <a href="{{contextRoot}}/accounts/create" class="btn-create-account" tabindex="4">Create Account</a>
45
+ <a href="{{contextRoot}}/signup" class="btn-create-account" tabindex="4">Create Account</a>
5146 </div>
5247
5348 <div class="rcell">
....@@ -59,14 +54,14 @@
5954 </div>
6055 <script>
6156 $(document).ready(function () {
62
- $('input[name="loginId"]').focus();
57
+ $('input[name="login_id"]').focus();
6358
6459 $('form').submit(function() {
65
- if($('#loginId').val() == '') {
66
- $('input[name="loginId"]').addClass('error').attr('placeholder', 'Please, enter your email.');
60
+ if($('#login_id').val() == '') {
61
+ $('input[name="login_id"]').addClass('error').attr('placeholder', 'Please, enter your email.');
6762 return false;
6863 }else if($('#password').val() == '') {
69
- $('input[name="loginId"]').removeClass('error').attr('placeholder', 'E-mail address');
64
+ $('input[name="login_id"]').removeClass('error').attr('placeholder', 'E-mail address');
7065 $('input[name="password"]').addClass('error').attr('placeholder', 'Please, enter your password.');
7166 return false;
7267 } else {
....@@ -75,11 +70,15 @@
7570 });
7671
7772 {{#invalidUser}}
78
- $('input[name="loginId"]').addClass('error').attr('placeholder', 'Email is invalid.');
73
+ $('input[name="login_id"]').addClass('error').attr('placeholder', 'Email is invalid.');
7974 {{/invalidUser}}
8075 {{#invalidPasswd}}
8176 $('input[name="password"]').addClass('error').attr('placeholder', 'Password is invalid.');
8277 {{/invalidPasswd}}
78
+ {{#invalidTokken}}
79
+ alert('Failed make a token. Please ask our support team.');
80
+ {{/invalidTokken}}
81
+
8382 });
8483 </script>
8584 </body>
views/signup.html
....@@ -0,0 +1,89 @@
1
+<!DOCTYPE HTML>
2
+<html lang="en">
3
+<head>
4
+ <title>Mobithru DMP</title>
5
+ <link rel="stylesheet" href="{{context}}/css/style.css"/>
6
+ <script src="{{cdnRoot}}/jquery-plugins/jquery-3.3.1.min.js"></script>
7
+</head>
8
+<body>
9
+<div class="content">
10
+ <form class="form-signup" action="signup" method="post">
11
+ <h1>Signup</h1>
12
+ {{#error}}
13
+ <h4 class="error">{{error}}</h4>
14
+ {{/error}}
15
+ <div>
16
+ <label for="name">Name :</label>
17
+ <input type="text" name="name" id="name" class="form-control" placeholder="Name" value="{{data.name}}" required/>
18
+ </div>
19
+ <div>
20
+ <label for="login_id">Email :</label>
21
+ <input type="text" name="login_id" id="login_id" class="form-control" placeholder="Email" value="{{data.login_id}}" required/>
22
+ </div>
23
+ <div>
24
+ <label for="passwd">Password</label>
25
+ <input type="password" name="passwd" id="passwd" placeholder="Password" value="{{data.passwd}}" required/>
26
+ </div>
27
+ <div>
28
+ <label for="mobile">Mobile :</label>
29
+ <input type="text" name="mobile" id="mobile" placeholder="Mobile" required value="{{data.mobile}}" />
30
+ </div>
31
+ <div>
32
+ <label for="organization">Organization Name :</label>
33
+ <input type="text" name="organization" id="organization" placeholder="Organization Name" value="{{data.organization}}" required/>
34
+ </div>
35
+ <div>
36
+ <label for="position">Position :</label>
37
+ <input type="text" name="position" id="position" placeholder="Position" value="{{data.position}}" required/>
38
+ </div>
39
+ <div>
40
+ <label for="account_type">Account Type :</label>
41
+ <select name="account_type" id="account_type">
42
+ <option value="mno" selected>MNO</option>
43
+ <option value="pm">Publisher&Marketer</option>
44
+ </select>
45
+ </div>
46
+ <div>
47
+ <label for="role">Role Type :</label>
48
+ <select name="role" id="role">
49
+ {{#roles}}
50
+ <option value="{{id}}">{{name}}</option>
51
+ {{/roles}}
52
+ </select>
53
+ </div>
54
+ <div>
55
+ <label for="accessibles">Accessibles :</label>
56
+ <fieldset>
57
+ <div id="accessibles">
58
+ {{#modules}}
59
+ <div>
60
+ {{#parent_id}}
61
+ <span class="empty-space">&nbsp;&nbsp;&nbsp;</span>
62
+ {{/parent_id}}
63
+ <input type="checkbox" id="{{id}}" name="accessibles" value="{{id}}"
64
+ {{#parent_id}}
65
+ data-parent-id="{{parent_id}}"
66
+ {{/parent_id}}
67
+ />
68
+ <label for="{{id}}">{{name}}</label>
69
+ </div>
70
+ {{/modules}}
71
+ </div>
72
+ </fieldset>
73
+ </div>
74
+
75
+ <button type="submit">Add Account</button>
76
+ </form>
77
+</div>
78
+<script>
79
+ $('input[type=checkbox]').on('change', function () {
80
+ const checked = $(this).is(':checked');
81
+ const id = $(this).val();
82
+ $.each($('input[type=checkbox]'), function (index, value) {
83
+ if (id == $(this).attr('data-parent-id')) {
84
+ $(this).prop('checked', checked);
85
+ }
86
+ });
87
+ });
88
+</script>
89
+{{>layout/footer}}