Skip to content

Commit

Permalink
Merge 2bc4c9d into 6d10d56
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaleb808 committed Apr 18, 2019
2 parents 6d10d56 + 2bc4c9d commit 5311c03
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions __tests__/routes/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Profile', () => {

expect(res.status).toBe(200);
expect(res.body.user.firstName).toBe('Peter');
expect(res.body.message).toBe('The information was updated successful');
expect(res.body.message).toBe('The information was updated successfully');
done();
});

Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Profile', () => {
.set('Authorization', loginUser1.token)
.send({ user: { username: 'claudine' } });
expect(res.status).toBe(200);
expect(res.body.message).toBe('The information was updated successful');
expect(res.body.message).toBe('The information was updated successfully');
done();
});

Expand Down
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ app.use(
secret: 'MYSECRETISVERYSECRET',
store,
resave: true,
saveUninitialized: true,
}),
saveUninitialized: true
})
);
app.use(passport.initialize());
app.use(passport.session());
Expand Down Expand Up @@ -66,8 +66,8 @@ app.use((err, req, res) => {
res.status(err.status || 500).json({
errors: {
message: err.message,
error: err,
},
error: err
}
});
});

Expand Down
10 changes: 5 additions & 5 deletions controllers/ArticleController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dotenv/config';
import opn from 'opn';
import open from 'open';
import sequelize, { Op } from 'sequelize';
import { User, Article, Favorite, Follow, Tag, Report, Bookmark, Reader } from '../database/models';
import { slugString, getReadingTime, calculateRating } from '../helpers';
Expand Down Expand Up @@ -413,7 +413,7 @@ class ArticleController {
message: 'Article not found'
});
}
opn(`https://twitter.com/intent/tweet?text=${process.env.FRONTEND_URL}/articles/${slug}`);
open(`https://twitter.com/intent/tweet?text=${process.env.FRONTEND_URL}/articles/${slug}`);
return res.status(200).json({ status: 200, message: 'Sharing article via Twitter' });
}

Expand All @@ -438,7 +438,7 @@ class ArticleController {
message: 'Article not found'
});
}
opn(
open(
`https://www.facebook.com/sharer/sharer.php?&u=https://lit-kigali1-staging.herokuapp.com/api/v1/article/${slug}`
);
return res.status(200).json({ status: 200, message: 'Sharing article via Facebook' });
Expand All @@ -465,7 +465,7 @@ class ArticleController {
message: 'Article not found'
});
}
opn(
open(
`https://www.linkedin.com/sharing/share-offsite/?url=${
process.env.FRONTEND_URL
}/articles/${slug}`
Expand Down Expand Up @@ -494,7 +494,7 @@ class ArticleController {
message: 'Article not found'
});
}
opn(`mailto:?subject=${article.title}&body=${process.env.FRONTEND_URL}/article/${slug}`);
open(`mailto:?subject=${article.title}&body=${process.env.FRONTEND_URL}/article/${slug}`);
return res.status(200).json({ status: 200, message: 'Sharing article via Email' });
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/AuthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import moment from 'moment';
import { User, ResetPassword, Token } from '../database/models';
import { sendEmailConfirmationLink, resetPasswordEmail, newPasswordEmail } from './MailController';

const { JWT_SECRET } = process.env;
const { JWT_SECRET, FRONTEND_URL } = process.env;

/**
* @description Authentication class
Expand Down Expand Up @@ -192,7 +192,7 @@ class AuthController {
* @returns {Object} Returns the response
*/
static async socialLogin(req, res) {
return res.json({ status: 200, user: req.user });
res.redirect(`${FRONTEND_URL}?token=${req.user.token}`);
}
}

Expand Down
11 changes: 7 additions & 4 deletions controllers/ProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class ProfileController {
await sendEmailConfirmationLink({ ...profile.get() });
message = 'Your email has changed. Please check your email for confirmation';
} else {
message = 'The information was updated successful';
message = 'The information was updated successfully';
}
const { confirmationCode, ...userData } = profile.get();
return res.status(200).send({
statu: 200,
status: 200,
message,
user: userData
});
Expand Down Expand Up @@ -198,12 +198,15 @@ class ProfileController {
*/
static async getCurrentUser(req, res) {
const { currentUser } = req;

const articles = await Article.findAll({
where: { userId: currentUser.id, status: { [Op.not]: 'deleted' } }
});
return res.status(200).json({
status: 200,
user: {
...currentUser,
password: undefined
password: undefined,
articles
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UserController {
await user.update({ confirmed: 'confirmed', confirmationCode: null });

await sendEmailVerified(user.get());
return res.json({ message: `${user.email} has been confirmed` });
return res.status(200).json({ status: 200, message: `${user.email} has been confirmed` });
}

/**
Expand Down
14 changes: 7 additions & 7 deletions middlewares/passportStrategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ passport.use(
try {
const data = profile._json;
const user = await User.findOrCreate({
where: { username: profile.id },
where: { username: data.screen_name },
defaults: {
username: data.id,
username: data.screen_name,
email: `${data.username}@twitter.com`,
firstName: data.screen_name,
password: data.id,
password: data.screen_name,
socialId: data.id,
socialEmail: data.email || null,
authType: 'twitter',
Expand Down Expand Up @@ -170,12 +170,12 @@ passport.use(
try {
const data = profile._json;
const user = await User.findOrCreate({
where: { socialId: profile.id },
where: { username: data.name.givenName },
defaults: {
username: data.id,
username: data.name.givenName,
email: data.id,
firstName: data.displayName,
password: profile.id,
firstName: data.name.givenName,
password: data.name.givenName,
socialId: profile.id,
socialEmail: data.email || null,
authType: 'Gmail',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"nock": "^10.0.6",
"node-sass": "^4.11.0",
"nodemon": "^1.18.9",
"open": "^6.1.0",
"opn": "^5.4.0",
"passport": "^0.4.0",
"passport-facebook": "^3.0.0",
Expand Down

0 comments on commit 5311c03

Please sign in to comment.