added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / signup / signup.component.ts
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 import { Component, OnInit } from '@angular/core';\r
18 import { routerTransition } from '../router.animations';\r
19 import { HttpClient } from '@angular/common/http';\r
20 import { AppGlobals } from '../app.global';\r
21 import { UserService } from '../shared/services/user.service';\r
22 import { Router } from '@angular/router';\r
23 import { User } from '../shared/models/user.model';\r
24 import { MatDialog } from '@angular/material';\r
25 import { AlertModalComponent } from '../shared/modules/alert-modal/alert-modal.component';\r
26 import { AuthService } from '../shared/services/auth.service';\r
27 \r
28 \r
29 @Component({\r
30     selector: 'app-signup',\r
31     templateUrl: './signup.component.html',\r
32     styleUrls: ['./signup.component.scss'],\r
33     animations: [routerTransition()]\r
34 })\r
35 export class SignupComponent implements OnInit {\r
36     public user = {\r
37         password: null,\r
38         firstName: null,\r
39         lastName: null,\r
40         email: null\r
41     };\r
42     public passwordConfirm;\r
43 \r
44     constructor(public router: Router,\r
45         private auth: AuthService,\r
46         public dialog: MatDialog\r
47         ) {\r
48            \r
49         }\r
50 \r
51     ngOnInit() {\r
52         \r
53     }\r
54 \r
55     register(){\r
56         // let body  = {\r
57         //     firstName: this.user.firstName,\r
58         //     lastName: this.user.lastName,\r
59         //     email: this.user.email,\r
60         //     password: this.user.password\r
61         // };\r
62         \r
63         if(this.user.password != this.passwordConfirm){\r
64             const dialogRef = this.dialog.open(AlertModalComponent, {\r
65                 data:{\r
66                     type: "Alert",\r
67                     message: "Passwords must match!"\r
68                 }\r
69 \r
70             });\r
71             \r
72             return;\r
73         }\r
74 \r
75         this.auth.register(this.user) \r
76             .subscribe(\r
77                 (res) => {\r
78                     const r = this.dialog.open(AlertModalComponent, {\r
79                         data: {\r
80                             type: "Alert",\r
81                             message: "Check your email to verify your account."\r
82                         }\r
83                     });\r
84 \r
85                     r.afterClosed().subscribe(res => {\r
86                         this.router.navigateByUrl('/login');\r
87                     })\r
88                       \r
89                 },\r
90                 (err) => {\r
91                     this.dialog.open(AlertModalComponent, {\r
92                         data:{\r
93                             type: "Alert",\r
94                             message: err\r
95                         }\r
96                     });\r
97                 }\r
98             );\r
99         \r
100         \r
101     }\r
102 }\r