Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signup done #4

Merged
merged 2 commits into from
May 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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