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