Advertisement
Guest User

Untitled

a guest
May 19th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. <template>
  2. <div class="login-wrapper columns">
  3. <div class="column is-8 is-hidden-mobile hero-banner">
  4. <section class="hero is-fullheight is-primary">
  5. </section>
  6. </div>
  7. <div class="column is-4">
  8. <section class="hero is-fullheight">
  9. <div class="hero-heading">
  10. <div class="section has-text-centered">
  11. <h1 class="title is-1"><strong>eduHours</strong></h1>
  12. </div>
  13. </div>
  14.  
  15. <div class="hero-body">
  16. <div class="container">
  17. <div class="columns">
  18. <div class="column is-10 is-offset-1">
  19.  
  20. <form @submit.prevent="onSubmit" class="login-form">
  21. <div class="columns">
  22. <div class="column">
  23. <p class="control has-icon has-icon-right">
  24. <input v-model="vm.username" class="input email-input is-medium" type="text" placeholder="username@eduhours.com">
  25. <span class="icon user">
  26. <i class="fa fa-user"></i>
  27. </span>
  28. </p>
  29. </div>
  30. </div>
  31.  
  32. <div class="columns">
  33. <div class="column">
  34. <p class="control has-icon has-icon-right">
  35. <input v-model="vm.password" class="input password-input is-medium" type="password" placeholder="●●●●●●●">
  36. <span class="icon user">
  37. <i class="fa fa-lock"></i>
  38. </span>
  39. </p>
  40. </div>
  41. </div>
  42.  
  43. <div class="columns">
  44. <div class="column">
  45. <p class="control login">
  46. <button class="button is-primary is-large is-fullwidth" :class="{ 'is-loading': isLoading }">
  47. <span class="icon">
  48. <i class="fa fa-sign-in"></i>
  49. </span>
  50. <span>Login</span>
  51. </button>
  52. </p>
  53. </div>
  54. </div>
  55. </form>
  56.  
  57. </div>
  58. </div>
  59.  
  60. <div class="columns">
  61. <powered-by></powered-by>
  62. </div>
  63. </div>
  64. </div>
  65. </section>
  66. </div>
  67. </div>
  68. </template>
  69.  
  70. <script>
  71. import ApiHelper from '@/Api/ApiHelper'
  72.  
  73. export default {
  74. name: 'Login',
  75. data () {
  76. return {
  77. isLoading: false,
  78. vm: {
  79. username: 'test@test.com',
  80. password: 'test'
  81. // username: null,
  82. // password: null
  83. }
  84. }
  85. },
  86.  
  87. methods: {
  88. onSubmit: function () {
  89. if (this.vm.username === null || this.vm.username === '') {
  90. return
  91. }
  92.  
  93. if (this.vm.password === null || this.vm.password === '') {
  94. return
  95. }
  96.  
  97. this.isLoading = true
  98.  
  99. const json = {
  100. username: this.vm.username,
  101. password: this.vm.password
  102. }
  103.  
  104. ApiHelper.post('auth', json)
  105. .then(response => {
  106. const accessToken = response.data.accessToken
  107. const tenantName = response.data.tenantName
  108. const fullName = response.data.fullName
  109. const userTypeName = response.data.userTypeName
  110.  
  111. // store to the browser's local storage
  112. localStorage.setItem('accessToken', accessToken)
  113. localStorage.setItem('tenantName', tenantName)
  114. localStorage.setItem('fullName', fullName)
  115. localStorage.setItem('userTypeName', userTypeName)
  116.  
  117. // push to dashboard
  118. this.$router.push({ path: '/dashboard' })
  119. })
  120. .catch(error => {
  121. const ERROR_API_SERVER_NOT_RUNNING = 'The Api server is not running now.'
  122. const ERROR_INCORRECT_LOGIN_PASSWORD = 'The login/password is incorrect.'
  123. const ERROR_GENERAL_NETWORK_ERROR = 'General network Error..'
  124.  
  125. this.isLoading = false
  126.  
  127. if (!error.response) {
  128. this.notifyOnError(ERROR_API_SERVER_NOT_RUNNING)
  129. } else {
  130. if (error.response.status === 401) {
  131. this.notifyOnError(ERROR_INCORRECT_LOGIN_PASSWORD)
  132. } else {
  133. this.notifyOnError(ERROR_GENERAL_NETWORK_ERROR)
  134. }
  135. }
  136. })
  137. }
  138. }
  139. }
  140. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement