From 6501ff42668b8d039e32650a91721259f4f7c638 Mon Sep 17 00:00:00 2001 From: Sameet Sapra Date: Sun, 12 Feb 2017 09:58:31 -0600 Subject: [PATCH 1/4] Get login UI working again --- controllers/services/users.js | 51 +++++++++++------------------------ 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/controllers/services/users.js b/controllers/services/users.js index c3c666c..2d5eaab 100644 --- a/controllers/services/users.js +++ b/controllers/services/users.js @@ -97,51 +97,32 @@ module.exports = function(app) { }); app.post('/login', function(req, res){ - var netid = req.body.netid, pass = req.body.password; - var options = { - url: `${SERVICES_URL}/session?username=${netid}`, + request({ + url: `${SERVICES_URL}/users/login`, method: "POST", json: true, headers: { "Authorization": GROOT_ACCESS_TOKEN }, - body: { - "username" : netid, - "password" : pass, - "validation-factors" : { - "validationFactors" : [{ - "name" : "remote_address", - "value" : "127.0.0.1" - }] - } - } - }; - - function callback(error, response, body) { - if(!body || !body["token"]) { - return res.render('login', { - authenticated: false, - errors: 'Invalid email or password.' - }); - } - - if (!error && response && response.statusCode == 200) { + body: req.body + }, function(err, response, body) { + if(err || !response || response.statusCode != 200) { + req.flash('error', (body && body.error) || err); + res.redirect('/login'); + } else { req.session.student = { - netid: netid, - token: body["token"], - email: netid + "@illinois.edu" + first_name: body.data.first_name, + last_name: body.data.last_name, + token: body.data.token, + netid: body.data.netid }; + req.session.username = req.session.student.first_name; req.session.roles.isStudent = true; utils.setAuthentication(req, res, function(req, res) { - utils.getUserData(req, res, function(req, res){ - res.redirect('/intranet'); - }); + res.redirect('/intranet'); }); - } else { - res.status(response.statusCode).send(error); } - } - request(options, callback); + }); }); -}; \ No newline at end of file +}; From fea3dc2ac558112ff406940374d89be95b2cec56 Mon Sep 17 00:00:00 2001 From: Sameet Sapra Date: Sun, 12 Feb 2017 11:10:09 -0600 Subject: [PATCH 2/4] Set up more user routes --- controllers/services/users.js | 79 +++++++++++++++++++++++++---------- views/_partials/users.ejs | 29 +++++++++++++ views/users_index.ejs | 55 +++++++++++++----------- 3 files changed, 117 insertions(+), 46 deletions(-) create mode 100644 views/_partials/users.ejs diff --git a/controllers/services/users.js b/controllers/services/users.js index 2d5eaab..3e2eccb 100644 --- a/controllers/services/users.js +++ b/controllers/services/users.js @@ -10,6 +10,7 @@ const SERVICES_URL = process.env.SERVICES_URL || 'http://localhost:8000'; const GROOT_ACCESS_TOKEN = process.env.GROOT_ACCESS_TOKEN || "TEMP_STRING"; +const path = require('path'); const request = require('request'); const utils = require('../../etc/utils.js'); @@ -20,8 +21,8 @@ module.exports = function(app) { } request({ - url: `${SERVICES_URL}/users/pre`, - method: "POST", + url: `${SERVICES_URL}/users`, + method: "GET", headers: { "Authorization": GROOT_ACCESS_TOKEN }, @@ -30,67 +31,101 @@ module.exports = function(app) { }, json: true }, function(err, response, body) { +<<<<<<< HEAD if(err) { return res.status(500).send("Sorry, there was a server error. Please try again."); +======= + if (err || !response || response.statusCode != 200) { + req.flash('error', (body && body.error) || err); + return res.status(500).send("Sorry, there was a server error. Please try again."); +>>>>>>> Set up more user routes } + res.render('users_index', { authenticated: utils.isAuthenticated(req), - session:req.session, - premembers: body, - messages: req.flash('success') + premembers: body.data }); }); - }); - - app.get('/intranet/users/:approvedUserNetID', function(req, res){ + app.put('/intranet/users/:netid/paid', function(req, res) { if(!req.session.roles.isAdmin && !req.session.roles.isTop4) { - return res.redirect('/login'); + res.redirect('/login'); } + var absUsersPath = path.resolve(__dirname + '/../../views/_partials/users.ejs'); request({ - url: `${SERVICES_URL}/users/paid`, - method: "POST", + url: `${SERVICES_URL}/users/` + req.params.netid + `/paid`, + method: "PUT", headers: { - "Authorization": GROOT_ACCESS_TOKEN - }, - body: { - "token" : req.session.student.token, - "netid" : req.params["approvedUserNetID"], + "Authorization": GROOT_ACCESS_TOKEN, + "Netid": req.session.student.netid }, +<<<<<<< HEAD json: true }, function(err) { if(err) { req.flash('error', "There was an issue, and the member may not have been added. Please contact someone from the Admin committee."); +======= + json: true, + body: {} + }, function(error, response, body) { + if (response && response.statusCode == 200 && body) { + res.status(200).send(ejs.render("<%- include('" + absUsersPath + "') %>", { users : body.data } )); +>>>>>>> Set up more user routes } else { - req.flash('success', "The member was added successfully!"); + res.status(response.statusCode).send(body.error); } + }); + }); + + app.delete('/intranet/users/:netid', function(req, res) { + if(!req.session.roles.isAdmin && !req.session.roles.isTop4) { + res.redirect('/login'); + } - res.redirect('/intranet/users'); + var absUsersPath = path.resolve(__dirname + '/../../views/_partials/users.ejs'); + request({ + url: `${SERVICES_URL}/users/` + req.params.netid, + method: "DELETE", + headers: { + "Authorization": GROOT_ACCESS_TOKEN, + "Netid": req.session.student.netid + }, + json: true, + body: {} + }, function(error, response, body) { + if (response && response.statusCode == 200 && body) { + res.status(200).send(ejs.render("<%- include('" + absUsersPath + "') %>", { users : body.data } )); + } else { + res.status(response.statusCode).send(body.error); + } }); }); app.post('/join', function(req, res) { +<<<<<<< HEAD var userData = { first_name: req.body.first_name, last_name: req.body.last_name, netid: req.body.netid, uin: req.body.uin }; +======= +>>>>>>> Set up more user routes request({ - url: `${SERVICES_URL}/users/newUser`, + url: `${SERVICES_URL}/users`, method: "POST", headers: { "Authorization": GROOT_ACCESS_TOKEN }, - body: userData, + body: req.body, json: true }, function(err, response, body) { if(err || !response || response.statusCode != 200) { - req.flash('error', err || body.error); + req.flash('error', (body && body.error) || err); } else { - req.flash('success', "Added as a premember"); + req.flash('success', body.message); } res.redirect('/join'); }); diff --git a/views/_partials/users.ejs b/views/_partials/users.ejs new file mode 100644 index 0000000..a763681 --- /dev/null +++ b/views/_partials/users.ejs @@ -0,0 +1,29 @@ +

Members

+ + + + + + + + + + + + + <% for (var user of users) { %> + + + + + + + + <% } %> + +
ActionNetidFirst NameLast NameSubmitted
+ <% if (!user.paid) { %> + Paid + Delete + <% } %> + <%= user.netid %><%= user.first_name %><%= user.last_name %><%=new Date(user.created_at).toLocaleString() %>
\ No newline at end of file diff --git a/views/users_index.ejs b/views/users_index.ejs index 4e1979c..484f7b4 100644 --- a/views/users_index.ejs +++ b/views/users_index.ejs @@ -13,30 +13,7 @@ this license in a file with the distribution.
@@ -49,4 +26,34 @@ this license in a file with the distribution. perPageDefault: 20 } }); + + function makeACMMember(netid) { + $.ajax({ + url: "/intranet/users/" + netid + "/paid", + method: "PUT", + success: function(response) { + $('#user-approval-table').html(response); + $("#user-approval-table").dynatable({ + dataset: { + perPageDefault: 20 + } + }); + } + }); + } + + function deleteACMMember(netid) { + $.ajax({ + url: "/intranet/users/" + netid, + method: "DELETE", + success: function(response) { + $('#user-approval-table').html(response); + $("#user-approval-table").dynatable({ + dataset: { + perPageDefault: 20 + } + }); + } + }); + } \ No newline at end of file From ead6bebc71879c1b848a4062545795d1db20586c Mon Sep 17 00:00:00 2001 From: Sameet Sapra Date: Sun, 12 Feb 2017 14:22:21 -0600 Subject: [PATCH 3/4] Can approve, delete, and join new users --- controllers/services/users.js | 31 +++--------------- views/_partials/users.ejs | 59 ++++++++++++++++++----------------- views/users_index.ejs | 28 +++++++++-------- 3 files changed, 51 insertions(+), 67 deletions(-) diff --git a/controllers/services/users.js b/controllers/services/users.js index 3e2eccb..7d8f70d 100644 --- a/controllers/services/users.js +++ b/controllers/services/users.js @@ -12,6 +12,7 @@ const SERVICES_URL = process.env.SERVICES_URL || 'http://localhost:8000'; const GROOT_ACCESS_TOKEN = process.env.GROOT_ACCESS_TOKEN || "TEMP_STRING"; const path = require('path'); const request = require('request'); +const ejs = require('ejs'); const utils = require('../../etc/utils.js'); module.exports = function(app) { @@ -31,19 +32,14 @@ module.exports = function(app) { }, json: true }, function(err, response, body) { -<<<<<<< HEAD if(err) { return res.status(500).send("Sorry, there was a server error. Please try again."); -======= - if (err || !response || response.statusCode != 200) { - req.flash('error', (body && body.error) || err); - return res.status(500).send("Sorry, there was a server error. Please try again."); ->>>>>>> Set up more user routes } res.render('users_index', { authenticated: utils.isAuthenticated(req), - premembers: body.data + premembers: body.data, + me: req.session.student }); }); }); @@ -61,18 +57,10 @@ module.exports = function(app) { "Authorization": GROOT_ACCESS_TOKEN, "Netid": req.session.student.netid }, -<<<<<<< HEAD json: true - }, function(err) { - if(err) { - req.flash('error', "There was an issue, and the member may not have been added. Please contact someone from the Admin committee."); -======= - json: true, - body: {} - }, function(error, response, body) { + }, function(err, response, body) { if (response && response.statusCode == 200 && body) { res.status(200).send(ejs.render("<%- include('" + absUsersPath + "') %>", { users : body.data } )); ->>>>>>> Set up more user routes } else { res.status(response.statusCode).send(body.error); } @@ -96,7 +84,7 @@ module.exports = function(app) { body: {} }, function(error, response, body) { if (response && response.statusCode == 200 && body) { - res.status(200).send(ejs.render("<%- include('" + absUsersPath + "') %>", { users : body.data } )); + res.status(200).send(ejs.render("<%- include('" + absUsersPath + "') %>", { users : body.data, me: req.session.student } )); } else { res.status(response.statusCode).send(body.error); } @@ -104,15 +92,6 @@ module.exports = function(app) { }); app.post('/join', function(req, res) { -<<<<<<< HEAD - var userData = { - first_name: req.body.first_name, - last_name: req.body.last_name, - netid: req.body.netid, - uin: req.body.uin - }; -======= ->>>>>>> Set up more user routes request({ url: `${SERVICES_URL}/users`, method: "POST", diff --git a/views/_partials/users.ejs b/views/_partials/users.ejs index a763681..4f7bf44 100644 --- a/views/_partials/users.ejs +++ b/views/_partials/users.ejs @@ -1,29 +1,32 @@ -

Members

- - - - - - - - - - - - - <% for (var user of users) { %> +<% if (users && users.length != 0) { %> +

Members

+
ActionNetidFirst NameLast NameSubmitted
+ - - - - - - - <% } %> - -
- <% if (!user.paid) { %> - Paid - Delete - <% } %> - <%= user.netid %><%= user.first_name %><%= user.last_name %><%=new Date(user.created_at).toLocaleString() %>
\ No newline at end of file + Action + Netid + First Name + Last Name + Submitted + + + + <% for (var user of users) { %> + + + <% if (!user.is_member && user.netid != me.netid) { %> + Paid + Delete + <% } %> + + <%= user.netid %> + <%= user.first_name %> + <%= user.last_name %> + <%= new Date(user.created_at).toLocaleString() %> + + <% } %> + + +<% } else { %> +
You have no users. That's a problem.
+<% } %> \ No newline at end of file diff --git a/views/users_index.ejs b/views/users_index.ejs index 484f7b4..657fb2e 100644 --- a/views/users_index.ejs +++ b/views/users_index.ejs @@ -13,7 +13,9 @@ this license in a file with the distribution.
@@ -32,12 +34,12 @@ this license in a file with the distribution. url: "/intranet/users/" + netid + "/paid", method: "PUT", success: function(response) { - $('#user-approval-table').html(response); - $("#user-approval-table").dynatable({ - dataset: { - perPageDefault: 20 - } - }); + $('#unapproved-users-partial').html(response); + $("#user-approval-table").dynatable({ + dataset: { + perPageDefault: 20 + } + }); } }); } @@ -47,12 +49,12 @@ this license in a file with the distribution. url: "/intranet/users/" + netid, method: "DELETE", success: function(response) { - $('#user-approval-table').html(response); - $("#user-approval-table").dynatable({ - dataset: { - perPageDefault: 20 - } - }); + $('#unapproved-users-partial').html(response); + $("#user-approval-table").dynatable({ + dataset: { + perPageDefault: 20 + } + }); } }); } From d369386e8a67f72025a2a30553b302652752e2eb Mon Sep 17 00:00:00 2001 From: Sameet Sapra Date: Sun, 19 Feb 2017 10:49:02 -0600 Subject: [PATCH 4/4] Improve html --- views/_partials/users.ejs | 4 +++- views/intranet.ejs | 4 ++-- views/users_index.ejs | 42 +++++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/views/_partials/users.ejs b/views/_partials/users.ejs index 4f7bf44..09c3e52 100644 --- a/views/_partials/users.ejs +++ b/views/_partials/users.ejs @@ -7,7 +7,7 @@ Netid First Name Last Name - Submitted + A Member Since @@ -17,6 +17,8 @@ <% if (!user.is_member && user.netid != me.netid) { %> Paid Delete + <% } else { %> +

No action to take.

<% } %> <%= user.netid %> diff --git a/views/intranet.ejs b/views/intranet.ejs index 984e30e..012f772 100644 --- a/views/intranet.ejs +++ b/views/intranet.ejs @@ -43,8 +43,8 @@ this license in a file with the distribution.

User Manager

-

Maintain pending ACM users

- +

View and maintain current and pending ACM users

+
<% } %> diff --git a/views/users_index.ejs b/views/users_index.ejs index 657fb2e..6e98f33 100644 --- a/views/users_index.ejs +++ b/views/users_index.ejs @@ -31,31 +31,31 @@ this license in a file with the distribution. function makeACMMember(netid) { $.ajax({ - url: "/intranet/users/" + netid + "/paid", - method: "PUT", - success: function(response) { - $('#unapproved-users-partial').html(response); - $("#user-approval-table").dynatable({ - dataset: { - perPageDefault: 20 - } - }); - } - }); + url: "/intranet/users/" + netid + "/paid", + method: "PUT", + success: function(response) { + $('#unapproved-users-partial').html(response); + $("#user-approval-table").dynatable({ + dataset: { + perPageDefault: 20 + } + }); + } + }); } function deleteACMMember(netid) { $.ajax({ - url: "/intranet/users/" + netid, - method: "DELETE", - success: function(response) { - $('#unapproved-users-partial').html(response); - $("#user-approval-table").dynatable({ - dataset: { - perPageDefault: 20 - } - }); - } + url: "/intranet/users/" + netid, + method: "DELETE", + success: function(response) { + $('#unapproved-users-partial').html(response); + $("#user-approval-table").dynatable({ + dataset: { + perPageDefault: 20 + } + }); + } }); } \ No newline at end of file