Advertisement
Guest User

Untitled

a guest
Nov 12th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div>
  3.         <h1>Авторизация</h1>
  4.         <b-form @submit="onSubmit">
  5.             <b-form-group id="exampleInputGroup2"
  6.                           label="Ваш логин:" label-for="exampleInput2">
  7.                 <b-form-input id="exampleInput2"
  8.                               type="text" v-model="form.name" required
  9.                               placeholder="Введите Ваш логин"
  10.                 ></b-form-input>
  11.  
  12.             </b-form-group>
  13.             <b-form-group id="exampleInputGroup2"
  14.                           label="Ваш пароль:" label-for="exampleInput2">
  15.                 <b-form-input id="exampleInput2"
  16.                               type="password" v-model="form.pass" required
  17.                               placeholder="Введите Ваш пароль"
  18.                 ></b-form-input>
  19.             </b-form-group>
  20.             <b-button type="submit" variant="primary">Submit</b-button>
  21.             <b-button type="reset" variant="secondary">Reset</b-button>
  22.         </b-form>
  23.     </div>
  24. </template>
  25.  
  26. <script>
  27.   import axios from 'axios'
  28.  
  29.   export default {
  30.     data () {
  31.       return {
  32.         form: {
  33.           name: '',
  34.           pass: ''
  35.         }
  36.       }
  37.     },
  38.     mounted () {
  39.       console.log(localStorage.getItem('token'))
  40.     },
  41.     methods: {
  42.       onSubmit (evt) {
  43.         evt.preventDefault()
  44.         axios.post('http://127.0.0.1:8000/token',
  45.           {
  46.             username: this.form.name, password: this.form.pass
  47.           })
  48.           .then((e) => {
  49.             if (e.data.token !== undefined) {
  50.               localStorage.setItem('token', e.data.token)
  51.               localStorage.setItem('loginUser', this.form.name)
  52.             }
  53.           })
  54.           .catch((err) => console.log(err))
  55.       }
  56.     }
  57.   }
  58. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement