Skip to content

Commit ef06272

Browse files
committed
feat(oauth): multiple strategies per account; changeable email
1 parent 46466b1 commit ef06272

33 files changed

+789
-383
lines changed

Diff for: app/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
139139
{
140140
value: 'googleAuth',
141141
name: 'Google',
142-
checked: false
142+
checked: true
143143
},
144144
{
145145
value: 'facebookAuth',
146146
name: 'Facebook',
147-
checked: false
147+
checked: true
148148
},
149149
{
150150
value: 'twitterAuth',
151151
name: 'Twitter',
152-
checked: false
152+
checked: true
153153
}
154154
]
155155
}, {

Diff for: app/templates/client/app/account(auth)/settings/settings(html).html

+34-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,35 @@
33
<div class="container">
44
<div class="row">
55
<div class="col-sm-12">
6-
<h1>Change Password</h1>
6+
<h1>Email</h1>
77
</div>
88
<div class="col-sm-12">
9-
<form class="form" name="form" ng-submit="changePassword(form)" novalidate>
9+
<form role="form" name="email" ng-submit="changeEmail()" novalidate>
10+
11+
<div class="form-group has-feedback">
12+
<label>Current Email</label>
13+
<input type="email" name="email" class="form-control" ng-model="user.email" placeholder='ex. [email protected]' />
14+
<p class="help-block" ng-show="!email.email.$valid">
15+
| Email not valid
16+
</p>
17+
</div>
18+
19+
<button class="btn btn-lg btn-primary" type="submit">Save changes</button>
20+
</form>
21+
</div>
22+
</div>
23+
<div class="row">
24+
<div class="col-sm-12">
25+
<h1><% if (filters.oauth) { %>{{ user.localEnabled ? 'Change' : 'Set' }}<% } else { %>Change<% } %> Password</h1>
26+
</div>
27+
<div class="col-sm-12">
28+
<form name="pwd" ng-submit="<% if(filters.oauth) { %>!user.localEnabled ? setPassword() : <% } %>changePassword()" novalidate>
1029

1130
<div class="form-group">
1231
<label>Current Password</label>
1332

14-
<input type="password" name="password" class="form-control" ng-model="user.oldPassword"
15-
mongoose-error/>
33+
<input type="password" name="old" placeholder='ex. password123' class="form-control" ng-model="user.oldPassword"
34+
mongoose-error <% if (filters.oauth) { %>ng-disabled='!user.localEnabled' <% } %>/>
1635
<p class="help-block" ng-show="form.password.$error.mongoose">
1736
{{ errors.other }}
1837
</p>
@@ -21,11 +40,11 @@ <h1>Change Password</h1>
2140
<div class="form-group">
2241
<label>New Password</label>
2342

24-
<input type="password" name="newPassword" class="form-control" ng-model="user.newPassword"
43+
<input type="password" name="new" placeholder='ex. GoofyM1ckeyDonald&Pluto' class="form-control" ng-model="user.newPassword"
2544
ng-minlength="3"
26-
required/>
45+
required />
2746
<p class="help-block"
28-
ng-show="(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || submitted)">
47+
ng-show="(pwd.new.$error.minlength || pwd.new.$error.required) && (pwd.new.$dirty || pwd.submitted)">
2948
Password must be at least 3 characters.
3049
</p>
3150
</div>
@@ -36,4 +55,12 @@ <h1>Change Password</h1>
3655
</form>
3756
</div>
3857
</div>
58+
<% if (filters.oauth) { %>
59+
<!-- <div class="row">
60+
<div class="col-sm-12">
61+
<h1>Social accounts</h1>
62+
</div>
63+
<div class="col-sm-12"></div>
64+
</div> -->
65+
<% } %>
3966
</div>

Diff for: app/templates/client/app/account(auth)/settings/settings(jade).jade

+34-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,47 @@ div(ng-include='"components/navbar/navbar.html"')
22
.container
33
.row
44
.col-sm-12
5-
h1 Change Password
5+
h1 Email
6+
7+
.col-sm-12
8+
form(role='form', name='email', ng-submit='changeEmail()', novalidate)
9+
10+
.form-group.has-feedback
11+
label Current Email
12+
input.form-control(type='email', name='email', ng-model='user.email', placeholder='ex. [email protected]')
13+
span.glyphicon.glyphicon-ok.form-control-feedback(ng-if='email.confirmed', title='email confirmed')
14+
p.help-block(ng-show='!email.email.$valid')
15+
| Email not valid
16+
17+
button.btn.btn-lg.btn-primary(type='submit') Save changes
18+
19+
.row
620
.col-sm-12
7-
form.form(name='form', ng-submit='changePassword(form)', novalidate='')
21+
h1 <% if (filters.oauth) { %>{{ user.localEnabled ? 'Change' : 'Set' }}<% } else { %>Change<% } %> Password
22+
23+
.col-sm-12
24+
form(role='form', name='pwd', ng-submit='<% if(filters.oauth) { %>!user.localEnabled ? setPassword() : <% } %>changePassword()', novalidate)
25+
826
.form-group
927
label Current Password
10-
input.form-control(type='password', name='password', ng-model='user.oldPassword', mongoose-error='')
11-
p.help-block(ng-show='form.password.$error.mongoose')
28+
input.form-control(type='password', name='old', placeholder='ex. password123', ng-model='user.oldPassword', <% if (filters.oauth) { %>ng-disabled='!user.localEnabled', <% } %>mongoose-error='')
29+
p.help-block(ng-show='pwd.old.$error.mongoose')
1230
| {{ errors.other }}
31+
1332
.form-group
1433
label New Password
15-
input.form-control(type='password', name='newPassword', ng-model='user.newPassword', ng-minlength='3', required='')
16-
p.help-block(ng-show='(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || submitted)')
34+
input.form-control(type='password', name='new', placeholder='ex. GoofyM1ckeyDonald&Pluto', ng-model='user.newPassword', ng-minlength='3', required)
35+
p.help-block(ng-show='(pwd.new.$error.minlength || pwd.new.$error.required) && (pwd.new.$dirty || pwd.submitted)')
1736
| Password must be at least 3 characters.
1837

19-
p.help-block {{ message }}
38+
p.help-block {{ message }}
2039

2140
button.btn.btn-lg.btn-primary(type='submit') Save changes
41+
42+
<% if (filters.oauth) { %>
43+
//- .row
44+
//- .col-sm-12
45+
//- h1 Social accounts
46+
47+
//- .col-sm-12
48+
<% } %>
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,59 @@
11
'use strict'
22

33
angular.module '<%= scriptAppName %>'
4-
.controller 'SettingsCtrl', ($scope, User, Auth) ->
4+
.controller 'SettingsCtrl', ($scope, Auth) ->
55
$scope.errors = {}
6-
$scope.changePassword = (form) ->
7-
$scope.submitted = true
86

9-
if form.$valid
7+
$scope.user = Auth.getCurrentUser()
8+
$scope.email = {}
9+
10+
getEmail = (user) ->
11+
return [null, null] unless $scope.user.credentials.length
12+
13+
for c in $scope.user.credentials when c.type is 'email'
14+
return [c.value, c.confirmed]
15+
16+
[null, null]
17+
18+
[initialEmail, $scope.email.confirmed] = getEmail $scope.user
19+
20+
$scope.user.email = initialEmail
21+
22+
$scope.changeEmail = ->
23+
if $scope.email.$valid
24+
Auth.changeEmail initialEmail, $scope.user.email
25+
.then ->
26+
$scope.message = 'Email successfully changed'
27+
28+
.catch ->
29+
# TODO: handle errors
30+
$scope.message = ''
31+
32+
$scope.changePassword = ->
33+
$scope.pwd.submitted = true
34+
35+
if $scope.pwd.$valid
1036
Auth.changePassword $scope.user.oldPassword, $scope.user.newPassword
1137
.then ->
12-
$scope.message = 'Password successfully changed.'
38+
$scope.message = 'Password successfully changed'
1339

1440
.catch ->
15-
form.password.$setValidity 'mongoose', false
41+
$scope.pwd.old.$setValidity 'mongoose', false
1642
$scope.errors.other = 'Incorrect password'
1743
$scope.message = ''
44+
<% if (filters.oauth) { %>
45+
$scope.setPassword = ->
46+
$scope.pwd.submitted = true
47+
48+
if $scope.pwd.$valid
49+
Auth.setPassword $scope.user.newPassword
50+
.then ->
51+
$scope.message = 'Password successfully set'
52+
$scope.user.localEnabled = true
53+
$scope.user.newPassword = ''
54+
55+
.catch ->
56+
$scope.pwd.old.$setValidity 'mongoose', false
57+
$scope.errors.other = 'Another account with that email already exists'
58+
$scope.message = ''
59+
<% } %>
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,71 @@
11
'use strict';
22

33
angular.module('<%= scriptAppName %>')
4-
.controller('SettingsCtrl', function ($scope, User, Auth) {
4+
.controller('SettingsCtrl', function ($scope, Auth) {
55
$scope.errors = {};
66

7-
$scope.changePassword = function(form) {
8-
$scope.submitted = true;
9-
if(form.$valid) {
7+
$scope.user = Auth.getCurrentUser();
8+
$scope.email = {};
9+
10+
var getEmail = function(user) {
11+
if (!$scope.user.credentials.length) {
12+
return null;
13+
}
14+
15+
for(var i in $scope.user.credentials) {
16+
var c = $scope.user.credentials[i];
17+
if(c.type==='email') return [c.value, c.confirmed];
18+
}
19+
};
20+
21+
var tmp = getEmail($scope.user);
22+
23+
var initialEmail = tmp ? tmp[0] : null;
24+
$scope.email.confirmed = tmp ? tmp[1] : null;
25+
26+
$scope.user.email = initialEmail;
27+
28+
$scope.changeEmail = function () {
29+
if($scope.email.$valid) {
30+
Auth.changeEmail(initialEmail, $scope.user.email)
31+
.then(function() {
32+
$scope.message = 'Email successfully changed';
33+
})
34+
.catch(function() {
35+
// TODO: handle errors
36+
$scope.message = '';
37+
});
38+
}
39+
}
40+
41+
$scope.changePassword = function() {
42+
$scope.pwd.submitted = true;
43+
if($scope.pwd.$valid) {
1044
Auth.changePassword( $scope.user.oldPassword, $scope.user.newPassword )
1145
.then( function() {
12-
$scope.message = 'Password successfully changed.';
46+
$scope.message = 'Password successfully changed';
1347
})
1448
.catch( function() {
15-
form.password.$setValidity('mongoose', false);
49+
$scope.pwd.old.$setValidity('mongoose', false);
1650
$scope.errors.other = 'Incorrect password';
1751
$scope.message = '';
1852
});
1953
}
2054
};
55+
<% if (filters.oauth) { %>
56+
$scope.setPassword = function() {
57+
$scope.submitted = true;
58+
if($scope.pwd.$valid) {
59+
Auth.changePassword( $scope.user.newPassword )
60+
.then( function() {
61+
$scope.message = 'Password successfully set';
62+
})
63+
.catch( function() {
64+
$scope.pwd.old.$setValidity('mongoose', false);
65+
$scope.errors.other = 'Another account with that email already exists';
66+
$scope.message = '';
67+
});
68+
}
69+
};
70+
<% } %>
2171
});

Diff for: app/templates/client/app/admin(auth)/admin(css).css

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.trash { color:rgb(209, 91, 71); }
2+
.confirm { color:rgb(240, 173, 78); }
3+
.confirmed { color:rgb(92, 184, 92); }

Diff for: app/templates/client/app/admin(auth)/admin(html).html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<li class="list-group-item" ng-repeat="user in users">
77
<strong>{{user.name}}</strong><br>
88
<span class="text-muted">{{user.email}}</span>
9+
<a ng-click="confirm(user)" ng-class="user.credentials[0].confirmed ? 'confirmed' : 'confirm'"><span class="glyphicon glyphicon-ok-circle"></span></a>
910
<a ng-click="delete(user)" class="trash"><span class="glyphicon glyphicon-trash pull-right"></span></a>
1011
</li>
1112
</ul>

Diff for: app/templates/client/app/admin(auth)/admin(jade).jade

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ div(ng-include='"components/navbar/navbar.html"')
66
li.list-group-item(ng-repeat='user in users')
77
strong {{user.name}}
88
br
9-
span.text-muted {{user.email}}
10-
a.trash(ng-click='delete(user)')
9+
span.text-muted {{user.credentials[0].value}}
10+
a(ng-click='confirm(user)', ng-class="user.credentials[0].confirmed ? 'confirmed' : 'confirm'", title='confirm email')
11+
span.glyphicon.glyphicon-ok-circle
12+
13+
a.trash(ng-click='delete(user)', title='delete user')
1114
span.glyphicon.glyphicon-trash.pull-right
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.trash { color:rgb(209, 91, 71); }
1+
.trash { color:rgb(209, 91, 71); }
2+
.confirm { color:rgb(240, 173, 78); }
3+
.confirmed { color:rgb(92, 184, 92); }
+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.trash { color:rgb(209, 91, 71); }
2+
.confirm { color:rgb(240, 173, 78); }
3+
.confirmed { color:rgb(92, 184, 92); }
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
.trash
2-
color rgb(209, 91, 71)
2+
color rgb(209, 91, 71)
3+
4+
.confirm
5+
color: rgb(240, 173, 78)
6+
7+
.confirmed
8+
color: rgb(92, 184, 92)

Diff for: app/templates/client/app/admin(auth)/admin.controller(coffee).coffee

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
angular.module '<%= scriptAppName %>'
4-
.controller 'AdminCtrl', ($scope, $http, Auth, User) ->
4+
.controller 'AdminCtrl', ($scope, $http, User) ->
55

66
$http.get '/api/users'
77
.success (users) ->
@@ -11,3 +11,6 @@ angular.module '<%= scriptAppName %>'
1111
User.remove id: user._id
1212
angular.forEach $scope.users, (u, i) ->
1313
$scope.users.splice i, 1 if u is user
14+
15+
$scope.confirm = (user) ->
16+
User.confirm id: user._id, null

Diff for: app/templates/client/app/admin(auth)/admin.controller(js).js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
angular.module('<%= scriptAppName %>')
4-
.controller('AdminCtrl', function ($scope, $http, Auth, User) {
4+
.controller('AdminCtrl', function ($scope, $http, User) {
55

66
$http.get('/api/users').success(function(users) {
77
$scope.users = users;
@@ -15,4 +15,8 @@ angular.module('<%= scriptAppName %>')
1515
}
1616
});
1717
};
18+
19+
$scope.confirm = function(user) {
20+
User.confirm({ id:user._id }, null);
21+
};
1822
});

0 commit comments

Comments
 (0)