Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Fixes #2 - Loader is recreated each time when it is needed. See ionic…
Browse files Browse the repository at this point in the history
  • Loading branch information
paoesco committed Dec 20, 2016
1 parent fed028a commit 6c433f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 10 additions & 9 deletions walkingdog-mobile/src/pages/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { SecurityContextHolder } from '../../components/authentication/security-
})
export class LoginPage {

loader: any;
loginForm: FormGroup;
private apiUrl: String;

Expand All @@ -35,9 +34,7 @@ import { SecurityContextHolder } from '../../components/authentication/security-
this.navCtrl.setRoot(HomePage);
}

this.loader = this.loadingCtrl.create({
content: "Please wait..."
});


this.loginForm = fb.group({
'email': ['', Validators.required],
Expand All @@ -53,29 +50,33 @@ import { SecurityContextHolder } from '../../components/authentication/security-


login(form: any) {
this.loader.present();
// Recreated every time we need it to fix https://github.com/driftyco/ionic/issues/6209
let loader = this.loadingCtrl.create({
content: "Please wait..."
});
loader.present();
if (form.valid) {
let value = form.value;
this.http
.post(`${this.apiUrl}/login`, JSON.stringify(value))
.subscribe((res: Response) => {
this.loader.dismiss();
loader.dismiss();
this.securityContextHolder.setCurrentUser(res.json());
this.navCtrl.setRoot(HomePage);
},
(err:Response) => {
if (err.status == 400 && err.statusText === 'user_not_enabled') {
this.loader.dismiss();
loader.dismiss();
alert('Your account has not been enabled yet. Please activate it by clicking on the link provided in e-mail');
return false;
} else {
this.loader.dismiss();
loader.dismiss();
alert('Wrong credentials');
return false;
}
});
} else {
this.loader.dismiss();
loader.dismiss();
alert('Required fields : email, password');
return false;
}
Expand Down
19 changes: 9 additions & 10 deletions walkingdog-mobile/src/pages/signup/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Http, Response } from '@angular/http';
})
export class SignupPage {

loader: any;
signupForm: FormGroup;
private apiUrl: String;

Expand All @@ -23,10 +22,6 @@ export class SignupPage {
private http: Http,
fb: FormBuilder) {

this.loader = this.loadingCtrl.create({
content: "Please wait..."
});

this.signupForm = fb.group({
'email': ['', Validators.required],
'password': ['', Validators.required],
Expand All @@ -45,32 +40,36 @@ export class SignupPage {
}

signup(form: any) {
this.loader.present();
// Recreated every time we need it to fix https://github.com/driftyco/ionic/issues/6209
let loader = this.loadingCtrl.create({
content: "Please wait..."
});
loader.present();
if (form.valid) {
let value = form.value;
this.http
.post(`${this.apiUrl}/signup`, JSON.stringify(value))
.subscribe((res: Response) => {
if (res.status == 201) {
this.loader.dismiss();
loader.dismiss();
alert('An e-mail has been sent. Please confirm you e-mail address before log in.');
this.navCtrl.setRoot(StartPage);
}

},
(err:Response) => {
if (err.status == 400) {
this.loader.dismiss();
loader.dismiss();
alert('E-mail address already exists. Please use another one.');
return false;
} else {
this.loader.dismiss();
loader.dismiss();
alert('Sorry, an error occured. Please come back later');
return false;
}
});
} else {
this.loader.dismiss();
loader.dismiss();
alert('Required fields : email, password, dog name, dog gender, dog breed, dog birthdate');
return false;
}
Expand Down

0 comments on commit 6c433f0

Please sign in to comment.