Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. <template>
  2.  
  3. <div class="input-field black-input login-wrapper border border-light">
  4.  
  5. <form class="form-signin" @submit.prevent="login">
  6. <h2 class="form-signin-heading">Please sign in</h2>
  7. <!-- <label for="inputEmail" class="sr-only">Email address</label> -->
  8.  
  9.  
  10. <div class="field">
  11. <label class="label">Username</label>
  12. <div class="control has-icons-left has-icons-right">
  13.  
  14. <input v-model="email" class="input" type="text" id="inputEmail" placeholder="Username" required autofocus>
  15. <span class="icon is-small is-left">
  16. <svg class="svg-inline--fa fa-user fa-w-16" aria-hidden="true" data-prefix="fas" data-icon="user" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 0c88.366 0 160 71.634 160 160s-71.634 160-160 160S96 248.366 96 160 167.634 0 256 0zm183.283 333.821l-71.313-17.828c-74.923 53.89-165.738 41.864-223.94 0l-71.313 17.828C29.981 344.505 0 382.903 0 426.955V464c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48v-37.045c0-44.052-29.981-82.45-72.717-93.134z"></path></svg><!-- <i class="fas fa-user"></i> -->
  17. </span>
  18. </div>
  19. </div>
  20.  
  21. <div class="field">
  22. <label class="label">Password</label>
  23. <div class="control has-icons-left has-icons-right">
  24.  
  25. <input v-model="password" class="input" type="password" id="inputPassword" placeholder="Password" required >
  26.  
  27. </div>
  28. </div>
  29.  
  30.  
  31.  
  32. <!-- <label for="inputPassword" class="sr-only">Password</label> -->
  33.  
  34. <!-- <span class="edit-icon"></span>
  35. <input v-model="password" type="password" id="inputPassword" class="" placeholder="Password" required> -->
  36.  
  37.  
  38.  
  39. <button type="submit" v-bind:class="{ 'is-loading': isLoading }" class="button is-info ">Sign In</button>
  40.  
  41. <button type="button" class="button is-danger" v-if="error">Login Failed</button>
  42.  
  43.  
  44.  
  45. </form>
  46.  
  47.  
  48.  
  49.  
  50. </div>
  51. </template>
  52.  
  53. <script>
  54. export default {
  55. name: 'Login',
  56. data () {
  57. return {
  58. email: '',
  59. password: '',
  60. error: false,
  61. isLoading: false
  62. }
  63. },
  64. created () {
  65. this.checkCurrentLoginOrRedirect()
  66. },
  67. updated () {
  68. this.checkCurrentLoginOrRedirect()
  69. },
  70. beforeMount(){
  71. console.log("before mount")
  72. },
  73. mounted(){
  74. console.log("mounted")
  75. },
  76. methods: {
  77. checkCurrentLoginOrRedirect () {
  78. if (localStorage.token) {
  79. this.$router.replace(this.$route.query.redirect || '/home')
  80. } else {
  81. this.$router.push('/')
  82. }
  83. },
  84. login () {
  85. this.isLoading = true;
  86. console.log(this.email)
  87. console.log(this.password)
  88. this.$http.post('/auth-token', { username: this.email, password: this.password })
  89. .then(request => this.loginSuccessful(request))
  90. .catch(() => this.loginFailed())
  91. },
  92. loginSuccessful (req) {
  93. console.log(req)
  94. if (!req.data.data.id) {
  95. this.loginFailed()
  96. return
  97. }
  98. localStorage.token = req.data.data.id
  99. this.error = false
  100. console.log("we made it")
  101. this.$router.push('/home')
  102. },
  103. loginFailed () {
  104. this.isLoading = false;
  105. console.log("failure ");
  106. this.error = 'Login failed!'
  107. delete localStorage.token
  108. }
  109.  
  110.  
  111. }
  112. }
  113. </script>
  114.  
  115. <style lang="css">
  116. body {
  117. background: #white;
  118. }
  119.  
  120.  
  121.  
  122. .form-signin {
  123. max-width: 330px;
  124.  
  125. margin: 0 auto;
  126. }
  127. .form-signin .form-signin-heading,
  128. .form-signin .checkbox {
  129. margin-bottom: 10px;
  130. }
  131. .form-signin .checkbox {
  132. font-weight: normal;
  133. }
  134. .form-signin .form-control {
  135. position: relative;
  136. height: auto;
  137. -webkit-box-sizing: border-box;
  138. box-sizing: border-box;
  139. padding: 10px;
  140. font-size: 16px;
  141. }
  142. .form-signin .form-control:focus {
  143. z-index: 2;
  144. }
  145. .form-signin input[type="email"] {
  146. margin-bottom: -1px;
  147. border-bottom-right-radius: 0;
  148. border-bottom-left-radius: 0;
  149. }
  150. .form-signin input[type="password"] {
  151. margin-bottom: 10px;
  152. border-top-left-radius: 0;
  153. border-top-right-radius: 0;
  154. }
  155. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement