Guest User

Untitled

a guest
Jan 8th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. <template>
  2. <transition name="fade" mode="out-in">
  3. <div>
  4. <div class="hero is-fullheight">
  5. <div class="hero-body">
  6. <div class="container">
  7. <h2 class="title is-2 has-text-white has-text-centered">Login</h2>
  8. <div class="columns">
  9. <div class="column is-one-third is-offset-one-third">
  10. <div class="box">
  11. <form action="#" method="POST" name="login" id="login" @submit='submit'>
  12. <b-field :type='errUser ? "is-danger" : ""' :message='errUser'>
  13. <b-input
  14. required
  15. icon="user"
  16. type="text"
  17. placeholder="Username"
  18. name="username"
  19. v-model.lazy='username'
  20. ></b-input>
  21. </b-field>
  22. <b-field>
  23. <b-input
  24. required
  25. icon="lock"
  26. type="password"
  27. placeholder="Password"
  28. name="password"
  29. v-model.lazy='password'
  30. password-reveal
  31. ></b-input>
  32. </b-field>
  33. <b-field class="cb">
  34. <b-checkbox v-model='rememberMe'>Remember Me</b-checkbox>
  35. <b-tooltip
  36. animated
  37. :label='explanation'
  38. position="is-right"
  39. class="tooltip"
  40. type="is-info"
  41. multilined
  42. >
  43. <b-icon icon="question-circle" size="is-small"></b-icon>
  44. </b-tooltip>
  45. </b-field>
  46. <button
  47. class="button is-dark is-fullwidth"
  48. type="submit"
  49. form="login"
  50. value="Submit"
  51. >Login</button>
  52. <div class="has-text-centered forgotPass">
  53. <a
  54. class="is-link is-size-7 is-centered"
  55. @click='forgotPassword = true'
  56. >Forgot Password?</a>
  57. </div>
  58. </form>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64.  
  65. <b-modal :active.sync='forgot_password' animation="zoom-out">
  66. <ForgotPasswordModal></ForgotPasswordModal>
  67. </b-modal>
  68. </div>
  69. </div>
  70. </transition>
  71. </template>
  72.  
  73. <script>
  74. import ForgotPasswordModal from "./subcomponents/ForgotPasswordModal"
  75. import error from './..//Utilities/ErrorGenerator'
  76. import { mapState, mapActions } from "vuex"
  77.  
  78. export default {
  79. components: {
  80. ForgotPasswordModal
  81. },
  82.  
  83. data: function () {
  84. const explanation = 'Mencentang opsi ini akan membuat anda terautentikasi secara otomatis selama 24 jam pada komputer ini'
  85. return {
  86. explanation,
  87. forgot_password: false,
  88. username: ``,
  89. password: ``,
  90. rememberMe: false
  91. }
  92. },
  93.  
  94. computed: mapState('current_user', ['user']),
  95.  
  96. computed: {
  97. errUser: function () {
  98. const regex = /[^\w.]/i
  99. if (this.username.length > 0 && regex.test(this.username))
  100. return `Username hanya boleh berisi karakter huruf, angka, dan titik`
  101. else
  102. return ``
  103. }
  104. },
  105.  
  106. methods: {
  107. ...mapActions('current_user', ['login']),
  108.  
  109. submit: function (e) {
  110. e.preventDefault()
  111.  
  112. console.log(this.user) // undefined, shouldn't it be null?
  113.  
  114. if (this.errUser) {
  115. this.$refs.user.focus()
  116. return
  117. }
  118.  
  119. this.login({ username: this.username, password: this.password }, this.rememberMe)
  120. .then(() => {
  121. console.log(this.user) // also undefined, should be some object, as vue-devtools shows the correct value
  122. this.$toast.open({
  123. message: `Berhasil login dengan username <samp>${this.username}</samp>`,
  124. type: 'is-black',
  125. duration: 3500
  126. })
  127. // this.$router.push({ name: 'Introduction' })
  128. }).catch(message => {
  129. error(message)
  130. })
  131. }
  132. }
  133. }
  134. </script>
  135.  
  136. <style lang="scss" scoped>
  137. .hero {
  138. /* Using linear-gradient generator */
  139. background: #000000; /* fallback for old browsers */
  140. background: -webkit-linear-gradient(
  141. to bottom,
  142. #434343,
  143. #000000
  144. ); /* Chrome 10-25, Safari 5.1-6 */
  145. background: linear-gradient(
  146. to bottom,
  147. #434343,
  148. #000000
  149. ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  150. }
  151.  
  152. form {
  153. .field:not(.cb) {
  154. min-height: 3.65em;
  155. }
  156. }
  157.  
  158. .forgotPass {
  159. margin-top: 0em;
  160. margin-bottom: 0em;
  161. }
  162.  
  163. .button {
  164. margin-bottom: 0em;
  165. }
  166.  
  167. .tooltip {
  168. cursor: pointer;
  169. margin: auto;
  170. margin-left: 0.3em;
  171. }
  172. </style>
Add Comment
Please, Sign In to add comment