Skip to content

Commit

Permalink
Merge branch 'develop' into bug/fix-response-error
Browse files Browse the repository at this point in the history
  • Loading branch information
AnayoOleru committed May 8, 2019
2 parents e863f0c + 522179b commit cdc1b1a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
16 changes: 12 additions & 4 deletions server/controllers/auth.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import dotenv from 'dotenv';
import db from '../models';
import authHelper from '../helpers/auth';
import searchDatabase from '../helpers/search-database';
import notifications from '../helpers/notifications';
import serverError from '../helpers/server-error';

dotenv.config();
const { findUser } = searchDatabase;
const { User } = db;
const error = ['invalid username and/or password'];
Expand Down Expand Up @@ -93,13 +95,19 @@ const signupController = async (req, res) => {
is_admin: isAdmin,
first_name: firstName,
is_reviewer: isReviewer,
is_activated: isActivated,
} = user;
const token = authHelper.encode({ id, isAdmin, isReviewer });
const token = authHelper.encode({
id,
email,
isAdmin,
isReviewer,
isActivated,
});

const verificationToken = authHelper.encode({ email });
const verificationLink = `${req.protocol}://${req.get(
'host'
)}/api/v1/auth/verification/${verificationToken}`;
const { FRONTEND_VERIFY_EMAIL_URL } = process.env;
const verificationLink = `${FRONTEND_VERIFY_EMAIL_URL}?token=${verificationToken}`;

await notifications.signupEmail(email, verificationLink, firstName);

Expand Down
10 changes: 10 additions & 0 deletions server/controllers/profile.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const getUserProfile = async (req, res) => {
'email',
'is_reviewer',
'research_field',
'image_url',
'bio',
'is_activated',
'is_reported',
'is_notified',
'createdAt',
'updatedAt',
],
Expand Down Expand Up @@ -93,6 +98,11 @@ const getProfileByField = async (req, res) => {
'email',
'is_reviewer',
'research_field',
'image_url',
'bio',
'is_activated',
'is_reported',
'is_notified',
'createdAt',
'updatedAt',
],
Expand Down
12 changes: 6 additions & 6 deletions server/controllers/reset-password.controllers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import dotenv from 'dotenv';
import notification from '../helpers/notifications';
import Authenticate from '../helpers/auth';
import model from '../models';
import serverError from '../helpers/server-error';

dotenv.config();
const { User } = model;

const { hashPassword } = Authenticate;
Expand Down Expand Up @@ -32,14 +34,12 @@ const updatePassword = async (req, res) => {
}
};

const acceptRequest = (req, res) =>
const acceptRequest = (req, res) => {
const { FRONTEND_PASSWORD_RESET_URL } = process.env;
res
.status(200)
.redirect(
`${req.protocol}://${req.get('host')}/api/v1/auth/reset/message?token=${
req.params.token
}`
);
.redirect(`${FRONTEND_PASSWORD_RESET_URL}?token=${req.params.token}`);
};

const ResetPasswordController = { updatePassword, acceptRequest };

Expand Down
2 changes: 1 addition & 1 deletion server/documentation/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const swaggerDefinition = {
description:
'A community of like-minded authors to foster inspiration and innovation by leveraging the modern web',
},
host: 'localhost:3000',
host: 'https://hermes-ah-backend.herokuapp.com',
basePath: '/api/v1',
schemes: ['https', 'http'],
securityDefinitions: {
Expand Down
1 change: 1 addition & 0 deletions server/helpers/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const profiler = user => {
lastname: user.last_name,
title: user.title,
bio: user.bio,
imageUrl: user.image_url,
phonenumber: user.phone_number,
email: user.email,
isreviewer: user.is_reviewer,
Expand Down
1 change: 1 addition & 0 deletions server/middlewares/reset-password.middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const ResetPasswordMiddleware = {

async mailer(req, res) {
try {
// const urlTest = req.body;
const linkUrl = `${req.protocol}://${req.get('host')}/api/v1/auth/reset/${
req.token
}/password`;
Expand Down
3 changes: 0 additions & 3 deletions server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ module.exports = (sequelize, DataTypes) => {
User.beforeCreate(user => {
user.password = authHelpers.hashPassword(user.password);
});
User.beforeUpdate(user => {
user.password = authHelpers.hashPassword(user.password);
});

User.associate = models => {
const { Follower, Article } = models;
Expand Down

0 comments on commit cdc1b1a

Please sign in to comment.