|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | angular.module('<%= scriptAppName %>') |
4 | | - .controller('SettingsCtrl', function ($scope, Auth) { |
| 4 | + .controller('SettingsCtrl', function ($scope, User, Auth) { |
5 | 5 | $scope.errors = {}; |
6 | 6 |
|
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) { |
| 7 | + $scope.changePassword = function(form) { |
| 8 | + $scope.submitted = true; |
| 9 | + if(form.$valid) { |
44 | 10 | Auth.changePassword( $scope.user.oldPassword, $scope.user.newPassword ) |
45 | 11 | .then( function() { |
46 | | - $scope.message = 'Password successfully changed'; |
| 12 | + $scope.message = 'Password successfully changed.'; |
47 | 13 | }) |
48 | 14 | .catch( function() { |
49 | | - $scope.pwd.old.$setValidity('mongoose', false); |
| 15 | + form.password.$setValidity('mongoose', false); |
50 | 16 | $scope.errors.other = 'Incorrect password'; |
51 | 17 | $scope.message = ''; |
52 | 18 | }); |
53 | 19 | } |
54 | 20 | }; |
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 | | -<% } %> |
71 | 21 | }); |
0 commit comments