Where is Ionic3’s authenctication sample based on WordPress Database. I wanna make login,logout,register page based on WordPress as Backend???
i wanna make login,logout,register page based on WordPress as Backend.
i need ionic3 sample.
plz tell me, thanks.
sry for my English.
I’m not sure if you’re looking for a “WordPress Backend” specifically here or you’re simply asking how to implement authentication Ionic3 using a PHP backend api.
I’ll give an example of my own. I have a backend that uses Bearer Token to authenticate. I make a request to the ‘/token’ endpoint passing in the credentials (‘username’ , ‘password’ and ‘grant_type’ which is ‘password’).
requestToken(credentials : any){
return this.provider.http.post(this.provider.apiUrl + '/token', credentials)
.map(res => res.json());
};
And here is my login page, where I get those credentials from the form and pass them to the function above. If the request is successful (statusCode 200), the Response will carries the ‘UserName’, ‘access_token’, and access token expiry date, and I store this data on my localStorage.
@Component({
selector: 'page-user',
templateUrl: 'login.html'
})
export class LoginPage {
login: UserModel = { username: '', password: '', grant_type: 'password' };
submitted = false;
constructor(
public navCtrl: NavController,
private account: AccountProvider,
public toastCtrl: ToastController) { }
onLogin(form: NgForm){
this.submitted = true;
if(form.valid){
let creds = "username="+this.login.username+"&password="+this.login.password +"&grant_type=password"
this.account.requestToken(creds)
.subscribe(res => {
this.account.login(res.userName); /** save username to localStorage*/
this.account.setAccessToken(res.access_token); /** save Bearer Token to localStorage*/
this.navCtrl.push(AccountPage);
}, () => {
this.toastCtrl.create({
message : 'Incorrect username or password. ',
duration: 3000,
position: 'top'
}).present();
});
}
}
}