Completed
Push — master ( 4e8691...51d7d6 )
by Sander
55s
created

angular.controller(ꞌPasswordPromptCtrlꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 54
rs 9.6716

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
                    if (isValid) {
54
                        API.runtime.sendMessage(API.runtime.id, {
55
                            method: "setMasterPassword",
56
                            args: {password: $scope.master_password, savePassword: $scope.master_password_remember}
57
                        }).then(function () {
58
                            setTimeout(function () {
59
                                window.location = '#!/';
60
                                $scope.saving = false;
61
                                $rootScope.$broadcast('showHeader');
62
63
                            }, 750);
64
                        });
65
                    } else {
66
                        $scope.saving = false;
67
                        $scope.inValidPassword = true;
68
                    }
69
                    $scope.$apply();
70
                });
71
72
            };
73
            $scope.showResetPassword = function () {
74
                $scope.resetPassword = true;
75
            };
76
77
            $scope.resetExtension = function () {
78
                $scope.confirmReset = true;
79
            };
80
81
            $scope.confirmedResetExtension = function () {
82
                API.runtime.sendMessage(API.runtime.id, {method: 'resetSettings'}).then(function () {
83
                    setTimeout(function () {
84
                        window.close();
85
                    }, 500);
86
                });
87
            };
88
89
        }]);
90
}());
91
92