Guest User

Untitled

a guest
Mar 5th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. <template>
  2. <v-container fluid>
  3. <v-progress-linear v-if="loginInProgress" v-bind:indeterminate="true"/>
  4. <v-layout xs12 column align-space-between>
  5. <v-flex>
  6. <v-form v-on:submit.prevent="login">
  7. <v-layout column>
  8. <v-flex>
  9. <v-text-field v-model="username" :label="label('User.username')" required/>
  10. </v-flex>
  11. <v-flex>
  12. <v-text-field
  13. :label="label('User.password')"
  14. v-model="password"
  15. autocomplete="off"
  16. :append-icon="showPassword ? 'visibility_off' : 'visibility'"
  17. :append-icon-cb="() => (showPassword = !showPassword)"
  18. :type="showPassword ? 'text': 'password'"
  19. required/>
  20. </v-flex>
  21. <v-flex>
  22. <v-text-field
  23. v-if="resettingPassword"
  24. :label="label('NewPassword')"
  25. v-model="newpassword"
  26. :append-icon="showPassword ? 'visibility_off' : 'visibility'"
  27. :append-icon-cb="() => (showPassword = !showPassword)"
  28. :type="showPassword ? 'text': 'password'"
  29. required/>
  30. </v-flex>
  31. <v-flex>
  32. <v-text-field
  33. v-if="resettingPassword"
  34. :label="label('NewPasswordVerify')"
  35. v-model="newpasswordverify"
  36. :append-icon="showPassword ? 'visibility_off' : 'visibility'"
  37. :append-icon-cb="() => (showPassword = !showPassword)"
  38. :type="showPassword ? 'text': 'password'"
  39. required/>
  40. </v-flex>
  41. <v-flex>
  42. <v-select :items="sites"
  43. v-model="selectedSite"
  44. item-text="siteid"
  45. :label="label('Site.siteid')"
  46. :filter="siteAutocompleteFilter"
  47. autocomplete
  48. required
  49. return-object
  50. :hint="`${selectedSite ? selectedSite.name : ''}`"
  51. persistent-hint>
  52. <template slot="item" slot-scope="data">
  53. <div>({{ data.item.siteid }}) &nbsp; {{data.item.name}}</div>
  54. </template>
  55. </v-select>
  56. </v-flex>
  57. </v-layout>
  58. <v-layout row justify-space-between>
  59. <v-flex>
  60. <v-checkbox
  61. v-if="!resettingPassword"
  62. :label="label('User.resetpassword')"
  63. v-model="changePassword"/>
  64. </v-flex>
  65. <v-flex class="text-xs-right">
  66. <v-btn
  67. @click="login"
  68. :disabled="sites.length <= 0 || loginInProgress || !selectedSite">
  69. {{label('login')}}
  70. </v-btn>
  71. </v-flex>
  72. </v-layout>
  73. </v-form>
  74. </v-flex>
  75. </v-layout>
  76. </v-container>
  77. </template>
  78.  
  79. <script>
  80. import { mapGetters } from "vuex";
  81. import { PasswordResetException } from "../exceptions";
  82.  
  83. export default {
  84. data() {
  85. return {
  86. resettingPassword: false,
  87. changePassword: false,
  88. showPassword: false,
  89. username: "",
  90. password: "",
  91. newpassword: null,
  92. newpasswordverify: null,
  93. selectedSite: null,
  94. sites: [],
  95. siteAutocompleteFilter(item, queryString, itemText) {
  96. const hasValue = val => (val != null ? val : "");
  97. const siteid = hasValue(item.siteid)
  98. .toString()
  99. .toLowerCase();
  100. const siteName = hasValue(item.name)
  101. .toString()
  102. .toLowerCase();
  103. const query = hasValue(queryString)
  104. .toString()
  105. .toLowerCase();
  106. return siteid.indexOf(query) > -1 || siteName.indexOf(query) > -1;
  107. }
  108. };
  109. },
  110. computed: {
  111. loginInProgress() {
  112. return this.$store.state.login_inprogress;
  113. },
  114. loginData() {
  115. let loginData = {
  116. username: this.username,
  117. password: this.password,
  118. siteid: this.selectedSite.siteid
  119. };
  120. if (this.resettingPassword) {
  121. loginData.password = this.password;
  122. loginData.newpassword = this.newpassword;
  123. loginData.newpasswordverify = this.newpasswordverify;
  124. }
  125. return loginData;
  126. },
  127. ...mapGetters(["label", "error"])
  128. },
  129. methods: {
  130. async login() {
  131. try {
  132. let loginData = this.loginData;
  133. if (this.changePassword) {
  134. loginData.resetpassword = "Y";
  135. this.changePassword = false;
  136. }
  137. await this.$store.dispatch("authenticate", loginData);
  138. this.$router.push({ name: "count" });
  139. } catch (e) {
  140. if (e instanceof PasswordResetException) {
  141. this.password = null;
  142. this.resettingPassword = true;
  143. } else {
  144. this.$notify(e.notifyParams);
  145. }
  146. }
  147. }
  148. },
  149. async created() {
  150. this.sites = await this.$store.dispatch('get_sites');
  151. throw new ReferenceError("testing");
  152. }
  153. };
  154. </script>
Add Comment
Please, Sign In to add comment