Skip to content

Instantly share code, notes, and snippets.

@glutengo
Last active April 12, 2017 22:18
Show Gist options
  • Select an option

  • Save glutengo/9423288c8caef819c50407f1aeb38e29 to your computer and use it in GitHub Desktop.

Select an option

Save glutengo/9423288c8caef819c50407f1aeb38e29 to your computer and use it in GitHub Desktop.
// login method
login() {
// set params: password or imageUrl, depending on chosen loginMethod
var params: any = {
username: this.username
};
if(this.loginMethod === 'password') {
params.password = this.password;
}
else {
params.image = this.imageUrl;
}
// perform http call
this.userRestService.login({
username: this.username,
password: this.password,
image: this.imageUrl
}).subscribe( data => {
// on success set token and user data
var token = data.token;
this.auth.setToken(token);
this.auth.setUser({username: this.username});
// navigate to home page
this.router.navigate(['/home']);
});
}
// image changed handler for embedded components (image picker, camera snapshot)
imageChanged(data) {
this.imageUrl = data;
this.ref.detectChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment