Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <div class="container">
- <h3>Jogo da Memória</h3>
- <br>
- <div class="text">
- Login:
- <input v-model="email" >
- <br>
- <br>
- Palavra-passe:
- <input type="password" v-model="password" >
- <br>
- <br>
- <p><button v-on:click="login" class="btn btn-default" >Confirmar</button> </p>
- </div>
- </div>
- </template>
- <script>
- export default {
- data: function(){
- return {
- username: "",
- password: "",
- email: "",
- changed: true
- }
- },
- methods:{
- login: function () {
- if((this.email.includes('@'))){
- axios.post('api/users/findnickname',{
- email: this.email
- })
- .then(response=> {
- console.log(this.username);
- this.username = response.data;
- console.log("USERNAME atribuido: "+this.username);
- axios.post('/api/login', {
- email: this.email,
- password: this.password
- })
- .then(response => {
- this.$store.state.token= response.data.access_token;
- this.$store.state.isUserLogged = true;
- this.$emit('tokenAssign');
- this.$store.state.username = this.username;
- //if() SE FOR ADMIN MANDAR PARA OUTRO SITIO
- axios.post('api/users/isAdmin',{
- username: this.username
- }).then(response=> {
- if(response.data===1){
- console.log("ADMIN durante o login, a definir state.isAdmin..");
- this.$store.state.isAdmin=1;
- this.$router.push('/admin');//TEMPORARIO
- }else{
- this.$router.push('/game');//TEMPORARIO
- }
- });
- // console.log(this.store().username)
- })
- .catch(function (error) {
- alert(error.response.data);
- console.log(error);
- });
- }).catch(function (error) {
- alert(error.response.data);
- console.log(error);
- });
- }else{
- let usernameOld= this.email;
- axios.post('api/users/findemail',{
- username: this.email //Campo onde o user preencheu com username vai ser enviado para a api para retornar o email
- })
- .then(response=> {
- this.email = response.data; //o username vai ser substituido pelo email para facilitar o login da api
- axios.post('/api/login', {
- email: this.email,
- password: this.password
- })
- .then(response => {
- this.$store.state.token= response.data.access_token;
- this.$store.state.isUserLogged = true;
- localStorage.setItem('cookie', response.data.access_token);
- this.$emit('tokenAssign');
- this.$store.state.username = usernameOld;
- //if() SE FOR ADMIN MANDAR PARA OUTRO SITIO
- axios.post('api/users/isAdmin',{
- username: usernameOld
- }).then(response=> {
- if(response.data===1){
- console.log("ADMIN durante o login, a definir state.isAdmin..");
- this.$store.state.isAdmin=1;
- this.$router.push('/admin');//TEMPORARIO
- }else{
- this.$router.push('/game');//TEMPORARIO
- }
- });
- //this.$router.push('/game');
- })
- .catch(function (error) {
- console.log(error);
- });
- });
- }
- },
- },
- mounted() {
- console.log('Component mounted.')
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement