7b5b1649944710d9d5525715a75e4abcef6f088d..fe715b1cb31a74ca32f0222d053ab14bab9e51d0
2018-10-23 JOE
modify url path
fe715b diff | tree
2018-10-23 JOE
modify url path
5c2356 diff | tree
2018-10-23 JOE
modify url path
fdef19 diff | tree
2018-10-23 JOE
modify url path
755319 diff | tree
2018-10-23 JOE
modify url path
62e430 diff | tree
2018-10-23 JOE
modify url path
150a34 diff | tree
2018-10-23 JOE
modify url path
021a82 diff | tree
2018-10-23 JOE
modify url path
2dcc74 diff | tree
2018-10-23 JOE
modify url path
617c29 diff | tree
2018-10-23 JOE
modify url path
37c44b diff | tree
2018-10-23 JOE
modify url path
94932c diff | tree
2018-10-23 JOE
modify url path
f12633 diff | tree
2018-10-23 JOE
modify url path
bcd213 diff | tree
2018-10-23 JOE
modify gitignore
78f8fc diff | tree
2018-10-23 JOE
add signup&account management
7cce65 diff | tree
16 files modified
1 files deleted
287 ■■■■ changed files
.gitignore 3 ●●●●● patch | view | raw | blame | history
config/config.js 3 ●●●● patch | view | raw | blame | history
model/account.js 7 ●●●●● patch | view | raw | blame | history
routes/accounts.js 78 ●●●● patch | view | raw | blame | history
routes/modules.js 18 ●●●● patch | view | raw | blame | history
routes/roles.js 4 ●●●● patch | view | raw | blame | history
util/util.js 1 ●●●● patch | view | raw | blame | history
views/accounts/create.html 35 ●●●● patch | view | raw | blame | history
views/accounts/list.html 28 ●●●● patch | view | raw | blame | history
views/accounts/update.html 28 ●●●● patch | view | raw | blame | history
views/layout/header-temp.html 14 ●●●● patch | view | raw | blame | history
views/login.html 4 ●●●● patch | view | raw | blame | history
views/modules/list.html 6 ●●●● patch | view | raw | blame | history
views/modules/update.html 2 ●●● patch | view | raw | blame | history
views/roles/list.html 6 ●●●● patch | view | raw | blame | history
views/roles/update.html 2 ●●● patch | view | raw | blame | history
views/signup.html 48 ●●●●● patch | view | raw | blame | history
.gitignore
....@@ -5,6 +5,9 @@
55 yarn-debug.log*
66 yarn-error.log*
77
8
+server.js
9
+config/config.js
10
+
811 # Runtime data
912 pids
1013 *.pid
config/config.js
....@@ -1,6 +1,7 @@
11 module.exports = {
22 path: {
3
- cdn: 'http://dmp.3ps.io/dmp'
3
+ cdn: 'http://dmp.3ps.io/dmp',
4
+ context: 'http://dmp.3ps.io/mobidmp',
45 },
56 secret: 'AMDMP_2018',
67 db: {
model/account.js
....@@ -2,12 +2,13 @@
22 const Schema = mongoose.Schema;
33
44 const AccountSchema = new Schema({
5
- login_id: {type: String, required: true, index: true, unique: true },
6
- name: {type: String, required: true},
7
- passwd: {type: String, required: true, bcrypt: true},
5
+ login_id: {type: String, required: true, index: true, unique: true},
6
+ name: {type: String, required: true, unique: true},
7
+ passwd: {type: String, required: true, bcrypt: true},
88 mobile: String,
99 organization: String,
1010 position: String,
11
+ account_type: String,
1112 role: {type: mongoose.Schema.ObjectId, ref: 'roles'},
1213 accessibles : [{type: mongoose.Schema.ObjectId, ref: 'modules'}],
1314 });
routes/accounts.js
....@@ -8,46 +8,80 @@
88 const util = require('../util/util.js');
99
1010 const Account = require('../model/account');
11
+const Modules = require('../model/module');
12
+const Roles = require('../model/role');
1113
12
-router.post('/', function(req, res, next) {
14
+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
+ });
22
+});
23
+
24
+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);
33
+ });
34
+});
35
+
36
+router.post('/create', function(req, res, next) {
1337 const data = Object.assign(req.body) || {};
1438 let hash = bcrypt.hashSync(data.passwd, 10);
1539 data.passwd = hash;
1640
17
- Account.create(data).then(account => {
18
- res.json(account);
41
+ Account.create(data).then(role => {
42
+ res.redirect(config.path.context + '/accounts/');
1943 }).catch(err => {
20
- util.reportError(err, res);
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
+ });
2154 });
2255 });
2356
24
-router.get('/', function(req, res, next) {
25
- Account.find({}).then(function (accounts) {
26
- res.json(accounts);
27
- }).catch(err => {
28
- util.reportError(err, res);
29
- });
30
-});
3157
3258 router.get('/:account_id', function(req, res, next) {
33
- Account.findOne({_id: req.params.account_id}).then(function (account) {
34
- res.json(account);
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);
3565 }).catch(err => {
3666 util.reportError(err, res);
3767 });
3868 });
3969
40
-router.put('/:account_id', function(req, res, next) {
70
+router.post('/:account_id', function(req, res, next) {
4171 const data = Object.assign(req.body) || {};
42
- Account.updateMany({_id: req.params.account_id}, { $set: data}, function(err, response) {
43
- err?util.reportError(err, res):res.json({'updated': response.n});
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/');
82
+ }
4483 });
4584 });
4685
47
-router.delete('/:account_id', function(req, res, next) {
48
- Account.deleteMany({ _id: req.params.account_id }, function (err, response) {
49
- err?util.reportError(err, res):res.json({'deleted': response.n});
50
- });
51
-});
5286
53
-module.exports = router;
87
+module.exports = router;
routes/modules.js
....@@ -31,7 +31,7 @@
3131 router.post('/create', function(req, res, next) {
3232 const data = Object.assign(req.body) || {};
3333 Modules.create(data).then(role => {
34
- res.redirect('/modules/');
34
+ res.redirect(config.path.context + '/modules/');
3535 }).catch(err => {
3636 Modules.find({}).then(function (modules) {
3737 const param = util.initParam();
....@@ -74,23 +74,9 @@
7474 res.render('modules/update', param);
7575 });
7676 } else {
77
- res.redirect('/modules/');
77
+ res.redirect(config.path.context + '/modules/');
7878 }
7979 });
8080 });
81
-
82
-
83
-// router.put('/:module_id', function(req, res, next) {
84
-// const data = Object.assign(req.body) || {};
85
-// Modules.updateMany({_id: req.params.module_id}, { $set: data}, function(err, response) {
86
-// err?util.reportError(err, res):res.json({'updated': response.n});
87
-// });
88
-// });
89
-
90
-// router.delete('/:module_id', function(req, res, next) {
91
-// Modules.deleteMany({ _id: req.params.module_id }, function (err, response) {
92
-// err?util.reportError(err, res):res.json({'deleted': response.n});
93
-// });
94
-// });
9581
9682 module.exports = router;
routes/roles.js
....@@ -32,7 +32,7 @@
3232 const data = Object.assign(req.body) || {};
3333 data.welcome_page_modile = util.generatePath(data.welcome_page_modile);
3434 Roles.create(data).then(role => {
35
- res.redirect('/roles/');
35
+ res.redirect(config.path.context + '/roles/');
3636 }).catch(err => {
3737 Modules.find({}).then(function (modules) {
3838 const param = util.initParam();
....@@ -74,7 +74,7 @@
7474 res.render('roles/update', param);
7575 });
7676 } else {
77
- res.redirect('/roles/');
77
+ res.redirect(config.path.context + '/roles/');
7878 }
7979 });
8080 });
util/util.js
....@@ -20,6 +20,7 @@
2020 function initParam() {
2121 const param = {};
2222 param.cdnRoot = config.path.cdn;
23
+ param.context = config.path.context;
2324 return param;
2425 }
2526
views/accounts/create.html
....@@ -1,34 +1,37 @@
11 {{>layout/header-temp}}
22 <div class="content">
3
- <form class="form-signup" action="create" method="post">
3
+ <form class="form-signup" action="create" method="post">
44 <h1>Add Account</h1>
5
+ {{#error}}
6
+ <h4 class="error">{{error}}</h4>
7
+ {{/error}}
58 <div>
69 <label for="name">Name :</label>
7
- <input type="text" name="name" id="name" class="form-control" placeholder="Name" required/>
10
+ <input type="text" name="name" id="name" class="form-control" placeholder="Name" value="{{data.name}}" required/>
811 </div>
912 <div>
10
- <label for="loginId">Email :</label>
11
- <input type="text" name="loginId" id="loginId" class="form-control" placeholder="Email" required/>
13
+ <label for="login_id">Email :</label>
14
+ <input type="text" name="login_id" id="login_id" class="form-control" placeholder="Email" value="{{data.login_id}}" required/>
1215 </div>
1316 <div>
14
- <label for="password">Password</label>
15
- <input type="password" name="password" id="password" placeholder="Password" required/>
17
+ <label for="passwd">Password</label>
18
+ <input type="password" name="passwd" id="passwd" placeholder="Password" value="{{data.passwd}}" required/>
1619 </div>
1720 <div>
1821 <label for="mobile">Mobile :</label>
19
- <input type="text" name="mobile" id="mobile" placeholder="Mobile" required/>
22
+ <input type="text" name="mobile" id="mobile" placeholder="Mobile" required value="{{data.mobile}}" />
2023 </div>
2124 <div>
2225 <label for="organization">Organization Name :</label>
23
- <input type="text" name="organization" id="organization" placeholder="Organization Name" required/>
26
+ <input type="text" name="organization" id="organization" placeholder="Organization Name" value="{{data.organization}}" required/>
2427 </div>
2528 <div>
2629 <label for="position">Position :</label>
27
- <input type="text" name="position" id="position" placeholder="Position" required/>
30
+ <input type="text" name="position" id="position" placeholder="Position" value="{{data.position}}" required/>
2831 </div>
2932 <div>
30
- <label for="accountType">Account Type :</label>
31
- <select name="accountType" id="accountType">
33
+ <label for="account_type">Account Type :</label>
34
+ <select name="account_type" id="account_type">
3235 <option value="mno" selected>MNO</option>
3336 <option value="pm">Publisher&Marketer</option>
3437 </select>
....@@ -47,13 +50,13 @@
4750 <div id="accessibles">
4851 {{#modules}}
4952 <div>
50
- {{#parentId}}
53
+ {{#parent_id}}
5154 <span class="empty-space">&nbsp;&nbsp;&nbsp;</span>
52
- {{/parentId}}
55
+ {{/parent_id}}
5356 <input type="checkbox" id="{{id}}" name="accessibles" value="{{id}}"
54
- {{#parentId}}
55
- data-parent-id="{{parentId}}"
56
- {{/parentId}}
57
+ {{#parent_id}}
58
+ data-parent-id="{{parent_id}}"
59
+ {{/parent_id}}
5760 />
5861 <label for="{{id}}">{{name}}</label>
5962 </div>
views/accounts/list.html
....@@ -1,13 +1,35 @@
11 {{>layout/header-temp}}
22 <body>
33 <div class="content">
4
- <h2>Account List&nbsp;<a href="{{contextRoot}}/accounts/create">ADD</a></h2>
4
+ <h2>Account List&nbsp;<a href="{{context}}/accounts/create">ADD</a></h2>
55 {{#accounts}}
66 <h3>
77 [{{role.name}}] {{name}}
8
- <a href="{{contextRoot}}/accounts/update?id={{id}}"><span>edit</span></a>
9
- <a href="{{contextRoot}}/accounts/delete?id={{id}}"><span>delete</span></a>
8
+ <a href="{{context}}/accounts/{{id}}"><span>edit</span></a>
9
+ <a id="{{id}}" class="btn_delete" href="#"><span>delete</span></a>
1010 </h3>
1111 {{/accounts}}
1212 </div>
13
+<script>
14
+ $(document).ready(function () {
15
+ $('.btn_delete').on('click', function(){
16
+ if(confirm("Are you sure you want to delete this?")){
17
+ const id = $(this).attr('id');
18
+ $.ajax({
19
+ url: "{{context}}/api/accounts/" + id,
20
+ method:"delete"
21
+ }).done(function(data) {
22
+ if(data.deleted == 1) {
23
+ $('#'+id).parent().remove();
24
+ }
25
+ }).fail(function(error) {
26
+ alert(error);
27
+ });
28
+ }
29
+ else{
30
+ return false;
31
+ }
32
+ });
33
+ });
34
+</script>
1335 {{>layout/footer}}
views/accounts/update.html
....@@ -1,23 +1,23 @@
11 {{>layout/header-temp}}
22 <div class="content">
3
- <form action="{{contextRoot}}/accounts/update" method="post">
3
+ <form action="{{context}}/accounts/update" method="post">
44 <h1>Modify Account</h1>
5
- {{#result}}
6
- <h4>{{result}}</h4>
7
- {{/result}}
5
+ {{#error}}
6
+ <h4 class="error">{{error}}</h4>
7
+ {{/error}}
88 {{#account}}
99 <div>
1010 <label for="name">Name :</label>
1111 <input type="text" name="name" id="name" placeholder="Name" required value="{{name}}"/>
12
- <input type="hidden" name="id" id="id" required value="{{id}}"/>
12
+ <input type="hidden" name="id" id="id" required value="{{id}}" readonly />
1313 </div>
1414 <div>
15
- <label for="loginId">Email :</label>
16
- <input type="text" name="loginId" id="loginId" placeholder="Email" required value="{{loginId}}"/>
15
+ <label for="login_id">Email :</label>
16
+ <input type="text" name="login_id" id="login_id" placeholder="Email" required value="{{login_id}}" readonly />
1717 </div>
1818 <div>
19
- <label for="password">Password</label>
20
- <input type="password" name="password" id="password" placeholder="Password" required value="{{password}}"/>
19
+ <label for="passwd">Password</label>
20
+ <input type="password" name="passwd" id="passwd" placeholder="Password" required value="{{passwd}}"/>
2121 </div>
2222 <div>
2323 <label for="mobile">Mobile :</label>
....@@ -34,7 +34,7 @@
3434 </div>
3535 <div>
3636 <label for="account_type">Account Type :</label>
37
- <select name="accountType" id="account_type">
37
+ <select name="account_type" id="account_type">
3838 <option value="mno" selected>MNO</option>
3939 <option value="pm">Publisher&Marketer</option>
4040 </select>
....@@ -68,7 +68,7 @@
6868 </fieldset>
6969 </div>
7070
71
- <button onClick="javasciprt:history.back();">Cancel</button>
71
+ <input type="button" onClick="javasciprt:history.back();" value="Cancel" />
7272 <button type="submit">Modify Module</button>
7373 </form>
7474 {{/account}}
....@@ -79,10 +79,10 @@
7979 </div>
8080 <script>
8181 $(function () {
82
- $('#account_type').val('{{account.accountType}}');
83
- $('#role').val('{{account.role.id}}');
82
+ $('#account_type').val('{{account.account_type}}');
83
+ $('#role').val('{{account.role}}');
8484 {{#account.accessibles}}
85
- $('#{{id}}').prop('checked', true);
85
+ $('#{{.}}').prop('checked', true);
8686 {{/account.accessibles}}
8787
8888 $('input[type=checkbox]').on('change', function () {
views/layout/header-temp.html
....@@ -2,15 +2,15 @@
22 <html lang="en">
33 <head>
44 <title>Mobithru DMP</title>
5
- <link rel="stylesheet" href="{{contextRoot}}/css/style.css"/>
5
+ <link rel="stylesheet" href="{{context}}/css/style.css"/>
66 <script src="{{cdnRoot}}/jquery-plugins/jquery-3.3.1.min.js"></script>
77 </head>
88 <body>
99 <div class="header-temp">
10
- <a href="{{contextRoot}}/dashboard">Dashboard</a>
11
- <a href="{{contextRoot}}/accounts/">Accounts</a>
12
- <a href="{{contextRoot}}/roles/">Roles</a>
13
- <a href="{{contextRoot}}/modules/">Modules</a>
14
- <a href="{{contextRoot}}/api-test">API Test</a>
15
- <a href="{{contextRoot}}/logout">Logout</a>
10
+ <a href="{{context}}/dashboard/">Dashboard</a>
11
+ <a href="{{context}}/accounts/">Accounts</a>
12
+ <a href="{{context}}/roles/">Roles</a>
13
+ <a href="{{context}}/modules/">Modules</a>
14
+ <a href="{{context}}/api-test/">API Test</a>
15
+ <a href="{{context}}/logout/">Logout</a>
1616 </div>
views/login.html
....@@ -4,7 +4,7 @@
44 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
55 <meta charset="utf-8">
66 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
7
- <title>MOBITHRU-Login</title>
7
+ <title>MOBITHRU</title>
88 <link href="{{cdnRoot}}/css/login.css" rel="stylesheet">
99
1010 <!-- Scripts -->
....@@ -47,7 +47,7 @@
4747 </form>
4848 <div class="divider-login-lcell"></div>
4949
50
- <a href="{{contextRoot}}/signup" class="btn-create-account" tabindex="4">Create Account</a>
50
+ <a href="{{contextRoot}}/accounts/create" class="btn-create-account" tabindex="4">Create Account</a>
5151 </div>
5252
5353 <div class="rcell">
views/modules/list.html
....@@ -1,11 +1,11 @@
11 {{>layout/header-temp}}
22 <body>
33 <div class="content">
4
- <h2>Module List&nbsp;<a href="{{contextRoot}}/modules/create">ADD</a></h2>
4
+ <h2>Module List&nbsp;<a href="{{context}}/modules/create">ADD</a></h2>
55 {{#modules}}
66 <h3>
77 {{name}}
8
- <a href="/modules/{{id}}"><span>edit</span></a>
8
+ <a href="{{context}}/modules/{{id}}"><span>edit</span></a>
99 <a id="{{id}}" class="btn_delete" href="#"><span>delete</span></a>
1010 </h3>
1111 {{/modules}}
....@@ -16,7 +16,7 @@
1616 if(confirm("Are you sure you want to delete this?")){
1717 const id = $(this).attr('id');
1818 $.ajax({
19
- url: "/api/modules/" + id,
19
+ url: "{{context}}/api/modules/" + id,
2020 method:"delete"
2121 }).done(function(data) {
2222 if(data.deleted == 1) {
views/modules/update.html
....@@ -33,7 +33,7 @@
3333 </select>
3434 </div>
3535
36
- <button onClick="javasciprt:history.back();">Cancel</button>
36
+ <input type="button" onClick="javasciprt:history.back();" value="Cancel" />
3737 <button type="submit">Modify Module</button>
3838 </form>
3939 {{/module}}
views/roles/list.html
....@@ -1,10 +1,10 @@
11 {{>layout/header-temp}}
22 <div class="content">
3
- <h2>Role List&nbsp;<a href="/roles/create">ADD</a></h2>
3
+ <h2>Role List&nbsp;<a href="{{context}}/roles/create">ADD</a></h2>
44 {{#roles}}
55 <h3>
66 {{name}}
7
- <a href="/roles/{{id}}"><span>edit</span></a>
7
+ <a href="{{context}}/roles/{{id}}"><span>edit</span></a>
88 <a id="{{id}}" class="btn_delete" href="#"><span>delete</span></a>
99 </h3>
1010 {{/roles}}
....@@ -15,7 +15,7 @@
1515 if(confirm("Are you sure you want to delete this?")){
1616 const id = $(this).attr('id');
1717 $.ajax({
18
- url: "/api/roles/" + id,
18
+ url: "{{context}}/api/roles/" + id,
1919 method:"delete"
2020 }).done(function(data) {
2121 if(data.deleted == 1) {
views/roles/update.html
....@@ -37,7 +37,7 @@
3737 </fieldset>
3838 </div>
3939
40
- <button onClick="javasciprt:history.back();">Cancel</button>
40
+ <input type="button" onClick="javasciprt:history.back();" value="Cancel" />
4141 <button type="submit">Modify Role</button>
4242 </form>
4343 {{/role}}
views/signup.html
deleted file mode 100644
....@@ -1,48 +0,0 @@
1
-{{>layout/header-temp}}
2
-<div class="content">
3
- <form class="form-signup" action="signup" method="post">
4
- <h1>Sign up</h1>
5
- <div>
6
- <label for="name">Name :</label>
7
- <input type="text" name="name" id="name" class="form-control" placeholder="Name" required/>
8
- </div>
9
- <div>
10
- <label for="login_id">Email :</label>
11
- <input type="text" name="login_id" id="login_id" class="form-control" placeholder="Email" required/>
12
- </div>
13
- <div>
14
- <label for="passwd">Password</label>
15
- <input type="password" name="passwd" id="passwd" placeholder="Password" required/>
16
- </div>
17
- <div>
18
- <label for="mobile">Mobile :</label>
19
- <input type="text" name="mobile" id="mobile" placeholder="Mobile" required/>
20
- </div>
21
- <div>
22
- <label for="organization">Organization Name :</label>
23
- <input type="text" name="organization" id="organization" placeholder="Organization Name" required/>
24
- </div>
25
- <div>
26
- <label for="position">Position :</label>
27
- <input type="text" name="position" id="position" placeholder="Position" required/>
28
- </div>
29
- <div>
30
- <label for="accountType">Account Type :</label>
31
- <select name="accountType" id="accountType">
32
- <option value="mno" selected>MNO</option>
33
- <option value="pm">Publisher&Marketer</option>
34
- </select>
35
- </div>
36
- <div>
37
- <label for="role">Role Type :</label>
38
- <select name="role" id="role">
39
- {{#roles}}
40
- <option value="{{id}}">{{name}}</option>
41
- {{/roles}}
42
- </select>
43
- </div>
44
-
45
- <button type="submit">Sign Up</button>
46
- </form>
47
-</div>
48
-{{>layout/footer}}