Created
January 19, 2018 00:27
-
-
Save SpencerCooley/bba53864790a90f8fe66aa1fc0070811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment