I have a login page but i do not know how to pass certain parameters after subscribing and receiving data. Also I don’t know how and where to check the received data…if login is true , push (this) if not (log error) ???
login.ts
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
login: {username?: string , password?: string} = {};
submitted = false;
constructor(public navCtrl: NavController, private schoolAppUsers: SchoolAppUsers) {
this.schoolAppUsers=schoolAppUsers;
}
onLogin(form) {
this.submitted = true;
if (form.valid) {
this.schoolAppUsers.login(this.login).subscribe(loginDetails => {
this.navCtrl.setRoot(TeachersPage);
});
}
}
}
service.ts
@Injectable()
export class SchoolAppUsers {
loginApiUrl = 'http://localhost/SchoolApp/include/userLogin.php';
login(login): Observable<User> {
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.loginApiUrl,'username='+login.username+'&password='+login.password, options)
.map(res => <User>(res.json()))
}
}
When I console log (loginDetails) , I see that I am receiving the right details, but how and where Do I write the conditions to act accordingly before setting or pushing the next page ??
Also when the user login , there is column specified for user role / user type … How do I pass this information along to use it in other pages…because I have 3 different users that have different access (admin , student, lecturer)
can someone please enlighten me on this issue , much appreciated.
