Skip to content

Commit

Permalink
Merge pull request #49 from andela/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
9jaswag committed Apr 11, 2019
2 parents 73ee94b + 1d70543 commit 784d376
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
20 changes: 16 additions & 4 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sendMail from '../helpers/emails';
import getName from '../helpers/user';
import { User } from '../models';

const { HOST_URL } = process.env;
const { HOST_URL_FRONTEND } = process.env;

dotenv.config();
const { JWT_SECRET } = process.env;
Expand Down Expand Up @@ -41,12 +41,15 @@ export default class UserController {
})
.then((newUser) => {
const {
dataValues: { id }
dataValues: { id, role }
} = newUser;
const token = generateToken(id);
return res.status(201).json({
success: true,
message: 'You have signed up successfully.',
user: {
name, username, email, role
},
token
});
})
Expand Down Expand Up @@ -91,9 +94,18 @@ export default class UserController {
const expiresIn = rememberMe ? '240h' : '24h';
try {
const token = generateToken(user.id, expiresIn);
const {
username, email, name, role
} = user;
return res.status(200).json({
success: true,
message: `Welcome ${user.username}`,
message: `Welcome ${username}`,
user: {
username,
email,
name,
role
},
token
});
} catch (err) {
Expand Down Expand Up @@ -168,7 +180,7 @@ export default class UserController {
const emailPayload = {
name,
email,
link: `${HOST_URL}/api/v1/resetpassword/${passwordResetToken}`,
link: `${HOST_URL_FRONTEND}/resetpassword/${passwordResetToken}`,
subject: 'Reset your password',
message: 'reset your password'
};
Expand Down
4 changes: 2 additions & 2 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sendMail from '../helpers/emails';

dotenv.config();

const { HOST_URL } = process.env;
const { HOST_URL_FRONTEND } = process.env;

module.exports = (sequelize, DataTypes) => {
const userSchema = {
Expand Down Expand Up @@ -113,7 +113,7 @@ module.exports = (sequelize, DataTypes) => {
const emailPayload = {
name,
email,
link: `${HOST_URL}/api/v1/verify/${verificationId}`,
link: `${HOST_URL_FRONTEND}/verify/${verificationId}`,
subject: "Welcome to Author's Haven",
message: 'verify your account'
};
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/userDummyData.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const validLoginUser = {

export const myUser = {
username: 'Alex20',
email: 'jacynnadi20@gmail.com',
email: 'jacynnad120@gmail.com',
name: 'Jacy20',
password: 'password'
};
Expand Down
2 changes: 1 addition & 1 deletion test/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('User login authentication: ', () => {
status,
body: { success, message }
} = res;
expect(res.body).be.an('object').which.has.keys(['success', 'message', 'token']);
expect(res.body).be.an('object').which.has.keys(['success', 'message', 'token', 'user']);
expect(status).to.be.equal(200);
expect(success).to.be.equal(true);
expect(message).to.be.equal(`Welcome ${superAdmin.username}`);
Expand Down

0 comments on commit 784d376

Please sign in to comment.