Last active
April 12, 2017 22:18
-
-
Save glutengo/9423288c8caef819c50407f1aeb38e29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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