Guest User

Untitled

a guest
Nov 12th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. formats:
  2. {
  3. "/api": {
  4. "target": "http://localhost:1100",
  5. "secure": false,
  6. }
  7. }
  8.  
  9. "scripts": {
  10. "ng": "ng",
  11. "start": "ng serve --proxy-config proxy.config.json",
  12. "build": "ng build",
  13. "test": "ng test",
  14. "lint": "ng lint",
  15. "e2e": "ng e2e"
  16. },
  17.  
  18. import { Injectable } from '@angular/core';
  19.  
  20. import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
  21. import { Observable } from 'rxjs/Observable';
  22.  
  23. import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
  24. import { catchError } from 'rxjs/operators/catchError';
  25. @Injectable({
  26. providedIn: 'root'
  27. })
  28. export class ApiService {
  29. private apiUrl: string;
  30. constructor(
  31. private http: HttpClient,
  32. ) {
  33. this.apiUrl = '';
  34. }
  35.  
  36. private formatErrors(error: any) {
  37. console.log(error)
  38. return new ErrorObservable(error);
  39. }
  40.  
  41. get(path: string, params: HttpParams = new HttpParams()): Observable<any> {
  42. return this.http.get(`${this.apiUrl}${path}`, { params })
  43. .pipe(catchError(this.formatErrors));
  44. }
  45.  
  46. post(path: string, body: Object = {}): Observable<any> {
  47. return this.http.post(
  48. `${this.apiUrl}${path}`,
  49. JSON.stringify(body)
  50. ).pipe(catchError(this.formatErrors));
  51. }
  52.  
  53.  
  54. }
  55.  
  56. import { Injectable } from '@angular/core';
  57. import { Observable } from 'rxjs/Observable';
  58. import { ApiService } from './api.service';
  59. import { map } from 'rxjs/operators/map';
  60. import {User} from '../models/user.model';
  61. @Injectable({
  62. providedIn: 'root'
  63. })
  64. export class UserService {
  65. constructor(private apiService: ApiService) { }
  66. signin(id, data): Observable<User>{
  67. return this.apiService.post('/api/user/signin', data)
  68. .pipe(map(data => data));
  69. }
  70. signup(id, data): Observable<User>{
  71. return this.apiService.post('/api/user/'+id+'/signup', data)
  72. .pipe(map(data => data));
  73. }
  74.  
  75. }
  76.  
  77. export class User{
  78. constructor(){};
  79. id: number;
  80. email: string;
  81. password:string ;
  82. firstName:string ;
  83. lastName:string ;
  84. type:number ;
  85. company:string;
  86. }
  87.  
  88. import { Component, OnInit } from '@angular/core';
  89. import{User} from '../../core/models/user.model'
  90. import { UserService } from 'src/app/core';
  91. import { FormsModule, ReactiveFormsModule } from '@angular/forms';
  92. import { NgModule } from '@angular/core';
  93. @Component({
  94. selector: 'app-signin',
  95. templateUrl: './signin.component.html',
  96. styleUrls: ['./signin.component.css'],
  97. providers: [UserService],
  98. })
  99. @NgModule({
  100. imports: [
  101. FormsModule,
  102. ReactiveFormsModule,
  103. ],
  104. })
  105. export class SigninComponent implements OnInit {
  106. private user: User=new User();
  107.  
  108. constructor(private userSvc: UserService) {
  109. this.user.email="";
  110. this.user.password="";
  111. }
  112. private email:string="";
  113. ngOnInit() {
  114. }
  115. ValidateLogin (){
  116. //validate
  117. var userid=0;
  118. alert(this.email);
  119. var param={firstName:this.user.firstName,
  120. lastName:this.user.lastName,
  121. email:this.user.email,
  122. password:this.user.password,
  123. company:this.user.company,
  124. type:1,
  125. };
  126.  
  127. this.userSvc.signin(userid, this.user).subscribe(data => {
  128. if(Number(data.id)>0){
  129. console.log("return status: ");
  130. }
  131. else{ console.log("error");}
  132. });
  133. }
  134. }
  135.  
  136. -----------------------------------------------------------
  137. @angular-devkit/architect 0.6.8
  138. @angular-devkit/build-angular 0.6.8
  139. @angular-devkit/build-optimizer 0.6.8
  140. @angular-devkit/core 0.6.8
  141. @angular-devkit/schematics 0.6.8
  142. @angular/cli 6.0.8
  143. @ngtools/webpack 6.0.8
  144. @schematics/angular 0.6.8
  145. @schematics/update 0.6.8
  146. rxjs 6.2.1
  147. typescript 2.7.2
  148. webpack 4.8.3
Add Comment
Please, Sign In to add comment