1
0
Fork 0
forked from lthn/blockchain

Some fixes with masterpassword and new Reset button (#48)

* added new password-functional

* small fixes:
This commit is contained in:
DrGurin 2019-07-26 17:26:08 +03:00 committed by cryptozoidberg
parent 18b7dbd132
commit 4abc9b9f31
8 changed files with 140 additions and 89 deletions

View file

@ -305,6 +305,13 @@ export class BackendService {
this.runCommand('get_secure_app_data', pass, callback);
}
setMasterPassword(pass, callback) {
this.runCommand('set_master_password', pass, callback);
}
checkMasterPassword(pass, callback) {
this.runCommand('check_master_password', pass, callback);
}
storeSecureAppData(callback?) {
const wallets = [];
this.variablesService.wallets.forEach((wallet) => {

View file

@ -50,6 +50,7 @@ export class VariablesService {
public enableAliasSearch = false;
public maxWalletNameLength = 25;
public maxCommentLength = 255;
public dataIsLoaded = false;
getExpMedTsEvent = new BehaviorSubject(null);
getHeightAppEvent = new BehaviorSubject(null);

View file

@ -9,7 +9,6 @@
<span class="loading-bar"></span>
</div>
</div>
<context-menu #allContextMenu>
<ng-template contextMenuItem (execute)="contextMenuCopy($event.item)">{{ 'CONTEXT_MENU.COPY' | translate }}</ng-template>
<ng-template contextMenuItem (execute)="contextMenuPaste($event.item)">{{ 'CONTEXT_MENU.PASTE' | translate }}</ng-template>

View file

@ -35,10 +35,13 @@
<input type="password" id="master-pass-login" formControlName="password" autofocus (contextmenu)="variablesService.onContextMenuPasteSelect($event)">
</div>
<button type="submit" class="blue-button">{{ 'LOGIN.BUTTON_NEXT' | translate }}</button>
<div class="wrap-button">
<button type="submit" class="blue-button">{{ 'LOGIN.BUTTON_NEXT' | translate }}</button>
<button type="button" class="blue-button_reset" (click)="dropSecureAppData()">{{ 'LOGIN.BUTTON_RESET' | translate }}</button> <!--Add "Reset"-button-->
</div>
</form>
</div>
</div>
</div>

View file

@ -26,7 +26,7 @@ export class LoginComponent implements OnInit, OnDestroy {
password: new FormControl('')
});
type = 'reg';
type = 'reg';
constructor(
private route: ActivatedRoute,
@ -47,10 +47,13 @@ export class LoginComponent implements OnInit, OnDestroy {
onSubmitCreatePass(): void {
if (this.regForm.valid) {
this.variablesService.appPass = this.regForm.get('password').value;
this.backend.storeSecureAppData((status, data) => {
this.variablesService.appPass = this.regForm.get('password').value //the pass what was written in input of login form by user
this.backend.setMasterPassword({pass: this.variablesService.appPass}, (status, data) => {
if (status) {
this.backend.storeSecureAppData({pass: this.variablesService.appPass});
this.variablesService.appLogin = true;
this.variablesService.dataIsLoaded = true;
this.variablesService.startCountdown();
this.ngZone.run(() => {
this.router.navigate(['/']);
@ -58,7 +61,8 @@ export class LoginComponent implements OnInit, OnDestroy {
} else {
console.log(data['error_code']);
}
});
})
}
}
@ -70,91 +74,115 @@ export class LoginComponent implements OnInit, OnDestroy {
});
}
dropSecureAppData(): void{
this.backend.dropSecureAppData(() => {
this.onSkipCreatePass();
});
}
onSubmitAuthPass(): void {
if (this.authForm.valid) {
const appPass = this.authForm.get('password').value;
this.backend.getSecureAppData({pass: appPass}, (status, data) => {
if (!data.error_code) {
this.variablesService.appLogin = true;
this.variablesService.startCountdown();
this.variablesService.appPass = appPass;
if (this.variablesService.wallets.length) {
this.ngZone.run(() => {
this.router.navigate(['/wallet/' + this.variablesService.wallets[0].wallet_id]);
});
return;
}
if (Object.keys(data).length !== 0) {
let openWallets = 0;
let runWallets = 0;
data.forEach((wallet, wallet_index) => {
this.backend.openWallet(wallet.path, wallet.pass, true, (open_status, open_data, open_error) => {
if (open_status || open_error === 'FILE_RESTORED') {
openWallets++;
this.ngZone.run(() => {
const new_wallet = new Wallet(
open_data.wallet_id,
wallet.name,
wallet.pass,
open_data['wi'].path,
open_data['wi'].address,
open_data['wi'].balance,
open_data['wi'].unlocked_balance,
open_data['wi'].mined_total,
open_data['wi'].tracking_hey
);
new_wallet.alias = this.backend.getWalletAlias(new_wallet.address);
if (wallet.staking) {
new_wallet.staking = true;
this.backend.startPosMining(new_wallet.wallet_id);
} else {
new_wallet.staking = false;
}
if (open_data.recent_history && open_data.recent_history.history) {
new_wallet.prepareHistory(open_data.recent_history.history);
}
this.backend.getContracts(open_data.wallet_id, (contracts_status, contracts_data) => {
if (contracts_status && contracts_data.hasOwnProperty('contracts')) {
this.ngZone.run(() => {
new_wallet.prepareContractsAfterOpen(contracts_data.contracts, this.variablesService.exp_med_ts, this.variablesService.height_app, this.variablesService.settings.viewedContracts, this.variablesService.settings.notViewedContracts);
});
}
});
this.variablesService.wallets.push(new_wallet);
if (this.variablesService.wallets.length === 1) {
this.router.navigate(['/wallet/' + this.variablesService.wallets[0].wallet_id]);
}
});
this.backend.runWallet(open_data.wallet_id, (run_status) => {
if (run_status) {
runWallets++;
} else {
if (wallet_index === data.length - 1 && runWallets === 0) {
this.ngZone.run(() => {
this.router.navigate(['/']);
});
}
}
});
} else {
if (wallet_index === data.length - 1 && openWallets === 0) {
this.ngZone.run(() => {
this.router.navigate(['/']);
});
}
}
this.variablesService.appPass = this.authForm.get('password').value;
if (this.variablesService.dataIsLoaded) {
this.backend.checkMasterPassword({pass: this.variablesService.appPass}, (status, data) => {
if (status) {
this.variablesService.appLogin = true;
this.variablesService.startCountdown();
this.ngZone.run(() => {
this.router.navigate(['/']);
});
});
} else {
this.ngZone.run(() => {
this.router.navigate(['/']);
});
}
}
});
}
})
} else {
this.getWalletData(this.variablesService.appPass)
}
}
}
getWalletData(appPass) {
this.backend.getSecureAppData({pass: appPass}, (status, data) => {
if (!data.error_code) {
this.variablesService.appLogin = true;
this.variablesService.dataIsLoaded = true;
this.variablesService.startCountdown();
this.variablesService.appPass = appPass;
if (this.variablesService.wallets.length) {
this.ngZone.run(() => {
this.router.navigate(['/wallet/' + this.variablesService.wallets[0].wallet_id]);
});
return;
}
if (Object.keys(data).length !== 0) {
let openWallets = 0;
let runWallets = 0;
data.forEach((wallet, wallet_index) => {
this.backend.openWallet(wallet.path, wallet.pass, true, (open_status, open_data, open_error) => {
if (open_status || open_error === 'FILE_RESTORED') {
openWallets++;
this.ngZone.run(() => {
const new_wallet = new Wallet(
open_data.wallet_id,
wallet.name,
wallet.pass,
open_data['wi'].path,
open_data['wi'].address,
open_data['wi'].balance,
open_data['wi'].unlocked_balance,
open_data['wi'].mined_total,
open_data['wi'].tracking_hey
);
new_wallet.alias = this.backend.getWalletAlias(new_wallet.address);
if (wallet.staking) {
new_wallet.staking = true;
this.backend.startPosMining(new_wallet.wallet_id);
} else {
new_wallet.staking = false;
}
if (open_data.recent_history && open_data.recent_history.history) {
new_wallet.prepareHistory(open_data.recent_history.history);
}
this.backend.getContracts(open_data.wallet_id, (contracts_status, contracts_data) => {
if (contracts_status && contracts_data.hasOwnProperty('contracts')) {
this.ngZone.run(() => {
new_wallet.prepareContractsAfterOpen(contracts_data.contracts, this.variablesService.exp_med_ts, this.variablesService.height_app, this.variablesService.settings.viewedContracts, this.variablesService.settings.notViewedContracts);
});
}
});
this.variablesService.wallets.push(new_wallet);
if (this.variablesService.wallets.length === 1) {
this.router.navigate(['/wallet/' + this.variablesService.wallets[0].wallet_id]);
}
});
this.backend.runWallet(open_data.wallet_id, (run_status) => {
if (run_status) {
runWallets++;
} else {
if (wallet_index === data.length - 1 && runWallets === 0) {
this.ngZone.run(() => {
this.router.navigate(['/']);
});
}
}
});
} else {
if (wallet_index === data.length - 1 && openWallets === 0) {
this.ngZone.run(() => {
this.router.navigate(['/']);
});
}
}
});
});
} else {
this.ngZone.run(() => {
this.router.navigate(['/']);
});
}
}
});
}
ngOnDestroy() {
this.queryRouting.unsubscribe();

View file

@ -72,6 +72,7 @@ export class SettingsComponent implements OnInit {
];
currentBuild = '';
appPass: any;
constructor(
private renderer: Renderer2,
@ -123,14 +124,24 @@ export class SettingsComponent implements OnInit {
if (this.changeForm.valid) {
this.variablesService.appPass = this.changeForm.get('new_password').value;
if (this.variablesService.appPass) {
this.backend.storeSecureAppData();
this.backend.setMasterPassword({pass: this.variablesService.appPass}, (status, data) => {
if (status) {
this.backend.storeSecureAppData({pass: this.variablesService.appPass});
this.variablesService.appLogin = true;
this.variablesService.dataIsLoaded = true;
this.variablesService.startCountdown();
} else {
console.log(data['error_code']);
}
})
} else {
this.backend.dropSecureAppData();
}
this.changeForm.reset();
}
}
onLockChange() {
if (this.variablesService.appLogin) {
this.variablesService.restartCountdown();

View file

@ -5,6 +5,7 @@
"MASTER_PASS": "Master password",
"BUTTON_NEXT": "Next",
"BUTTON_SKIP": "Skip",
"BUTTON_RESET": "Reset",
"INCORRECT_PASSWORD": "Invalid password",
"FORM_ERRORS": {
"PASS_REQUIRED": "Password is required",

View file

@ -20,7 +20,8 @@ button {
padding: 0 1rem;
height: 4.2rem;
&:disabled:not(.transparent-button) {
&:disabled:not(.transparent-button),
&.blue-button_reset{
@include themify($themes) {
background-color: themed(disabledButtonBackgroundColor);