Skip to content

Commit

Permalink
Merge pull request #3 from techla/17-roles
Browse files Browse the repository at this point in the history
17 roles
  • Loading branch information
techla authored Mar 22, 2018
2 parents 383c694 + 7212826 commit 8207831
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ var noReturnUrls = [
exports.signup = async function (req, res, next) {
try {
const user = await UserService.signUp(req.body)
const { _id, firstName, lastName, email, username } = user
const payload = { id: _id, firstName, lastName, email, username }
const { _id, firstName, lastName, email, username, roles } = user;
const payload = { id: _id, firstName, lastName, email, username, roles }
const token = jwt.sign(payload, config.jwt.secret)
return res.status(200)
.cookie('TOKEN', token, { maxAge: 900000, httpOnly: true })
.json({ user: payload, tokenExpiresIn: 101010010101 })
.json({ user: payload, tokenExpiresIn: (new Date(Date.now() + 60 * 60 * 24 * 1000)).getTime() })
} catch(err) {
return next(new ApiError(err.message))
}
Expand All @@ -42,12 +42,12 @@ exports.signup = async function (req, res, next) {
* Signin after passport authentication
*/
exports.signin = async function (req, res) {
const { _id, firstName, lastName, email, username } = req.user;
const payload = { id: _id, firstName, lastName, email, username };
const { _id, firstName, lastName, email, username, roles } = req.user;
const payload = { id: _id, firstName, lastName, email, username, roles };
const token = jwt.sign(payload, configuration.jwt.secret);
return res.status(200)
.cookie('TOKEN', token)
.json({ user: payload, tokenExpiresIn: 10101010101 });
.json({ user: payload, tokenExpiresIn: (new Date(Date.now() + 60 * 60 * 24 * 1000)).getTime() });
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ exports.update = function (req, res) {

user.updated = Date.now();
user.displayName = user.firstName + ' ' + user.lastName;

user.save(function (err) {
User.findByIdAndUpdate(user.id, user, function (err) {
if (err) {
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
Expand Down
1 change: 1 addition & 0 deletions server/modules/users/server/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class UserService {
username: user.username,
email: user.email,
provider: user.provider,
roles: user.roles,
created: user.created,
}
}
Expand Down

0 comments on commit 8207831

Please sign in to comment.