Skip to content

Commit

Permalink
Send server status to browser
Browse files Browse the repository at this point in the history
The HMIS server sends some status to the client *server*, which should
be reflected in what the Node server sends to the browser.  Adding the
`.status()` method everywhere should take care of that.

Also: Remove obsolete method for getting information about a user, since
we use the `/externalId` endpoint for that now.  Make a few small text
changes and make sure that the token cookie is used everywhere.
  • Loading branch information
cecilia-donnelly committed Aug 1, 2016
1 parent 2c769aa commit 0e3dee9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 42 deletions.
46 changes: 9 additions & 37 deletions app/controllers/client.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports.addClient = function(req, res) {
data.push(chunk);
});
res_post.on('end', function() {
res.send(data.join(''));
res.status(res_post.statusCode).send(data.join(''));
});
});

Expand Down Expand Up @@ -97,7 +97,7 @@ exports.getEnrollments = function(req, res) {
data.push(chunk);
});
res_get.on('end', function() {
res.send(data.join(''));
res.status(res_get.statusCode).send(data.join(''));
});
});

Expand Down Expand Up @@ -129,7 +129,7 @@ exports.getClients = function(req, res) {
data.push(chunk);
});
res_get.on('end', function() {
res.send(data.join(''));
res.status(res_get.statusCode).send(data.join(''));
});
});

Expand Down Expand Up @@ -162,7 +162,7 @@ exports.getClient = function(req, res) {
data.push(chunk);
});
res_get.on('end', function() {
res.send(data.join(''));
res.status(res_get.statusCode).send(data.join(''));
});
});

Expand Down Expand Up @@ -226,7 +226,7 @@ exports.editClient = function(req, res) {
data.push(chunk);
});
res_put.on('end', function() {
res.send(data.join(''));
res.status(res_put.statusCode).send(data.join(''));
});
});

Expand Down Expand Up @@ -257,7 +257,7 @@ exports.getClientId = function(req, res) {
data.push(chunk);
});
res_get.on('end', function() {
res.send(data.join(''));
res.status(res_get.statusCode).send(data.join(''));
});
});

Expand Down Expand Up @@ -289,7 +289,7 @@ exports.authenticateUser = function(req, res) {
data.push(chunk);
});
res_post.on('end', function() {
res.send(data);
res.status(res_post.statusCode).send(data);
});
});

Expand Down Expand Up @@ -318,12 +318,12 @@ exports.getIdentity = function (req, res) {
// Set up the request
var post_req = http.request(post_options, function(res_post) {
res_post.setEncoding('utf8');
var data = []
var data = [];
res_post.on('data', function (chunk) {
data.push(chunk);
});
res_post.on('end', function() {
res.send(data);
res.status(res_post.statusCode).send(data);
});
});

Expand All @@ -332,32 +332,4 @@ exports.getIdentity = function (req, res) {
post_req.end()
};

exports.getUserInfo = function(req, res) {

var get_options = {
host: config.api.host,
port: config.api.port,
path: '/openhmis/api/v3/users/' + req.query.user_id,
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': req.query.token
}
};

// Set up the request
var get_req = http.request(get_options, function(res_get) {
res_get.setEncoding('utf8');
var data = []
res_get.on('data', function (chunk) {
data.push(chunk);
});
res_get.on('end', function() {
console.log("DEBUG: user info is: " + data);
res.send(data.join(''));
});
});

// get the data
get_req.end()
};
1 change: 0 additions & 1 deletion app/routes/client.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ module.exports = function(app) {
app.route('/client_id').get(client.getClientId);
app.route('/authenticate').post(client.authenticateUser);
app.route('/identify').post(client.getIdentity);
app.route('/user_account').get(client.getUserInfo);
};
1 change: 1 addition & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and definitely add more when you add new functionality.
- account info shows up at top right
- search
- edit
- switch to edit screen works
- search after editing (should show new/changed info)
- export
- should have latest version of data
Expand Down
4 changes: 2 additions & 2 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ function getClients(token) {
new_client['dateCreated'] = quickConvertDate(line[21]);
new_client['dateUpdated'] = quickConvertDate(line[22]);
// do the POST!
new_client['id_token'] = id_token;
new_client['id_token'] = getCookie('id_token=');
$.ajax("/clients/", {
method: "POST",
data: new_client,
Expand Down Expand Up @@ -1379,7 +1379,7 @@ function saveChanges() {
client['gender'] = $("#intakeForm #gender").val();
client['ethnicity'] = $("#intakeForm #ethnicity").val();
client['ssn'] = $("#intakeForm #ssn").val();
client['id_token'] = id_token;
client['id_token'] = getCookie('id_token=');
if (entityIndex > 0 ){
$.ajax("/clients/" + entityIndex, {
method: "PUT",
Expand Down
4 changes: 2 additions & 2 deletions public/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function switchToSearch(keepResults) {
*/
function getLoginInfo(token) {
var token_wrapper = {"token": token};
var account_error_text = "Sorry, there was an error finding your account";
var account_error_text = "Sorry, there was an error finding your account.";
$.ajax({
type: 'POST',
url: '/identify/',
Expand All @@ -103,7 +103,7 @@ function getLoginInfo(token) {
document.cookie = "user_name=" + account.user.externalId;
document.cookie = "user_org=" + account.user.organization;
document.cookie = "user_coc=" + account.user.coC;
$("#loginInfo").html(getCookie('user_name=') + "<br/>" + getCookie('user_org=') + "<br/>" + getCookie('user_coc='));
$("#loginInfo").html(getCookie('user_name=') + "<br/>" + getCookie('user_org=') + "<br/>CoC: " + getCookie('user_coc='));
}
else {
document.cookie = "user_name=" + account.externalId;
Expand Down

0 comments on commit 0e3dee9

Please sign in to comment.