【发布时间】:2017-06-27 06:23:20
【问题描述】:
我是 Ionic 和 Angular 的新手,并且拥有多年的 .NET 开发经验。我正在网上尝试一些示例来使用 Ionic 2 构建登录原型。
我让 WebAPI 在后台工作,只是根据传递的凭据是否正确返回 JSON 真或假。
我的身份验证提供程序如下所示:
public login(credentials) {
if (credentials.email === null || credentials.password === null) {
return Observable.throw("Please insert credentials");
} else {
this.result = this.http.post(this.CONST.APIUrl, JSON.stringify(credentials), new RequestOptions({headers: this.contentHeader})).map(res => res.json())
if (this.result)
{
this.currentUser = new User('Simon', 'saimon@devdactic.com');
}
return this.result;
}}
登录页面如下所示:
public login() {
this.showLoading()
this.auth.login(this.registerCredentials).subscribe(allowed => {
if (allowed) {
setTimeout(() => {
this.loading.dismiss();
this.nav.setRoot(HomePage)
});
} else {
this.showError("Access Denied");
}
},
error => {
this.showError(error);
});
}
目前它总是让用户登录。我知道这是因为 this.result 总是有价值的。但是在允许用户登录之前,我如何检查从 API 返回的数据?
【问题讨论】:
标签: angularjs ionic-framework ionic2