Commit ba11de86 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Merge pull request #68 from stratisproject/ui

Add basic validation to login and recovery components
parents 1ef99821 2c54be78
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<div class="form-group"> <div class="form-group">
<label>Your password: </label> <label>Your password: </label>
<input class="form-control" type="password" formControlName="password" placeholder="Enter password here"> <input class="form-control" type="password" formControlName="password" placeholder="Enter password here">
<div *ngIf="formErrors.password" class="alert alert-danger">{{formErrors.password}}</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<button type="submit" [disabled]="!openWalletForm.valid" class="btn btn-success">Decrypt</button> <button type="submit" [disabled]="!openWalletForm.valid" class="btn btn-success">Decrypt</button>
......
...@@ -13,10 +13,7 @@ import { WalletLoad } from '../shared/classes/wallet-load'; ...@@ -13,10 +13,7 @@ import { WalletLoad } from '../shared/classes/wallet-load';
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) { constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) {
this.openWalletForm = fb.group({ this.buildDecryptForm();
"selectWallet": ["", Validators.required],
"password": ["", Validators.required]
});
} }
private openWalletForm: FormGroup; private openWalletForm: FormGroup;
...@@ -27,6 +24,43 @@ export class LoginComponent implements OnInit { ...@@ -27,6 +24,43 @@ export class LoginComponent implements OnInit {
this.getWalletFiles(); this.getWalletFiles();
} }
private buildDecryptForm(): void {
this.openWalletForm = this.fb.group({
"selectWallet": ["", Validators.required],
"password": ["", Validators.required]
});
this.openWalletForm.valueChanges
.subscribe(data => this.onValueChanged(data));
this.onValueChanged();
}
onValueChanged(data?: any) {
if (!this.openWalletForm) { return; }
const form = this.openWalletForm;
for (const field in this.formErrors) {
this.formErrors[field] = '';
const control = form.get(field);
if (control && control.dirty && !control.valid) {
const messages = this.validationMessages[field];
for (const key in control.errors) {
this.formErrors[field] += messages[key] + ' ';
}
}
}
}
formErrors = {
'password': ''
};
validationMessages = {
'password': {
'required': 'Please enter your password.'
}
};
private updateWalletFileDisplay(walletName: string) { private updateWalletFileDisplay(walletName: string) {
this.openWalletForm.patchValue({selectWallet: walletName}) this.openWalletForm.patchValue({selectWallet: walletName})
} }
......
...@@ -15,14 +15,17 @@ ...@@ -15,14 +15,17 @@
<div class="form-group"> <div class="form-group">
<label>Mnemonic:</label> <label>Mnemonic:</label>
<input class="form-control" formControlName="walletMnemonic" type="text" placeholder="Enter your saved mnemonic."> <input class="form-control" formControlName="walletMnemonic" type="text" placeholder="Enter your saved mnemonic.">
<div *ngIf="formErrors.walletMnemonic" class="alert alert-danger">{{formErrors.walletMnemonic}}</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Wallet password: </label> <label>Wallet password: </label>
<input class="form-control" type="password" formControlName="walletPassword" placeholder="Enter password here."> <input class="form-control" type="password" formControlName="walletPassword" placeholder="Enter password here.">
<div *ngIf="formErrors.walletPassword" class="alert alert-danger">{{formErrors.walletPassword}}</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Name:</label> <label>Name:</label>
<input class="form-control" formControlName="walletName" type="text" placeholder="Enter a name for your wallet."> <input class="form-control" formControlName="walletName" type="text" placeholder="Enter a name for your wallet.">
<div *ngIf="formErrors.walletName" class="alert alert-danger">{{formErrors.walletName}}</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Network:</label> <label>Network:</label>
......
...@@ -15,12 +15,8 @@ import { WalletRecovery } from '../../shared/classes/wallet-recovery'; ...@@ -15,12 +15,8 @@ import { WalletRecovery } from '../../shared/classes/wallet-recovery';
export class RecoverComponent implements OnInit { export class RecoverComponent implements OnInit {
constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) { constructor(private globalService: GlobalService, private apiService: ApiService, private router: Router, private fb: FormBuilder) {
this.recoverWalletForm = fb.group({ this.buildRecoverForm();
"walletMnemonic": ["", Validators.required],
"walletPassword": ["", Validators.required],
"walletName": ["", Validators.required],
"selectNetwork": ["test", Validators.required]
});
} }
private recoverWalletForm: FormGroup; private recoverWalletForm: FormGroup;
...@@ -33,6 +29,60 @@ export class RecoverComponent implements OnInit { ...@@ -33,6 +29,60 @@ export class RecoverComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
private buildRecoverForm(): void {
this.recoverWalletForm = this.fb.group({
"walletMnemonic": ["", Validators.required],
"walletPassword": ["", Validators.required],
"walletName": ["", [
Validators.required,
Validators.minLength(3),
Validators.maxLength(24)
]
],
"selectNetwork": ["test", Validators.required]
});
this.recoverWalletForm.valueChanges
.subscribe(data => this.onValueChanged(data));
this.onValueChanged();
}
onValueChanged(data?: any) {
if (!this.recoverWalletForm) { return; }
const form = this.recoverWalletForm;
for (const field in this.formErrors) {
this.formErrors[field] = '';
const control = form.get(field);
if (control && control.dirty && !control.valid) {
const messages = this.validationMessages[field];
for (const key in control.errors) {
this.formErrors[field] += messages[key] + ' ';
}
}
}
}
formErrors = {
'walletMnemonic': '',
'walletPassword': '',
'walletName': ''
};
validationMessages = {
'walletMnemonic': {
'required': 'Please enter your 12 word phrase.'
},
'walletPassword': {
'required': 'A password is required.'
},
'walletName': {
'required': 'Name is required.',
'minlength': 'Name must be at least 3 characters long.',
'maxlength': 'Name cannot be more than 24 characters long.'
}
};
private onBackClicked() { private onBackClicked() {
this.router.navigate(["/setup"]); this.router.navigate(["/setup"]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment