-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from fga-eps-mds/feature/43-user-signup
#43 Cadastro de usuário
- Loading branch information
Showing
6 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,171 @@ | ||
<template> | ||
<div class="signup"> | ||
<h1>This is an sign up page</h1> | ||
<div class="signup gradient"> | ||
<TopBar :iconleft="'chevron-left'"></TopBar> | ||
<div class="content-container"> | ||
<div class="content-title"> | ||
<a style="font-size: 40px"> Criar conta </a> | ||
</div> | ||
<div class="content-form"> | ||
<TextField class="mt-3" v-model="username" :label="'Nome'"></TextField> | ||
<TextField class="mt-3" v-model="email" :label="'Email'"></TextField> | ||
<TextField class="mt-3" v-model="password" :label="'Senha'" :password="true"></TextField> | ||
<TextField class="mt-3" v-model="confirm_password" :label="'Confirme a senha'" :password="true"></TextField> | ||
</div> | ||
<div class="content-button"> | ||
<SignButton class="mt-4" :label="'Criar conta'" @action="signup"/> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
import TopBar from '../components/layout/TopBar' | ||
import TextField from '../components/input/TextField' | ||
import SignButton from '../components/input/SignButton' | ||
import axios from "axios" | ||
import router from "../router" | ||
export default { | ||
components: { | ||
TopBar, | ||
TextField, | ||
SignButton, | ||
}, | ||
data() { | ||
return { | ||
username: '', | ||
email: '', | ||
password: '', | ||
confirm_password: '', | ||
} | ||
}, | ||
methods: { | ||
signup(){ | ||
if (!this.validateInput()) { | ||
return | ||
} | ||
let data = { | ||
email: this.email, | ||
username: this.username, | ||
password: this.password, | ||
confirm_password: this.confirm_password | ||
} | ||
let dataToken = { | ||
email: this.email, | ||
password: this.password, | ||
} | ||
const url = 'http://0.0.0.0:8080/users/signup/' | ||
axios.post(url, data) | ||
.then((response) => { | ||
axios.post("http://0.0.0.0:8080/users/token/", dataToken) | ||
.then((response) => { | ||
if (response.status == '200') { | ||
this.$toasted.show('Created!').goAway(2000) | ||
let tokenData = { | ||
accessToken: response.data['access'], | ||
refreshToken: response.data['refresh'] | ||
} | ||
this.$store.commit('authUser', tokenData); | ||
router.push({name: 'home'}) | ||
} else { | ||
this.$toasted.show('Algum erro ocorreu, tente de novo').goAway(2000) | ||
} | ||
}) | ||
.catch ((errors) => { | ||
console.log(errors.response) | ||
router.push({name: 'signin'}) | ||
}) | ||
}) | ||
.catch((error) => { | ||
if(error.response.data.email){ | ||
this.$toasted.show(error.response.data.email).goAway(2000) | ||
} | ||
if(error.response.data.username){ | ||
this.$toasted.show(error.response.data.username).goAway(2000) | ||
} | ||
if(error.response.data.password){ | ||
this.$toasted.show(error.response.data.password).goAway(2000) | ||
} | ||
}) | ||
}, | ||
validateInput(){ | ||
if (!this.username) { | ||
this.$toasted.show('Insira seu nome').goAway(2000) | ||
return false | ||
} | ||
if (!this.email) { | ||
this.$toasted.show('Insira um email').goAway(2000) | ||
return false | ||
} | ||
if (!this.password) { | ||
this.$toasted.show('Insira uma senha').goAway(2000) | ||
return false | ||
} | ||
if (this.password.length < 8) { | ||
this.$toasted.show('Insira uma senha maior que 8 caracteres').goAway(2000) | ||
return false | ||
} | ||
if (this.confirm_password != this.password) { | ||
this.$toasted.show('As senhas devem corresponder').goAway(2000) | ||
return false | ||
} | ||
let emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/igm | ||
if (!this.email.match(emailRegex)) { | ||
this.$toasted.show('Email digitado não é válido').goAway(2000) | ||
return false | ||
} | ||
return true | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
@import "../assets/stylesheets/colors.scss"; | ||
.content-button { | ||
margin-top: 90px; | ||
} | ||
.content-title { | ||
width: 100%; | ||
padding: 0px 25px; | ||
margin-bottom: 20%; | ||
color: $color-default-text; | ||
display: flex; | ||
justify-content: left; | ||
} | ||
.content-container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
.signup { | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
margin-top: 0; | ||
text-align: center; | ||
} | ||
.gradient { | ||
background-image: linear-gradient(180deg, rgba(86, 163, 166, 1), rgba(75s, 125, 170, 105)); | ||
} | ||
</style> |