Completed
Push — master ( 641a91...fc9f6a )
by
unknown
10:16
created

js/importers/importer-dashlanecsv.js   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 48
rs 8.7018
c 0
b 0
f 0
nc 1
nop 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A PassmanImporter.dashLaneCsv.readFile 0 36 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
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
// Importers should always start with this
24
/** global: PassmanImporter */
25
var PassmanImporter = PassmanImporter || {};
26
(function(window, $, PassmanImporter) {
27
	'use strict';
28
	// Define the importer
29
	PassmanImporter.dashLaneCsv = {
30
		info: {
31
			name: 'Dashlane 4 csv',
32
			id: 'dashLaneCsv',
33
			exportSteps: ['Create an csv export. Go to File -> export -> Unsecured archive (readable) in CSV format']
34
		}
35
	};
36
37
	PassmanImporter.dashLaneCsv.readFile = function (file_data) {
38
		/** global: C_Promise */
39
		return new C_Promise(function(){
40
			var rows = file_data.split('\n');
41
			var credential_list = [];
42
			for (var i = 0; i < rows.length; i++) {
43
				var row = rows[i];
44
				var row_data = row.split('","');
45
				if (row_data[0].charAt(0) === '"') {
46
					row_data[0] = row_data[0].substring(1);
47
				}
48
49
				if (row_data[row_data.length-1].toString().charAt(row_data[row_data.length - 1].length - 1) === '"') {
50
					row_data[row_data.length - 1] = row_data[row_data.length -1].substring(0, row_data[row_data.length - 1].length - 1);
51
				}
52
53
				var _credential = PassmanImporter.newCredential();
54
				_credential.label = row_data[0];
55
				_credential.username = row_data[2];
56
				_credential.password = row_data[row_data.length - 2];
57
				_credential.url = row_data[0];
58
				_credential.description = row_data[row_data.length - 1];
59
				if(_credential.label){
60
					credential_list.push(_credential);
61
				}
62
63
				var progress = {
64
					percent: i/rows.length*100,
65
					loaded: i,
66
					total: rows.length
67
				};
68
				this.call_progress(progress);
69
			}
70
			this.call_then(credential_list);
71
		});
72
	};
73
})(window, $, PassmanImporter);
74