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

Commit 82d2377

Browse files
committed
Merge pull request #439 from igorauad/uniqueEmail
Make emails unique
2 parents e6b8a69 + 0efc82d commit 82d2377

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

modules/core/server/controllers/errors.server.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ var getUniqueErrorMessage = function(err) {
77
var output;
88

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

1313
} catch(ex) {
14-
output = 'Unique field already exist';
14+
output = 'Unique field already exists';
1515
}
1616

1717
return output;

modules/users/client/config/users.client.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ angular.module('users').config(['$stateProvider',
3636
templateUrl: 'modules/users/views/authentication/signup.client.view.html'
3737
}).
3838
state('authentication.signin', {
39-
url: '/signin',
39+
url: '/signin?err',
4040
templateUrl: 'modules/users/views/authentication/signin.client.view.html'
4141
}).
4242
state('password', {

modules/users/client/controllers/authentication.client.controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http
44
function($scope, $http, $location, Authentication) {
55
$scope.authentication = Authentication;
66

7+
// Get an eventual error defined in the URL query string:
8+
$scope.error = $location.search().err;
9+
710
// If user is signed in then redirect back home
811
if ($scope.authentication.user) $location.path('/');
912

modules/users/client/views/authentication/signin.client.view.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ <h3 class="col-md-12 text-center">Or with your account</h3>
1818
&nbsp; or&nbsp;
1919
<a data-ui-sref="authentication.signup">Sign up</a>
2020
</div>
21-
<div class="forgot-password">
21+
<div class="text-center forgot-password">
2222
<a data-ui-sref="password.forgot">Forgot your password?</a>
2323
</div>
24-
<div data-ng-show="error" class="text-center text-danger">
25-
<strong data-ng-bind="error"></strong>
26-
</div>
24+
<alert type="danger" data-ng-show="error" class="text-center text-danger">
25+
<span data-ng-bind="error"></span>
26+
</alert>
2727
</fieldset>
2828
</form>
2929
</div>

modules/users/server/controllers/users/users.authentication.server.controller.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ exports.signout = function (req, res) {
8383
exports.oauthCallback = function (strategy) {
8484
return function (req, res, next) {
8585
passport.authenticate(strategy, function (err, user, redirectURL) {
86-
if (err || !user) {
87-
return res.redirect('/#!/signin');
86+
if (err) {
87+
return res.redirect('/authentication/signin?err=' + encodeURIComponent(errorHandler.getErrorMessage(err)));
88+
}
89+
if (!user) {
90+
return res.redirect('/authentication/signin');
8891
}
8992
req.login(user, function (err) {
9093
if (err) {
91-
return res.redirect('/#!/signin');
94+
return res.redirect('/authentication/signin');
9295
}
9396

9497
return res.redirect(redirectURL || '/');

modules/users/server/models/user.server.model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var UserSchema = new Schema({
5252
email: {
5353
type: String,
5454
trim: true,
55+
unique: true,
5556
default: '',
5657
validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
5758
},

0 commit comments

Comments
 (0)