Card.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div>
  3. <h1>Card from Contacts</h1>
  4. <div v-if="fingerprint">
  5. <p>{{fingerprint}}</p>
  6. <div v-for="(card, index) in contactsCards" v-bind:key="index">
  7. <div v-if="card.fingerprint.replace(/[: ]/gi,'') === fingerprint.replace(/[: ]/gi,'')">
  8. <BusinessCard :card="card"/>
  9. <TextEncrypter :rsaPubKey="getPubKey(fingerprint)"/>
  10. <p>
  11. <pre>{{JSON.stringify(card, null, 1)}}</pre>
  12. </p>
  13. <p><button v-on:click="toggleLock()">Click to toggle lock</button></p>
  14. <div v-if="!locked">
  15. <p><strong>WARNING&#58;</strong>
  16. This will remove the card if you click the button below.</p>
  17. <button v-on:click="rmCard(index)" class="danger">Remove Card</button>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <div v-else>
  23. <p>No fingerprint.</p>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import {mapState, mapGetters, mapMutations, mapActions} from "vuex"
  29. import BusinessCard from '@/components/BusinessCard.vue'
  30. import TextEncrypter from '@/components/TextEncrypter.vue'
  31. export default {
  32. name: "Card",
  33. components: {
  34. BusinessCard,
  35. TextEncrypter
  36. },
  37. data() {
  38. return {
  39. locked: true
  40. }
  41. },
  42. props: ["fingerprint"],
  43. computed: {
  44. ...mapState([
  45. "contactsCards"
  46. ]),
  47. ...mapGetters([
  48. "getCardFromFingerprint"
  49. ])
  50. },
  51. methods: {
  52. ...mapGetters({
  53. keyPair: "getKeyFromFingerprint"
  54. }),
  55. ...mapMutations([
  56. "rmContactsCard",
  57. ]),
  58. ...mapActions({
  59. rmCard: "rmCard",
  60. }),
  61. getPubKey: function(fingerprint) {
  62. const keyPairs = this.keyPair()(fingerprint)
  63. return (keyPairs.length > 0) ? keyPairs[0].pubKey : undefined
  64. },
  65. toggleLock: function() {
  66. this.locked = !this.locked
  67. },
  68. getAvatar: function(email) {
  69. let hexval = this.getHash(email);
  70. return `https://www.libravatar.org/avatar/${hexval}?s=80`;
  71. },
  72. getHash: function(text) {
  73. try {
  74. const crypto = require('crypto');
  75. const hash = crypto.createHash('sha256')
  76. .update(text)
  77. .digest('hex');
  78. return hash;
  79. } catch (err) {
  80. console.log('crypto support is disabled!');
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. </style>