credential-form-modal.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <modal :id="id" tabindex="-1" role="dialog" :aria-labelledby="id+'Label'">
  3. <h5 slot="header" class="modal-title" :id="id+'Label'">
  4. Edit Credential
  5. </h5>
  6. <div slot="body">
  7. <div class="form-group">
  8. <label for="newusername">Username</label>
  9. <input type="text" :name="'newusername'+data.credid" :id="'newusername'+data.credid" class="form-control credential" v-model="data.creduser">
  10. </div>
  11. <div class="form-group">
  12. <label for="newpassword">Password</label>
  13. <input type="text" :name="'newpassword'+data.credid" :id="'newpassword'+data.credid" class="form-control credential" v-model="data.credpass">
  14. <button type="button" class="btn btn-secondary" @click="getRandomPassword(data.credid)">Generate Random</button>
  15. </div>
  16. <div class="form-group"></div>
  17. </div>
  18. <div slot="footer">
  19. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  20. <button type="button" class="btn btn-primary" @click="updateCredential()">Save</button>
  21. </div>
  22. </modal>
  23. </template>
  24. <script>
  25. export default {
  26. props: ['populateWith', 'modalId'],
  27. data() {
  28. return {
  29. data: JSON.parse(JSON.stringify(this.populateWith)),
  30. id: this.modalId,
  31. errors: []
  32. }
  33. },
  34. methods: {
  35. rndStr(len) {
  36. let text = ""
  37. let chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%"
  38. for( let i=0; i < len; i++ ) {
  39. text += chars.charAt(Math.floor(Math.random() * chars.length))
  40. }
  41. return text
  42. },
  43. getRandomPassword(id) {
  44. this.data.credpass = this.rndStr(16);
  45. },
  46. updateCredential() {
  47. axios.put('/api/credentials/' + this.data.credid, this.data).then(response => {}).catch(error =>{console.error(error)});
  48. $('#credential'+this.data.credid+'editModal').modal('hide');
  49. }
  50. }
  51. }
  52. </script>