Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- onSubmit(userData: any): void {
- this.user = new UserData(userData);
- this.services.getAccess(this.user).subscribe();
- }
- getAccess(user: UserData): any {
- let headers = new Headers();
- let client_id = 'fge432358768979fgwefg34f34';
- let credentials = 'grant_type=password&client_id=' + client_id + '&client_secret=' + user.secretKey + '&username=' + user.email + '&password=' + user.password;
- headers.append('Content-Type', 'application/x-www-form-urlencoded');
- return this.http.post(
- this.baseApiUrl + '/oauth/access_token',
- credentials,
- {
- headers: headers
- }
- )
- .map(this.handleSuccess)
- .catch(this.handleError);
- }
- handleError(error: Response | any) {
- console.log('error');
- swal("Oops...", 'The informations you’ve entered doesn’t match any account. ', "error");
- return Observable.throw(error);
- }
- handleSuccess(res: Response) {
- if (res.status === 200) {
- swal(
- {
- title: "Good job!",
- text: "You have successfully logged in.",
- timer: 2000,
- type: "success",
- showConfirmButton: false
- }
- );
- this.setCookie(res.json().access_token)
- }
- }
- setCookie(accessToken: string): void {
- this.cookie.setForOneHour(accessToken);
- }
- .map(data => this.handleSuccess(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement