Skip to content

Commit d096ff1

Browse files
committed
Apply minor cleanup, mostly on indentation
1 parent 9c4bd7d commit d096ff1

File tree

2 files changed

+155
-158
lines changed

2 files changed

+155
-158
lines changed

backend/globaleaks/handlers/user.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ def get(self):
168168

169169
self.write(user_status)
170170

171-
172171
@BaseHandler.authenticated('*')
173172
@inlineCallbacks
174173
def put(self):

client/app/js/directives.js

Lines changed: 155 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -86,186 +86,184 @@ angular.module('GLDirectives', ['GLBrowserCrypto']).
8686
}
8787
};
8888
}).
89-
directive('zxPasswordMeter', function() {
90-
return {
91-
scope: {
92-
value: "="
93-
},
94-
templateUrl: "views/partials/password_meter.html",
95-
link: function(scope) {
96-
scope.type = null;
97-
scope.text = '';
89+
directive('zxPasswordMeter', function() {
90+
return {
91+
scope: {
92+
value: "="
93+
},
94+
templateUrl: "views/partials/password_meter.html",
95+
link: function(scope) {
96+
scope.type = null;
97+
scope.text = '';
9898

99-
scope.$watch('value', function(newValue) {
100-
if (newValue === undefined) {
101-
return;
102-
}
99+
scope.$watch('value', function(newValue) {
100+
if (newValue === undefined) {
101+
return;
102+
}
103103

104-
if (newValue.password === 'undefined') { // <- intentionally as string
105-
// Short term fix for:
106-
// https://github.com/ghostbar/angular-zxcvbn/issues/13
107-
newValue.password = '';
108-
}
104+
if (newValue.password === 'undefined') { // <- intentionally as string
105+
// Short term fix for:
106+
// https://github.com/ghostbar/angular-zxcvbn/issues/13
107+
newValue.password = '';
108+
}
109109

110-
if (newValue.password === '') {
111-
scope.type = null;
112-
scope.text = '';
113-
} else if (newValue.score < 3) {
114-
newValue.score = 1;
115-
scope.type = 'danger';
116-
scope.text = 'Weak';
117-
} else if (newValue.score < 4) {
118-
// guesses needed >= 10^8, <= 10^10
119-
scope.type = 'warning';
120-
scope.text = 'Acceptable';
121-
} else {
122-
// guesses needed >= 10^10
123-
scope.type = 'success';
124-
scope.text = 'Strong';
125-
}
126-
});
127-
}
128-
};
110+
if (newValue.password === '') {
111+
scope.type = null;
112+
scope.text = '';
113+
} else if (newValue.score < 3) {
114+
newValue.score = 1;
115+
scope.type = 'danger';
116+
scope.text = 'Weak';
117+
} else if (newValue.score < 4) {
118+
// guesses needed >= 10^8, <= 10^10
119+
scope.type = 'warning';
120+
scope.text = 'Acceptable';
121+
} else {
122+
// guesses needed >= 10^10
123+
scope.type = 'success';
124+
scope.text = 'Strong';
125+
}
126+
});
127+
}
128+
};
129129
}).
130-
directive('imageUpload', function () {
131-
return {
132-
restrict: 'A',
133-
scope: {
134-
imageUploadModel: '=',
135-
imageUploadModelAttr: '@',
136-
imageUploadUrl: '@'
137-
},
138-
templateUrl: 'views/partials/image_upload.html',
139-
controller: 'ImageUploadCtrl'
140-
};
130+
directive('imageUpload', function () {
131+
return {
132+
restrict: 'A',
133+
scope: {
134+
imageUploadModel: '=',
135+
imageUploadModelAttr: '@',
136+
imageUploadUrl: '@'
137+
},
138+
templateUrl: 'views/partials/image_upload.html',
139+
controller: 'ImageUploadCtrl'
140+
};
141141
}).
142+
// pgpPubKeyDisplay displays the important details from a public key.
143+
directive('pgpPubkeyDisplay', ['glbcKeyLib', function(glbcKeyLib) {
144+
// Create object that displays relevant key details to the user. This function
145+
// returns fingerprint, key id, creation date, and expiration date. If the parse
146+
// fails the function returns undefined.
147+
function pgpKeyDetails(armoredText) {
148+
// Catch the obivous errors and save time!
149+
if (typeof armoredText !== 'string' || !armoredText.startsWith('---')) {
150+
return;
151+
}
142152

143-
// pgpPubKeyDisplay displays the important details from a public key.
144-
directive('pgpPubkeyDisplay', ['glbcKeyLib', function(glbcKeyLib) {
145-
// Create object that displays relevant key details to the user. This function
146-
// returns fingerprint, key id, creation date, and expiration date. If the parse
147-
// fails the function returns undefined.
148-
function pgpKeyDetails(armoredText) {
149-
// Catch the obivous errors and save time!
150-
if (typeof armoredText !== 'string' || !armoredText.startsWith('---')) {
151-
return;
152-
}
153-
154-
var res = openpgp.key.readArmored(armoredText);
153+
var res = openpgp.key.readArmored(armoredText);
155154

156-
if (angular.isDefined(res.err)) {
157-
// There were errors. Bail out.
158-
return;
159-
}
155+
if (angular.isDefined(res.err)) {
156+
// There were errors. Bail out.
157+
return;
158+
}
160159

161-
var key = res.keys[0];
162-
163-
var niceprint = niceFingerPrint(key.primaryKey.fingerprint);
164-
var uids = extractAllUids(key);
165-
var created = key.primaryKey.created;
166-
167-
return {
168-
user_info: uids,
169-
fingerprint: niceprint,
170-
created: created,
171-
expiration: key.getExpirationTime(),
172-
};
173-
}
174-
175-
// niceFingerPrint produces the full key fingerprint in the standard
176-
// 160 bit format. See: https://tools.ietf.org/html/rfc4880#section-12.2
177-
function niceFingerPrint(print) {
178-
if (typeof print !== 'string' && print.length !== 40) {
179-
// Do nothing, the passed params are strange.
180-
return print;
181-
}
160+
var key = res.keys[0];
182161

183-
print = print.toUpperCase();
162+
var niceprint = niceFingerPrint(key.primaryKey.fingerprint);
163+
var uids = extractAllUids(key);
164+
var created = key.primaryKey.created;
184165

185-
var nice = print[0];
186-
for (var i = 1; i < 40; i++) {
187-
// Insert a space every 4th octet
188-
if (i % 4 === 0) {
189-
nice += " ";
190-
}
191-
if (i % 20 === 0) {
192-
nice += " ";
193-
}
194-
nice += print[i];
166+
return {
167+
user_info: uids,
168+
fingerprint: niceprint,
169+
created: created,
170+
expiration: key.getExpirationTime(),
171+
};
195172
}
196173

197-
return nice;
198-
}
199-
200-
// Returns all of the userId's found in the list of uids attached to the key.
201-
function extractAllUids(key) {
202-
var uids = [];
203-
key.users.forEach(function(user) {
204-
uids.push(user.userId.userid);
205-
});
206-
return uids;
207-
}
174+
// niceFingerPrint produces the full key fingerprint in the standard
175+
// 160 bit format. See: https://tools.ietf.org/html/rfc4880#section-12.2
176+
function niceFingerPrint(print) {
177+
if (typeof print !== 'string' && print.length !== 40) {
178+
// Do nothing, the passed params are strange.
179+
return print;
180+
}
208181

209-
return {
210-
restrict: 'A',
211-
templateUrl: 'views/partials/pubkey_display.html',
212-
scope: {
213-
keyStr: '=keyStr',
182+
print = print.toUpperCase();
214183

215-
},
216-
controller: ['$scope', function($scope) {
217-
$scope.$watch('keyStr', function(newVal, oldVal) {
218-
if (newVal === "") {
219-
return;
184+
var nice = print[0];
185+
for (var i = 1; i < 40; i++) {
186+
// Insert a space every 4th octet
187+
if (i % 4 === 0) {
188+
nice += " ";
220189
}
221-
$scope.is_valid_key = glbcKeyLib.validPublicKey(newVal);
222-
if ($scope.is_valid_key) {
223-
$scope.key_details = pgpKeyDetails(newVal);
190+
if (i % 20 === 0) {
191+
nice += " ";
224192
}
193+
nice += print[i];
194+
}
195+
196+
return nice;
197+
}
198+
199+
// Returns all of the userId's found in the list of uids attached to the key.
200+
function extractAllUids(key) {
201+
var uids = [];
202+
key.users.forEach(function(user) {
203+
uids.push(user.userId.userid);
225204
});
226-
}]};
205+
return uids;
206+
}
207+
208+
return {
209+
restrict: 'A',
210+
templateUrl: 'views/partials/pubkey_display.html',
211+
scope: {
212+
keyStr: '=keyStr',
213+
214+
},
215+
controller: ['$scope', function($scope) {
216+
$scope.$watch('keyStr', function(newVal, oldVal) {
217+
if (newVal === "") {
218+
return;
219+
}
220+
$scope.is_valid_key = glbcKeyLib.validPublicKey(newVal);
221+
if ($scope.is_valid_key) {
222+
$scope.key_details = pgpKeyDetails(newVal);
223+
}
224+
});
225+
}]};
227226
}]).
227+
// pgpPubkeyValidator binds to text-areas to provide input validation on user
228+
// input GPG public keys. Note that the directive attaches itself to the
229+
// containing form's ngModelController NOT the ngModel bound to the value of the
230+
// text-area itself. If the key word 'canBeEmpty' the pgp key validator is disabled
231+
// when the textarea's input is empty.
232+
directive('pgpPubkeyValidator', ['glbcKeyLib', function(glbcKeyLib) {
233+
// scope is the directives scope
234+
// elem is a jqlite reference to the bound element
235+
// attrs is the list of directives on the element
236+
// ngModel is the model controller attached to the form
237+
function link(scope, elem, attrs, ngModel){
228238

229-
// pgpPubkeyValidator binds to text-areas to provide input validation on user
230-
// input GPG public keys. Note that the directive attaches itself to the
231-
// containing form's ngModelController NOT the ngModel bound to the value of the
232-
// text-area itself. If the key word 'canBeEmpty' the pgp key validator is disabled
233-
// when the textarea's input is empty.
234-
directive('pgpPubkeyValidator', ['glbcKeyLib', function(glbcKeyLib) {
235-
// scope is the directives scope
236-
// elem is a jqlite reference to the bound element
237-
// attrs is the list of directives on the element
238-
// ngModel is the model controller attached to the form
239-
function link(scope, elem, attrs, ngModel){
239+
scope.canBeEmpty = false;
240+
if (scope.pgpPubkeyValidator === 'canBeEmpty') {
241+
scope.canBeEmpty = true;
242+
}
240243

241-
scope.canBeEmpty = false;
242-
if (scope.pgpPubkeyValidator === 'canBeEmpty') {
243-
scope.canBeEmpty = true;
244-
}
244+
// modelValue is the models value, viewVal is displayed on the page.
245+
ngModel.$validators.pgpPubKeyValidator = function(modelVal, viewVal) {
245246

246-
// modelValue is the models value, viewVal is displayed on the page.
247-
ngModel.$validators.pgpPubKeyValidator = function(modelVal, viewVal) {
247+
// Check for obvious problems.
248+
if (typeof modelVal !== 'string') {
249+
modelVal = '';
250+
}
248251

249-
// Check for obvious problems.
250-
if (typeof modelVal !== 'string') {
251-
modelVal = '';
252-
}
252+
if (scope.canBeEmpty && modelVal === '') {
253+
return true;
254+
}
253255

254-
if (scope.canBeEmpty && modelVal === '') {
255-
return true;
256+
return glbcKeyLib.validPublicKey(modelVal);
257+
};
258+
}
259+
// Return a Directive Definition Object for angular to compile
260+
return {
261+
restrict: 'A',
262+
require: 'ngModel',
263+
link: link,
264+
scope: {
265+
// The string passed to the directive is used to assign special key word behavior.
266+
pgpPubkeyValidator: '@',
256267
}
257-
258-
return glbcKeyLib.validPublicKey(modelVal);
259268
};
260-
}
261-
// Return a Directive Definition Object for angular to compile
262-
return {
263-
restrict: 'A',
264-
require: 'ngModel',
265-
link: link,
266-
scope: {
267-
// The string passed to the directive is used to assign special key word behavior.
268-
pgpPubkeyValidator: '@',
269-
}
270-
};
271269
}]);

0 commit comments

Comments
 (0)