rohit.gowda 4 years ago
parent
commit
83548b2bf3
1 changed files with 21 additions and 4 deletions
  1. 21 4
      app/src/pages/settings/settings.ts

+ 21 - 4
app/src/pages/settings/settings.ts

@@ -22,7 +22,8 @@ export class SettingsPage {
   revocationCertificate:string;
   email: string;
   keyid;
-
+  userId;
+  email1: string;
   constructor(
     public navCtrl: NavController,
     public toastCtrl: ToastController,
@@ -34,9 +35,20 @@ export class SettingsPage {
     private openpgp: PgpKeyServerProvider,
     private gun: P2pDatabaseGunProvider,
   ) {
+    this.init();
     this.loadValuesFromStorage();
 
   }
+  private async init() {
+    this.userId = await this.storage.get("userId");
+    console.log("email of teh user is FIRST ONE", this.email);
+    if(!this.email){
+    const email = await this.gun.getEmail(this.userId);
+    this.email1 = email.email;
+    console.log("email of the user is", this.email1);
+       await this.storage.set("email", this.email1);
+    }
+  }
 
   async loadValuesFromStorage() {
     this.privateKey = await this.storage.get("privateKey");
@@ -97,12 +109,17 @@ export class SettingsPage {
     await this.openpgp.publishPubKey(this.publicKey);
     this.showToast("Publc key published");
 
-    const userId = await this.storage.get("userId");
-    await this.gun.setEmail(userId, this.email);
+   
+    await this.gun.setEmail(this.userId, this.email);
     //test if stored in gun
-    const email = await this.gun.getEmail(userId);
+    const email = await this.gun.getEmail(this.userId);
   }
 
+  // async publishPrivateKey() {
+  //   console.log("publishing pvt key");
+  //   await this.cryptoUtils.publishPrivateKey(this.privateKey);
+  // }
+
   exportPrivateKey() {
     if (this.privateKey.length) {
       this.sharing