-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oauth): multiple strategies per account; changeable email
- Loading branch information
Showing
33 changed files
with
789 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,35 @@ | |
<div class="container"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
<h1>Change Password</h1> | ||
<h1>Email</h1> | ||
</div> | ||
<div class="col-sm-12"> | ||
<form class="form" name="form" ng-submit="changePassword(form)" novalidate> | ||
<form role="form" name="email" ng-submit="changeEmail()" novalidate> | ||
|
||
<div class="form-group has-feedback"> | ||
<label>Current Email</label> | ||
<input type="email" name="email" class="form-control" ng-model="user.email" placeholder='ex. [email protected]' /> | ||
<p class="help-block" ng-show="!email.email.$valid"> | ||
| Email not valid | ||
</p> | ||
</div> | ||
|
||
<button class="btn btn-lg btn-primary" type="submit">Save changes</button> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
<h1><% if (filters.oauth) { %>{{ user.localEnabled ? 'Change' : 'Set' }}<% } else { %>Change<% } %> Password</h1> | ||
</div> | ||
<div class="col-sm-12"> | ||
<form name="pwd" ng-submit="<% if(filters.oauth) { %>!user.localEnabled ? setPassword() : <% } %>changePassword()" novalidate> | ||
|
||
<div class="form-group"> | ||
<label>Current Password</label> | ||
|
||
<input type="password" name="password" class="form-control" ng-model="user.oldPassword" | ||
mongoose-error/> | ||
<input type="password" name="old" placeholder='ex. password123' class="form-control" ng-model="user.oldPassword" | ||
mongoose-error <% if (filters.oauth) { %>ng-disabled='!user.localEnabled' <% } %>/> | ||
<p class="help-block" ng-show="form.password.$error.mongoose"> | ||
{{ errors.other }} | ||
</p> | ||
|
@@ -21,11 +40,11 @@ <h1>Change Password</h1> | |
<div class="form-group"> | ||
<label>New Password</label> | ||
|
||
<input type="password" name="newPassword" class="form-control" ng-model="user.newPassword" | ||
<input type="password" name="new" placeholder='ex. GoofyM1ckeyDonald&Pluto' class="form-control" ng-model="user.newPassword" | ||
ng-minlength="3" | ||
required/> | ||
required /> | ||
<p class="help-block" | ||
ng-show="(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || submitted)"> | ||
ng-show="(pwd.new.$error.minlength || pwd.new.$error.required) && (pwd.new.$dirty || pwd.submitted)"> | ||
Password must be at least 3 characters. | ||
</p> | ||
</div> | ||
|
@@ -36,4 +55,12 @@ <h1>Change Password</h1> | |
</form> | ||
</div> | ||
</div> | ||
<% if (filters.oauth) { %> | ||
<!-- <div class="row"> | ||
<div class="col-sm-12"> | ||
<h1>Social accounts</h1> | ||
</div> | ||
<div class="col-sm-12"></div> | ||
</div> --> | ||
<% } %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,47 @@ div(ng-include='"components/navbar/navbar.html"') | |
.container | ||
.row | ||
.col-sm-12 | ||
h1 Change Password | ||
h1 Email | ||
|
||
.col-sm-12 | ||
form(role='form', name='email', ng-submit='changeEmail()', novalidate) | ||
|
||
.form-group.has-feedback | ||
label Current Email | ||
input.form-control(type='email', name='email', ng-model='user.email', placeholder='ex. [email protected]') | ||
span.glyphicon.glyphicon-ok.form-control-feedback(ng-if='email.confirmed', title='email confirmed') | ||
p.help-block(ng-show='!email.email.$valid') | ||
| Email not valid | ||
|
||
button.btn.btn-lg.btn-primary(type='submit') Save changes | ||
|
||
.row | ||
.col-sm-12 | ||
form.form(name='form', ng-submit='changePassword(form)', novalidate='') | ||
h1 <% if (filters.oauth) { %>{{ user.localEnabled ? 'Change' : 'Set' }}<% } else { %>Change<% } %> Password | ||
|
||
.col-sm-12 | ||
form(role='form', name='pwd', ng-submit='<% if(filters.oauth) { %>!user.localEnabled ? setPassword() : <% } %>changePassword()', novalidate) | ||
|
||
.form-group | ||
label Current Password | ||
input.form-control(type='password', name='password', ng-model='user.oldPassword', mongoose-error='') | ||
p.help-block(ng-show='form.password.$error.mongoose') | ||
input.form-control(type='password', name='old', placeholder='ex. password123', ng-model='user.oldPassword', <% if (filters.oauth) { %>ng-disabled='!user.localEnabled', <% } %>mongoose-error='') | ||
p.help-block(ng-show='pwd.old.$error.mongoose') | ||
| {{ errors.other }} | ||
|
||
.form-group | ||
label New Password | ||
input.form-control(type='password', name='newPassword', ng-model='user.newPassword', ng-minlength='3', required='') | ||
p.help-block(ng-show='(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || submitted)') | ||
input.form-control(type='password', name='new', placeholder='ex. GoofyM1ckeyDonald&Pluto', ng-model='user.newPassword', ng-minlength='3', required) | ||
p.help-block(ng-show='(pwd.new.$error.minlength || pwd.new.$error.required) && (pwd.new.$dirty || pwd.submitted)') | ||
| Password must be at least 3 characters. | ||
|
||
p.help-block {{ message }} | ||
p.help-block {{ message }} | ||
|
||
button.btn.btn-lg.btn-primary(type='submit') Save changes | ||
|
||
<% if (filters.oauth) { %> | ||
//- .row | ||
//- .col-sm-12 | ||
//- h1 Social accounts | ||
//- .col-sm-12 | ||
<% } %> |
54 changes: 48 additions & 6 deletions
54
app/templates/client/app/account(auth)/settings/settings.controller(coffee).coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,59 @@ | ||
'use strict' | ||
|
||
angular.module '<%= scriptAppName %>' | ||
.controller 'SettingsCtrl', ($scope, User, Auth) -> | ||
.controller 'SettingsCtrl', ($scope, Auth) -> | ||
$scope.errors = {} | ||
$scope.changePassword = (form) -> | ||
$scope.submitted = true | ||
|
||
if form.$valid | ||
$scope.user = Auth.getCurrentUser() | ||
$scope.email = {} | ||
|
||
getEmail = (user) -> | ||
return [null, null] unless $scope.user.credentials.length | ||
|
||
for c in $scope.user.credentials when c.type is 'email' | ||
return [c.value, c.confirmed] | ||
|
||
[null, null] | ||
|
||
[initialEmail, $scope.email.confirmed] = getEmail $scope.user | ||
|
||
$scope.user.email = initialEmail | ||
|
||
$scope.changeEmail = -> | ||
if $scope.email.$valid | ||
Auth.changeEmail initialEmail, $scope.user.email | ||
.then -> | ||
$scope.message = 'Email successfully changed' | ||
|
||
.catch -> | ||
# TODO: handle errors | ||
$scope.message = '' | ||
|
||
$scope.changePassword = -> | ||
$scope.pwd.submitted = true | ||
|
||
if $scope.pwd.$valid | ||
Auth.changePassword $scope.user.oldPassword, $scope.user.newPassword | ||
.then -> | ||
$scope.message = 'Password successfully changed.' | ||
$scope.message = 'Password successfully changed' | ||
|
||
.catch -> | ||
form.password.$setValidity 'mongoose', false | ||
$scope.pwd.old.$setValidity 'mongoose', false | ||
$scope.errors.other = 'Incorrect password' | ||
$scope.message = '' | ||
<% if (filters.oauth) { %> | ||
$scope.setPassword = -> | ||
$scope.pwd.submitted = true | ||
|
||
if $scope.pwd.$valid | ||
Auth.setPassword $scope.user.newPassword | ||
.then -> | ||
$scope.message = 'Password successfully set' | ||
$scope.user.localEnabled = true | ||
$scope.user.newPassword = '' | ||
|
||
.catch -> | ||
$scope.pwd.old.$setValidity 'mongoose', false | ||
$scope.errors.other = 'Another account with that email already exists' | ||
$scope.message = '' | ||
<% } %> |
62 changes: 56 additions & 6 deletions
62
app/templates/client/app/account(auth)/settings/settings.controller(js).js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,71 @@ | ||
'use strict'; | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller('SettingsCtrl', function ($scope, User, Auth) { | ||
.controller('SettingsCtrl', function ($scope, Auth) { | ||
$scope.errors = {}; | ||
|
||
$scope.changePassword = function(form) { | ||
$scope.submitted = true; | ||
if(form.$valid) { | ||
$scope.user = Auth.getCurrentUser(); | ||
$scope.email = {}; | ||
|
||
var getEmail = function(user) { | ||
if (!$scope.user.credentials.length) { | ||
return null; | ||
} | ||
|
||
for(var i in $scope.user.credentials) { | ||
var c = $scope.user.credentials[i]; | ||
if(c.type==='email') return [c.value, c.confirmed]; | ||
} | ||
}; | ||
|
||
var tmp = getEmail($scope.user); | ||
|
||
var initialEmail = tmp ? tmp[0] : null; | ||
$scope.email.confirmed = tmp ? tmp[1] : null; | ||
|
||
$scope.user.email = initialEmail; | ||
|
||
$scope.changeEmail = function () { | ||
if($scope.email.$valid) { | ||
Auth.changeEmail(initialEmail, $scope.user.email) | ||
.then(function() { | ||
$scope.message = 'Email successfully changed'; | ||
}) | ||
.catch(function() { | ||
// TODO: handle errors | ||
$scope.message = ''; | ||
}); | ||
} | ||
} | ||
|
||
$scope.changePassword = function() { | ||
$scope.pwd.submitted = true; | ||
if($scope.pwd.$valid) { | ||
Auth.changePassword( $scope.user.oldPassword, $scope.user.newPassword ) | ||
.then( function() { | ||
$scope.message = 'Password successfully changed.'; | ||
$scope.message = 'Password successfully changed'; | ||
}) | ||
.catch( function() { | ||
form.password.$setValidity('mongoose', false); | ||
$scope.pwd.old.$setValidity('mongoose', false); | ||
$scope.errors.other = 'Incorrect password'; | ||
$scope.message = ''; | ||
}); | ||
} | ||
}; | ||
<% if (filters.oauth) { %> | ||
$scope.setPassword = function() { | ||
$scope.submitted = true; | ||
if($scope.pwd.$valid) { | ||
Auth.changePassword( $scope.user.newPassword ) | ||
.then( function() { | ||
$scope.message = 'Password successfully set'; | ||
}) | ||
.catch( function() { | ||
$scope.pwd.old.$setValidity('mongoose', false); | ||
$scope.errors.other = 'Another account with that email already exists'; | ||
$scope.message = ''; | ||
}); | ||
} | ||
}; | ||
<% } %> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.trash { color:rgb(209, 91, 71); } | ||
.confirm { color:rgb(240, 173, 78); } | ||
.confirmed { color:rgb(92, 184, 92); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.trash { color:rgb(209, 91, 71); } | ||
.trash { color:rgb(209, 91, 71); } | ||
.confirm { color:rgb(240, 173, 78); } | ||
.confirmed { color:rgb(92, 184, 92); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.trash { color:rgb(209, 91, 71); } | ||
.confirm { color:rgb(240, 173, 78); } | ||
.confirmed { color:rgb(92, 184, 92); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
.trash | ||
color rgb(209, 91, 71) | ||
color rgb(209, 91, 71) | ||
|
||
.confirm | ||
color: rgb(240, 173, 78) | ||
|
||
.confirmed | ||
color: rgb(92, 184, 92) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.