Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Make emails unique
Browse files Browse the repository at this point in the history
Emails are made unique. When user attempts to sign in through a provider in which his email is one that is already registered, user is redirected to the signin page with an error passed as a query string parameter.
  • Loading branch information
igorauad committed Jul 17, 2015
1 parent e1605b6 commit 5d4d7ce
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/core/server/controllers/errors.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ var getUniqueErrorMessage = function(err) {

try {
var fieldName = err.err.substring(err.err.lastIndexOf('.$') + 2, err.err.lastIndexOf('_1'));
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exist';
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exists';

} catch(ex) {
output = 'Unique field already exist';
output = 'Unique field already exists';
}

return output;
Expand Down
2 changes: 1 addition & 1 deletion modules/users/client/config/users.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ angular.module('users').config(['$stateProvider',
templateUrl: 'modules/users/views/authentication/signup.client.view.html'
}).
state('authentication.signin', {
url: '/signin',
url: '/signin?err',
templateUrl: 'modules/users/views/authentication/signin.client.view.html'
}).
state('password', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http
function($scope, $http, $location, Authentication) {
$scope.authentication = Authentication;

// Get an eventual error defined in the URL query string:
$scope.error = $location.search().err;

// If user is signed in then redirect back home
if ($scope.authentication.user) $location.path('/');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ <h3 class="col-md-12 text-center">Or with your account</h3>
&nbsp; or&nbsp;
<a data-ui-sref="authentication.signup">Sign up</a>
</div>
<div class="forgot-password">
<div class="text-center forgot-password">
<a data-ui-sref="password.forgot">Forgot your password?</a>
</div>
<div data-ng-show="error" class="text-center text-danger">
<strong data-ng-bind="error"></strong>
</div>
<alert type="danger" data-ng-show="error" class="text-center text-danger">
<span data-ng-bind="error"></span>
</alert>
</fieldset>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ exports.signout = function (req, res) {
exports.oauthCallback = function (strategy) {
return function (req, res, next) {
passport.authenticate(strategy, function (err, user, redirectURL) {
if (err || !user) {
return res.redirect('/#!/signin');
if (err) {
return res.redirect('/authentication/signin?err=' + encodeURIComponent(errorHandler.getErrorMessage(err)));
}
if (!user) {
return res.redirect('/authentication/signin');
}
req.login(user, function (err) {
if (err) {
return res.redirect('/#!/signin');
return res.redirect('/authentication/signin');
}

return res.redirect(redirectURL || '/');
Expand Down
1 change: 1 addition & 0 deletions modules/users/server/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var UserSchema = new Schema({
email: {
type: String,
trim: true,
unique: true,
default: '',
validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
},
Expand Down

0 comments on commit 5d4d7ce

Please sign in to comment.