Completed
Pull Request — master (#143)
by Sander
48s
created

angular.controller(ꞌPasswordPromptCtrlꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 28
rs 8.8571
c 1
b 0
f 0
1
/* global API */
2
3
/**
4
 * Nextcloud - passman
5
 *
6
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
7
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
(function () {
26
    'use strict';
27
28
    /**
29
     * @ngdoc function
30
     * @name passmanApp.controller:MainCtrl
31
     * @description
32
     * # MainCtrl
33
     * Controller of the passmanApp
34
     */
35
    angular.module('passmanExtension')
36
        .controller('PasswordPromptCtrl', ['$scope', 'Settings', '$location', '$rootScope', function ($scope, Settings, $window, $rootScope) {
37
            $scope.settings = {};
38
39
            API.runtime.sendMessage(API.runtime.id, {method: "getMasterPasswordSet"}).then(function (isSet) {
40
                $scope.masterPwSet = isSet;
41
                $scope.$apply();
42
            });
43
            $rootScope.$broadcast('hideHeader');
44
            $scope.master_password_remember = false;
45
            $scope.master_password = '';
46
            $scope.apply_settings = function () {
47
                $scope.saving = true;
48
                $scope.inValidPassword = false;
49
                API.runtime.sendMessage(API.runtime.id, {
50
                    method: 'isMasterPasswordValid',
51
                    args: $scope.master_password
52
                }).then(function (isValid) {
53
                    console.log({password: $scope.master_password, savePassword: $scope.master_password_remember});
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
54
                    if (isValid) {
55
                        API.runtime.sendMessage(API.runtime.id, {
56
                            method: "setMasterPassword",
57
                            args: {password: $scope.master_password, savePassword: $scope.master_password_remember}
58
                        }).then(function () {
59
                            setTimeout(function () {
60
                                window.location = '#!/';
61
                                $scope.saving = false;
62
                                $rootScope.$broadcast('showHeader');
63
64
                            }, 750);
65
                        });
66
                    } else {
67
                        $scope.saving = false;
68
                        $scope.inValidPassword = true;
69
                    }
70
                    $scope.$apply();
71
                });
72
73
            };
74
            $scope.showResetPassword = function () {
75
                $scope.resetPassword = true;
76
            };
77
78
            $scope.resetExtension = function () {
79
                $scope.confirmReset = true;
80
            };
81
82
            $scope.confirmedResetExtension = function () {
83
                API.runtime.sendMessage(API.runtime.id, {method: 'resetSettings'}).then(function () {
84
                    setTimeout(function () {
85
                        window.close()
86
                    }, 750);
87
                });
88
            };
89
90
        }]);
91
}());
92
93