Browse Source

store user email addresss in gundb on key publish

rohit.gowda 4 years ago
parent
commit
8f9a0679d3

+ 11 - 1
app/src/pages/settings/settings.ts

@@ -8,6 +8,7 @@ import {
 import { Storage } from "@ionic/storage";
 import { CryptoProvider } from "../../providers/crypto/crypto";
 import { SocialSharing } from "@ionic-native/social-sharing";
+import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
 import { PgpKeyServerProvider } from "../../providers/pgp-key-server/pgp-key-server";
 
 @Component({
@@ -30,7 +31,8 @@ export class SettingsPage {
     private loadingCtrl: LoadingController,
     private sharing: SocialSharing,
     private alertCtrl: AlertController,
-    private openpgp: PgpKeyServerProvider
+    private openpgp: PgpKeyServerProvider,
+    private gun: P2pDatabaseGunProvider,
   ) {
     this.loadValuesFromStorage();
 
@@ -95,12 +97,20 @@ export class SettingsPage {
     this.storage.set("revocationCert", this.revocationCertificate);
     this.storage.set("keywords", this.keywords ? this.keywords.trim() : "");
 
+    
     this.showToast("Successfully saved!");
   }
 
   async publishPublicKey() {
     await this.openpgp.publishPubKey(this.publicKey);
     this.showToast("Publc key published");
+
+    const userId = await this.storage.get("userId");
+    console.log("userid is:",userId);
+    await this.gun.setEmail(userId, this.email);
+    //test if stored in gun
+    const email = await this.gun.getEmail(userId);
+    console.log("email:",email);
   }
 
   exportPrivateKey() {

+ 34 - 0
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -127,4 +127,38 @@ export class P2pDatabaseGunProvider {
       return likeEntry;
     }
   }
+
+  public async setEmail(userId,email){
+     const emailadd = this.gun.get(userId).put({
+      email: email
+    });
+
+    this.gun
+      .get(this.osnPrefix)
+      .get("email")
+      .set(emailadd);
+
+  }
+
+   public async getEmail(userId){
+    let entry = await this.gun
+      .get(this.osnPrefix)
+      .get("email");
+    console.log("get the email entry from gun :",entry);
+    const emailEntry = await this.gun
+      .get(this.osnPrefix)
+      .get("email")
+      .get(userId)
+      .then();
+
+      if (emailEntry === undefined) {
+      return null;
+    } else {
+      return emailEntry;
+    }
+  }
+
+
+
+  
 }