Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove hardcoded login paths and use config.public.loginPage instead #1518

Merged
merged 1 commit into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/users/public/services/meanUser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('mean.users').factory('MeanUser', [ '$rootScope', '$http', '$location', '$stateParams', '$cookies', '$q', '$timeout',
function($rootScope, $http, $location, $stateParams, $cookies, $q, $timeout) {
angular.module('mean.users').factory('MeanUser', [ '$rootScope', '$http', '$location', '$stateParams', '$cookies', '$q', '$timeout', '$meanConfig',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

function($rootScope, $http, $location, $stateParams, $cookies, $q, $timeout, $meanConfig) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.


var self;

Expand Down Expand Up @@ -186,7 +186,7 @@ angular.module('mean.users').factory('MeanUser', [ '$rootScope', '$http', '$loca
else {
$cookies.put('redirect', $location.path());
$timeout(deferred.reject);
$location.url('/auth/login');
$location.url($meanConfig.loginPage);
}
});

Expand Down
8 changes: 4 additions & 4 deletions packages/core/users/server/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function(MeanUser) {
*/
authCallback: function(req, res) {
var payload = req.user;
var escaped = JSON.stringify(payload);
var escaped = JSON.stringify(payload);
escaped = encodeURI(escaped);
// We are sending the payload inside the token
var token = jwt.sign(escaped, config.secret, { expiresInMinutes: 60*5 });
Expand All @@ -53,7 +53,7 @@ module.exports = function(MeanUser) {
if (req.isAuthenticated()) {
return res.redirect('/');
}
res.redirect('/login');
res.redirect(config.public.loginPage);
},

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ module.exports = function(MeanUser) {

// We are sending the payload inside the token
var token = jwt.sign(escaped, config.secret, { expiresInMinutes: 60*5 });
res.json({
res.json({
token: token,
redirect: config.strategies.landingPage
});
Expand Down Expand Up @@ -186,7 +186,7 @@ module.exports = function(MeanUser) {
escaped = encodeURI(escaped);
var token = jwt.sign(escaped, config.secret, { expiresInMinutes: 60*5 });
res.json({ token: token });

});
},

Expand Down
23 changes: 12 additions & 11 deletions packages/core/users/server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function(MeanUser, app, auth, database, passport) {

// User routes use users controller
var users = require('../controllers/users')(MeanUser);
var loginPage = config.public.loginPage;

app.route('/api/logout')
.get(users.signout);
Expand Down Expand Up @@ -85,12 +86,12 @@ module.exports = function(MeanUser, app, auth, database, passport) {
app.route('/api/auth/facebook')
.get(passport.authenticate('facebook', {
scope: ['email', 'user_about_me'],
failureRedirect: '/auth/login',
failureRedirect: loginPage,
}), users.signin);

app.route('/api/auth/facebook/callback')
.get(passport.authenticate('facebook', {
failureRedirect: '/auth/login',
failureRedirect: loginPage,
}), users.authCallback);
}

Expand All @@ -99,26 +100,26 @@ module.exports = function(MeanUser, app, auth, database, passport) {
// Setting the github oauth routes
app.route('/api/auth/github')
.get(passport.authenticate('github', {
failureRedirect: '/auth/login'
failureRedirect: loginPage
}), users.signin);

app.route('/api/auth/github/callback')
.get(passport.authenticate('github', {
failureRedirect: '/auth/login'
failureRedirect: loginPage
}), users.authCallback);
}

if(config.strategies.twitter.enabled)
{
{
// Setting the twitter oauth routes
app.route('/api/auth/twitter')
.get(passport.authenticate('twitter', {
failureRedirect: '/auth/login'
failureRedirect: loginPage
}), users.signin);

app.route('/api/auth/twitter/callback')
.get(passport.authenticate('twitter', {
failureRedirect: '/auth/login'
failureRedirect: loginPage
}), users.authCallback);
}

Expand All @@ -127,7 +128,7 @@ module.exports = function(MeanUser, app, auth, database, passport) {
// Setting the google oauth routes
app.route('/api/auth/google')
.get(passport.authenticate('google', {
failureRedirect: '/auth/login',
failureRedirect: loginPage,
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
Expand All @@ -136,7 +137,7 @@ module.exports = function(MeanUser, app, auth, database, passport) {

app.route('/api/auth/google/callback')
.get(passport.authenticate('google', {
failureRedirect: '/auth/login'
failureRedirect: loginPage
}), users.authCallback);
}

Expand All @@ -145,13 +146,13 @@ module.exports = function(MeanUser, app, auth, database, passport) {
// Setting the linkedin oauth routes
app.route('/api/auth/linkedin')
.get(passport.authenticate('linkedin', {
failureRedirect: '/auth/login',
failureRedirect: loginPage,
scope: ['r_emailaddress']
}), users.signin);

app.route('/api/auth/linkedin/callback')
.get(passport.authenticate('linkedin', {
failureRedirect: '/auth/login'
failureRedirect: loginPage
}), users.authCallback);
}

Expand Down