Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #238 from hunterwilliams/fix-updating-user
Browse files Browse the repository at this point in the history
Fix #229 Account Edits
  • Loading branch information
grtjn committed Sep 25, 2015
2 parents f9c615c + f923ca2 commit 9f67975
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
49 changes: 39 additions & 10 deletions app/templates/node-server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,47 @@ var options = {
};

router.get('/user/status', function(req, res) {
var headers = req.headers;
noCache(res);
if (req.session.user === undefined) {
res.send('{"authenticated": false}');
res.send({authenticated: false});
} else {
res.send({
authenticated: true,
username: req.session.user.name,
profile: req.session.user.profile
delete headers['content-length'];
var status = http.get({
hostname: options.mlHost,
port: options.mlHttpPort,
path: '/v1/documents?uri=/api/users/' + req.session.user.name + '.json',
headers: headers,
auth: req.session.user.name + ':' + req.session.user.password
}, function(response) {
if (response.statusCode === 200) {
response.on('data', function(chunk) {
var json = JSON.parse(chunk);
if (json.user !== undefined) {
res.status(200).send({
authenticated: true,
username: req.session.user.name,
profile: json.user
});
} else {
console.log('did not find chunk.user');
}
});
} else if (response.statusCode === 404) {
//no profile yet for user
res.status(200).send({
authenticated: true,
username: req.session.user.name,
profile: {}
});
} else {
res.send({authenticated: false});
}
});

status.on('error', function(e) {
console.log(JSON.stringify(e));
console.log('status check failed: ' + e.statusCode);
});
}
});
Expand Down Expand Up @@ -72,14 +105,10 @@ router.post('/user/login', function(req, res) {
response.on('data', function(chunk) {
var json = JSON.parse(chunk);
if (json.user !== undefined) {
req.session.user.profile = {
fullname: json.user.fullname,
emails: json.user.emails
};
res.status(200).send({
authenticated: true,
username: username,
profile: req.session.user.profile
profile: json.user
});
} else {
console.log('did not find chunk.user');
Expand Down
4 changes: 4 additions & 0 deletions app/templates/ui/app/user/profile.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
if (form.$valid) {
addEmail();

if (ctrl.user.emails) {
_.pull(ctrl.user.emails, '');
}

mlRest.updateDocument({
user: {
'fullname': ctrl.user.fullname,
Expand Down
1 change: 1 addition & 0 deletions app/templates/ui/app/user/user.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
loginService.login('test', 'abc').then(function(response) {
expect(response.data).to.deep.eq({ authenticated: true, username: 'bob' });
expect(service.currentUser()).to.deep.eq({ name: 'bob' });
expect(service.getUser()).to.deep.eq({ name: 'bob' });
});
expect($http.post).to.have.been.calledOnce;
$rootScope.$apply();
Expand Down

0 comments on commit 9f67975

Please sign in to comment.