Skip to content

Commit

Permalink
Merge pull request #4 from GoogolApp/signup
Browse files Browse the repository at this point in the history
Signup done
  • Loading branch information
igormatheusdiniz committed May 24, 2018
2 parents 6dee59e + 3ebf866 commit f9bfcaa
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/pages/signup/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@ export class SignUpPage {
constructor(public navCtrl: NavController, public alert:AlertController, public usersService:UsersService) {
}

validateFields() : boolean {
let regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

if(this.email === "" || this.username === "" || this.password === "" || this.password === "") {
this.presentAlert("Preencha todos os campos!");
return false;
}
if(!regex.test(this.email)) {
this.presentAlert("E-mail inválido!");
return false;
}
if(this.password !== this.password_confirm) {
this.presentAlert("As senhas não combinam!");
return false;
}

return true;
}

createUser(){
if(this.password !== this.password_confirm){
this.presentAlert("As senhas não combinam!")
}else{
if(this.validateFields()){

let user = new User(this.username, this.email, this.password);

this.usersService.create(user).subscribe(
data => {
this.presentAlert("Usuário criado com sucesso!");
this.createdUserAlert("Usuário criado com sucesso!");
this.clearFields();
this.goSignIn();
},
Expand All @@ -46,6 +64,15 @@ export class SignUpPage {
this.password_confirm = "";
}

createdUserAlert(message) {
let alert = this.alert.create({
title: 'Sucesso!',
subTitle: message,
buttons: ['OK']
});
alert.present();
}

presentAlert(message) {
let alert = this.alert.create({
title: 'Atenção',
Expand Down

0 comments on commit f9bfcaa

Please sign in to comment.