Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component,OnInit } from '@angular/core';
- import {AuthService} from '../services/auth.service';
- import {User} from '../models/user';
- @Component({
- selector: 'login',
- templateUrl: `./login.component.html`
- })
- export class LoginComponent {
- user: User = new User();
- constructor(private auth: AuthService) {}
- onLogin(): void{
- this.auth.login(this.user)
- .then((user) => {
- console.log(user);
- })
- .catch((err) => {
- console.log(err);
- });
- }
- import { Injectable } from '@angular/core';
- import {HttpClient, HttpErrorResponse,HttpHeaders} from '@angular/common/http';
- //import 'rxjs/add/operator/toPromise';
- import {API_URL} from '../env';
- import {map,catchError} from 'rxjs/operators';
- import { throwError } from 'rxjs';
- @Injectable()
- export class AuthService {
- test(): string {
- return 'working';
- }
- constructor(private http: HttpClient) {}
- httpOptions = {
- headers: new HttpHeaders({
- 'Content-Type': 'application/json',
- 'Authorization': 'my-auth-token'
- })
- };
- private static _handleError(err: Response | any) {
- return throwError(err || 'Error: Unable to complete request.');
- // return "error"
- }
- login(user) : Promise<any>{
- return this.http.post(`${API_URL}/login`,user, this.httpOptions).toPromise()
- catchError(AuthService._handleError)
- }
- @app.route('/login', methods = ['POST'])
- def login():
- data1 = request.get_json(force=True)
- mydoc = mycol.find(data1)
- y = None
- for x in mydoc:
- print(x)
- y = x
- if (y == None):
- return jsonify({'error': 'error'})
- else :
- return jsonify({'done':'done'})
Add Comment
Please, Sign In to add comment