Skip to content

Commit aa71887

Browse files
Saby-BishopsMutugiiidogi
authored
manager: smoother server pin changing (fixes #9217) (#9236)
Co-authored-by: mutugiii <[email protected]> Co-authored-by: dogi <[email protected]>
1 parent d314979 commit aa71887

File tree

5 files changed

+50
-20
lines changed

5 files changed

+50
-20
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.64",
4+
"version": "0.20.65",
55
"myplanet": {
6-
"latest": "v0.36.37",
7-
"min": "v0.35.37"
6+
"latest": "v0.36.44",
7+
"min": "v0.35.44"
88
},
99
"scripts": {
1010
"ng": "ng",

src/app/manager-dashboard/manager-dashboard.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h3 i18n *ngIf="showParentList">{{ planetType === 'community' ? 'Nation' : 'Cent
7777
</ng-container>
7878
</div>
7979
<div *ngIf="pin"><span i18n>myPlanet Server pin:</span> <b class="pinClass">{{ ' ' + pin + ' ' }}</b>
80-
<button mat-raised-button i18n (click)="resetPin()">Reset Pin</button>
80+
<button mat-raised-button i18n (click)="confirmResetPin()">Reset Pin</button>
8181
</div>
8282
</ng-container>
8383
<div>

src/app/manager-dashboard/manager-dashboard.component.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class ManagerDashboardComponent implements OnInit, OnDestroy {
3636
versionLatestApk = '';
3737
versionLocalApk = '';
3838
dialogRef: MatDialogRef<DialogsListComponent>;
39+
resetPinDialog: MatDialogRef<DialogsPromptComponent>;
3940
pin: string;
4041
activityLogs: any = {};
4142
private onDestroy$ = new Subject<void>();
@@ -248,22 +249,39 @@ export class ManagerDashboardComponent implements OnInit, OnDestroy {
248249
}
249250
}
250251

251-
resetPin() {
252-
const userName = 'org.couchdb.user:satellite';
253-
this.couchService.get('_users/' + userName)
254-
.pipe(switchMap((data) => {
255-
const { derived_key, iterations, password_scheme, salt, ...satelliteProfile } = data;
256-
satelliteProfile.password = this.managerService.createPin();
257-
return forkJoin([
258-
this.couchService.put('_users/' + userName, satelliteProfile),
259-
this.couchService.put('_node/nonode@nohost/_config/satellite/pin', satelliteProfile.password)
260-
]);
261-
})).subscribe((res) => {
262-
this.getSatellitePin();
263-
this.planetMessageService.showMessage($localize`Pin reset successfully`);
264-
}, (error) => this.planetMessageService.showAlert($localize`Error to reset pin`));
252+
confirmResetPin() {
253+
this.resetPinDialog = this.dialog.open(DialogsPromptComponent, {
254+
data: {
255+
type: 'pin',
256+
changeType: 'reset',
257+
okClick: {
258+
request: this.resetPin(),
259+
onNext: () => {
260+
this.resetPinDialog.close();
261+
this.getSatellitePin();
262+
this.planetMessageService.showMessage($localize`PIN reset successfully`);
263+
},
264+
onError: () => this.planetMessageService.showAlert($localize`There was an error resetting the PIN`)
265+
}
266+
}
267+
});
265268
}
266269

270+
resetPin() {
271+
const userName = 'org.couchdb.user:satellite';
272+
return this.couchService.get('_users/' + userName)
273+
.pipe(
274+
switchMap((data) => {
275+
const { derived_key, iterations, password_scheme, salt, ...satelliteProfile } = data;
276+
satelliteProfile.password = this.managerService.createPin();
277+
return forkJoin([
278+
this.couchService.put('_users/' + userName, satelliteProfile),
279+
this.couchService.put('_node/nonode@nohost/_config/satellite/pin', satelliteProfile.password)
280+
]);
281+
})
282+
);
283+
}
284+
267285
setVersions() {
268286
const opts = { responseType: 'text', withCredentials: false, headers: { 'Content-Type': 'text/plain' } };
269287
this.managerService.getVersion('planet', opts).subscribe((version: string) => this.versionLocal = version);

src/app/manager-dashboard/manager.service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,18 @@ export class ManagerService {
5858
}
5959

6060
createPin() {
61-
return Array(4).fill(0).map(() => Math.floor(Math.random() * 10)).join('');
61+
// Use window.crypto.getRandomValues for cryptographically secure random digits
62+
const pinArray = new Uint8Array(4);
63+
window.crypto.getRandomValues(pinArray);
64+
// Map random bytes to digits 0-9 without modulo bias
65+
return Array.from(pinArray, byte => {
66+
// Discard and retry if value is > 249 to prevent modulo bias
67+
let digit = byte;
68+
while (digit > 249) {
69+
digit = window.crypto.getRandomValues(new Uint8Array(1))[0];
70+
}
71+
return (digit % 10).toString();
72+
}).join('');
6273
}
6374

6475
getChildPlanets(onlyAccepted = false, parentCode = this.stateService.configuration.code, domain?) {

src/app/shared/dialogs/dialogs-prompt.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<mat-dialog-content>
22
<b *ngIf="data.type === 'changes'" i18n>You have unsaved changes.</b>
33
<p *ngIf="showMainParagraph" i18n>
4-
Are you sure you want to {data.changeType, select, accept {accept} archive {archive} reject {reject} delete {delete} leave {leave} remove {remove} leader {give leadership to} exit {leave}}
4+
Are you sure you want to {data.changeType, select, accept {accept} archive {archive} reject {reject} delete {delete} leave {leave} remove {remove} leader {give leadership to} exit {leave} reset {reset}}
55
the {data.amount, select, single
66
{following {data.type, select,
77
community {community}
@@ -22,6 +22,7 @@
2222
news {message}
2323
report {report}
2424
changes {form}
25+
pin {pin}
2526
survey {survey}}?
2627
}
2728
many

0 commit comments

Comments
 (0)