Skip to content

Commit

Permalink
Merge branch 'feature/165167110/oauth-payload-handle' of https://gith…
Browse files Browse the repository at this point in the history
…ub.com/andela/apollo-ah-backend into feature/165167110/oauth-payload-handle
  • Loading branch information
devdbrandy committed Apr 9, 2019
2 parents 4af37f5 + b76bc21 commit 65e806c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Binary file added public/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion server/controllers/profileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
SERVER_ERROR,
OK,
NOT_FOUND,
FORBIDDEN,
} = STATUS;

/** profile controller class */
Expand Down Expand Up @@ -42,7 +43,7 @@ class ProfileController {
};
const profileExists = await ProfileController.profileUsernameExists(username, userId);
if (profileExists !== null) {
return Response.send(res, CREATED, {}, MESSAGE.USERNAME_EXITS, true);
return Response.send(res, FORBIDDEN, {}, MESSAGE.USERNAME_EXITS, true);
}
try {
await Profile.update(
Expand Down
13 changes: 6 additions & 7 deletions server/controllers/usersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UsersController {
const { body } = request;

try {
const user = await User.create(body);
const user = await User.create(body, { raw: true });
const role = await models.Role.findOne({ where: { name: 'user' } });
await user.setRole(role);
const token = await generateToken({ user });
Expand All @@ -50,8 +50,8 @@ class UsersController {
};
user.firstname = '';
user.lastname = '';
user.gender = '';
user.bio = '';
user.image = `${env('API_DOMAIN')}/avatar.png`;
user.username = request.body.username.toLowerCase();
user.userId = user.id;
await models.Profile.create(user);
Expand Down Expand Up @@ -164,8 +164,10 @@ class UsersController {
const user = await User.findOne({
where: { email },
raw: true,
include: [{
model: models.Profile,
}]
});

// validate user password
if (!user || (user && !User.comparePassword(user, password))) {
return Response.send(
Expand All @@ -176,11 +178,8 @@ class UsersController {
false
);
}

// generate token from user payload
const payload = user;
const token = await generateToken(payload);

const token = await generateToken(user);
// respond with token
return response
.status(200)
Expand Down
1 change: 0 additions & 1 deletion server/models/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ const Profile = (sequelize, DataTypes) => {
};
return ProfileSchema;
};

export default Profile;

0 comments on commit 65e806c

Please sign in to comment.