Guest User

Untitled

a guest
Oct 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import { Component,OnInit } from '@angular/core';
  2. import {AuthService} from '../services/auth.service';
  3. import {User} from '../models/user';
  4.  
  5. @Component({
  6. selector: 'login',
  7. templateUrl: `./login.component.html`
  8.  
  9. })
  10. export class LoginComponent {
  11. user: User = new User();
  12. constructor(private auth: AuthService) {}
  13. onLogin(): void{
  14. this.auth.login(this.user)
  15. .then((user) => {
  16. console.log(user);
  17.  
  18. })
  19. .catch((err) => {
  20. console.log(err);
  21. });
  22. }
  23.  
  24. import { Injectable } from '@angular/core';
  25. import {HttpClient, HttpErrorResponse,HttpHeaders} from '@angular/common/http';
  26. //import 'rxjs/add/operator/toPromise';
  27. import {API_URL} from '../env';
  28. import {map,catchError} from 'rxjs/operators';
  29. import { throwError } from 'rxjs';
  30.  
  31. @Injectable()
  32. export class AuthService {
  33. test(): string {
  34. return 'working';
  35. }
  36. constructor(private http: HttpClient) {}
  37. httpOptions = {
  38. headers: new HttpHeaders({
  39. 'Content-Type': 'application/json',
  40. 'Authorization': 'my-auth-token'
  41. })
  42. };
  43. private static _handleError(err: Response | any) {
  44. return throwError(err || 'Error: Unable to complete request.');
  45. // return "error"
  46. }
  47. login(user) : Promise<any>{
  48. return this.http.post(`${API_URL}/login`,user, this.httpOptions).toPromise()
  49.  
  50. catchError(AuthService._handleError)
  51.  
  52. }
  53.  
  54. @app.route('/login', methods = ['POST'])
  55. def login():
  56. data1 = request.get_json(force=True)
  57. mydoc = mycol.find(data1)
  58. y = None
  59. for x in mydoc:
  60. print(x)
  61. y = x
  62.  
  63. if (y == None):
  64. return jsonify({'error': 'error'})
  65. else :
  66. return jsonify({'done':'done'})
Add Comment
Please, Sign In to add comment