Completed
Push — master ( 1608e3...7f081a )
by Sander
02:27
created

js/importers/importer-padlock.js   A

Complexity

Total Complexity 14
Complexity/F 4.67

Size

Lines of Code 73
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 0
c 2
b 1
f 0
nc 2
dl 0
loc 73
rs 10
wmc 14
mnd 3
bc 13
fnc 3
bpm 4.3333
cpm 4.6666
noi 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A PassmanImporter.padlock.readFile 0 60 1
A 0 72 1
1
/**
2
 * Nextcloud - passman
3
 *
4
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
5
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
6
 * @copyright Copyright (c) 2017, Bingen Eguzkitza ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
// TODO: Allow for new lines and commas in values
25
26
// Importers should always start with this
27
/** global: PassmanImporter */
28
var PassmanImporter = PassmanImporter || {};
29
(function(window, $, PassmanImporter) {
30
	'use strict';
31
	// Define the importer
32
	PassmanImporter.padlock = {
33
		info: {
34
			name: 'Padlock',
35
			id: 'padlock',
36
			exportSteps: ['Create a csv export. Go to Menu -> Settings -> Export Data and copy text into a .csv file']
37
		}
38
	};
39
40
	PassmanImporter.padlock.readFile = function (file_data) {
41
		/** global: C_Promise */
42
		return new C_Promise(function(){
43
			var rows = PassmanImporter.readCsv(file_data, true);
44
			var credential_list = [];
45
			for (var i = 0; i < rows.length; i++) {
46
				var row = rows[i];
47
				var _credential = PassmanImporter.newCredential();
48
				var j = 0;
49
				for (var k in row) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
50
					if (!row[k]) {
51
						continue;
52
					}
53
					if (k == 'name') {
54
						_credential.label = row.name;
55
						continue;
56
					}
57
					if (k == 'username') {
58
						_credential.username = row.username;
59
						continue;
60
					}
61
					if (k == 'password') {
62
						_credential.password = row.password;
63
						continue;
64
					}
65
					if (k.toLowerCase() == 'url') {
66
						_credential.url = row[k];
67
						continue;
68
					}
69
					if (k.toLowerCase() == 'e-mail' ||
70
					    k.toLowerCase() == 'email') {
71
						_credential.email = row[k];
72
						continue;
73
					}
74
					if (k.toLowerCase() == 'description') {
75
						_credential.description = row[k];
76
						continue;
77
					}
78
					_credential.custom_fields[j] = {
79
						'label' : k,
80
						'value' : row[k],
81
						'secret' : true,
82
						'field_type' : 'text'
83
					};
84
					j++;
85
				}
86
				if(_credential.label){
87
					credential_list.push(_credential);
88
				}
89
90
				var progress = {
91
					percent: i/rows.length*100,
92
					loaded: i,
93
					total: rows.length
94
				};
95
				this.call_progress(progress);
96
			}
97
			this.call_then(credential_list);
98
		});
99
	};
100
})(window, $, PassmanImporter);
101