Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import store from '../../../store.js'
- import axios from 'axios'
- import ContentApi from '../../../api.js'
- const contentApi = new ContentApi();
- import qs from 'qs'
- export default {
- data () {
- return {
- username: '',
- password: '',
- loading:false,
- submitErrors: [],
- invalid: false,
- }
- },
- methods: {
- attemptLogin(){
- if(this.username == '' || this.password == ''){
- this.submitErrors = [];
- this.submitErrors.push("You must provide both a username and password.");
- this.invalid = true;
- setTimeout(()=>{ this.invalid = false }, 300);
- }
- else{
- this.submitErrors = [];
- this.loading = true;
- let that = this;
- let data = {
- username:this.username,
- password:this.password,
- client_id:contentApi.clientID,//application client
- grant_type: 'password'
- }
- let headers = {
- 'Content-Type': 'application/x-www-form-urlencoded',
- }
- axios.post(contentApi.authToken, qs.stringify(data), headers)
- .then(response => {
- localStorage.setItem("authToken", response.data.access_token);
- store.state.authenticated = true;
- })
- .catch(e => {
- that.invalid = true;
- setTimeout(()=>{ that.invalid = false }, 300);
- console.log(e);//change to raise exception.
- that.submitErrors = [];
- that.submitErrors.push(e.response.data.error_description);
- that.loading = false;
- e.response.data.error_description
- });
- //do your ajax call here to request a token.
- }
- },
- },
- }
Add Comment
Please, Sign In to add comment