Commit d7cb9abf authored by Cédric Moreau's avatar Cédric Moreau

[enh] Modification du compte via URL

parent 8d97ae9b
......@@ -43,7 +43,7 @@ const appRoutes: Routes = [
data: { creation: true }
},
{
path: 'mon_compte/modifier',
path: 'mon_compte/edit/:pub',
component: AccountPage
},
{
......
......@@ -6,6 +6,7 @@
<ion-item>
<ion-label>Identifiant secret</ion-label>
<ion-input type="password"
[disabled]="computing"
[(ngModel)]="salt"
placeholder="Tapez votre identifiant secret."></ion-input>
</ion-item>
......@@ -13,11 +14,12 @@
<ion-item>
<ion-label>Mot de passe</ion-label>
<ion-input type="password"
[disabled]="computing"
[(ngModel)]="passwd"
placeholder="Tapez votre mot de passe." ></ion-input>
</ion-item>
<ion-item [hidden]="generated">
<ion-item [hidden]="generated || salt || passwd">
<ion-label>Tapez vos identifiants secrets puis cliquer sur « Valider ».</ion-label>
</ion-item>
<ion-item [hidden]="computing || !generated || salt || passwd">
......@@ -30,6 +32,14 @@
<ion-spinner item-left></ion-spinner>
<ion-label>Vérification de la clé...</ion-label>
</ion-item>
<ion-item>
<ion-label>Mémoriser ces valeurs le temps de la navigation</ion-label>
<ion-checkbox color="royal" [(ngModel)]="remember" checked="false"></ion-checkbox>
</ion-item>
<ion-item>
<ion-label>Ne plus me demander confirmation le temps de la navigation</ion-label>
<ion-checkbox color="royal" [(ngModel)]="noConfirm" checked="false"></ion-checkbox>
</ion-item>
</ion-list>
<p>
......
import {Component} from "@angular/core";
import {Component, OnInit} from "@angular/core";
import {NavParams, ViewController} from "ionic-angular";
const scrypt = require('scrypt-async')
const tweetnacl = require('tweetnacl')
......@@ -9,21 +9,31 @@ const base58 = require('../../lib/base58')
selector: 'auth_modal',
template: require('./auth_modal.html')
})
export class AuthModal {
export class AuthModal implements OnInit {
error:string
generated:string
salt:string = ""
passwd:string = ""
keyPair:any
salt:string
passwd:string
expectedPub:string
computing:Boolean
remember:Boolean
noConfirm:Boolean
constructor(
private params: NavParams,
public viewCtrl: ViewController
) {
this.expectedPub = this.params.get('expectedPub')
this.salt = sessionStorage.getItem('salt')
this.passwd = sessionStorage.getItem('passwd')
this.remember = Boolean(sessionStorage.getItem('remember'))
this.noConfirm = Boolean(sessionStorage.getItem('noConfirm'))
}
ngOnInit(): void {
if (this.noConfirm) {
this.valideCle()
}
}
getKeyPair() {
......@@ -51,15 +61,32 @@ export class AuthModal {
.then((pair) => {
this.computing = false
this.generated = base58.encode(pair.publicKey)
const salt = this.salt, passwd = this.passwd
this.salt = ""
this.passwd = ""
if (this.expectedPub === this.generated) {
// Success auth
if (this.remember) {
sessionStorage.setItem('salt', salt)
sessionStorage.setItem('passwd', passwd)
sessionStorage.setItem('remember', "1")
} else {
sessionStorage.removeItem('salt')
sessionStorage.removeItem('passwd')
sessionStorage.removeItem('remember')
sessionStorage.removeItem('remember')
}
if (this.noConfirm) {
sessionStorage.setItem('noConfirm', "1")
} else {
sessionStorage.removeItem('noConfirm')
}
this.viewCtrl.dismiss(pair)
} else {
this.error = 'La clé générée n\'est pas celle de votre compte. Une faute de frappe ?'
}
})
}, 100)
}, 500)
}
cancel() {
......
import {Component} from "@angular/core";
import {Component, OnInit} from "@angular/core";
import {AccountService} from "../../services/account-service";
import {ActivatedRoute} from "@angular/router";
import {LoginService} from "../../services/login-service";
......@@ -7,7 +7,7 @@ import {LoginService} from "../../services/login-service";
selector: 'account',
template: require('../../app/topbar.html') + require('./account.html')
})
export class AccountPage {
export class AccountPage implements OnInit {
title:string = "Créer ou modifier mon compte"
......@@ -20,4 +20,13 @@ export class AccountPage {
accountService.beginCreation(loginService.pub)
}
}
ngOnInit() {
this.route.params.subscribe(params => {
if (params['pub']) {
return this.accountService.getAccountInfos(params['pub'])
.then(res => this.accountService.acc = res.acc)
}
});
}
}
......@@ -34,7 +34,7 @@
Ce compte est actif.
</p>
<p>
<button ion-button color="primary" routerLink="/mon_compte/modifier">Modifier le compte</button>
<button ion-button color="primary" [routerLink]="['/mon_compte/edit', loginService.pub]">Modifier le compte</button>
</p>
</ng-container>
<h2>Porte-monnaie associé</h2>
......
......@@ -24,6 +24,7 @@ export class AccountService {
private alertCtrl: AlertController,
public authService: AuthService,
) {
this.acc = {}
}
get raw() { return this.rawify(this.acc) }
......
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