-
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
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
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.