Guest User

Untitled

a guest
Feb 11th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. <div align="center">
  2. <form (ngSubmit)="onLoginSubmit()" class="fullForm">
  3.  
  4. <div class="imgcontainer"></div>
  5. <h2>PL Auth</h2>
  6. <div class="container">
  7. <form (ngSubmit)="generateOtpSubmit()" class="generateOtpForm">
  8. <label> <b>Username: </b>
  9. </label> <input type="text" placeholder="Enter Username" id="username"
  10. [(ngModel)]=userName name="uname" required> <br> <br>
  11. <label> <b>Password : </b>
  12. </label> <input type="password" placeholder="Enter Password" id="password"
  13. [(ngModel)]=password name="psw" required> <br> <br>
  14. <button type="submit" class="otpButton">Generate OTP</button>
  15. </form>
  16. <br> <br> <label> <b>Enter OTP : </b>
  17. </label> <input type="text" placeholder="Enter OTP" id="otp" [(ngModel)]=otp
  18. name="otp" required> <br> <br>
  19. <button type="submit" class="loginButton">Login</button>
  20.  
  21. </div>
  22. <div>
  23. <p style="color: red;">{{ loginStatus }}</p>
  24. </div>
  25. </form>
  26. <router-outlet></router-outlet>
  27. </div>
  28.  
  29. import { Component, OnInit } from '@angular/core';
  30. import { Location } from '@angular/common';
  31. import { HomepageComponent } from './homepage/homepage.component';
  32. import { Headers, Http, Response } from '@angular/http';
  33. import { RouterModule, Routes } from '@angular/router';
  34. import { HttpClient } from '@angular/common/http';
  35. import { Directive } from '@angular/core';
  36. //import { Router } from '@angular/router';
  37. import { Router } from "@angular/router";
  38. import { Text } from '@angular/compiler';
  39.  
  40.  
  41. export const appRoutes: Routes = [
  42. {path: 'home', component:HomepageComponent}
  43. ];
  44.  
  45. @Component({
  46. selector: 'app-root',
  47. templateUrl: './app.component.html',
  48. styleUrls: ['./app.component.css']
  49. })
  50.  
  51. export class AppComponent implements OnInit {
  52.  
  53. otpsubmitted = false;
  54. loginSubmitted = false;
  55. userName = '';
  56. password = '';
  57. otp ='';
  58. userAuthCheck:Text;
  59. checkOtp:Text;
  60. authCheck ='';
  61. loginStatus='';
  62.  
  63. ngOnInit() {
  64. }
  65.  
  66. constructor(private http: Http,private httpClient: HttpClient,private route: Router ) { }
  67.  
  68. private generateOtp(){
  69. this.http.post('http://localhost:8080/loginController/generateotp', {
  70. userMail: this.userName
  71. })
  72. .subscribe(
  73. res => {
  74. console.log(res);
  75. },
  76. err => {
  77. console.log("Error occured");
  78. }
  79. );
  80. }
  81.  
  82. private logSubmit(){
  83. this.http.post('http://localhost:8080/loginController/authUser', {
  84. userMail: this.userName,
  85. password: this.password,
  86. otp: this.otp
  87. })
  88. .subscribe(
  89. res => {
  90. const printResp=res.json();
  91. console.log(res);
  92. //this.loginStatus=printResp.status;
  93.  
  94. if (printResp.status === 'true'){
  95. this.loginStatus = '';
  96. console.log('in the clickName');
  97. this.route.navigateByUrl('/home');
  98. //this.route.navigate(['home/']);
  99. } else if(printResp.status === 'false') {
  100. this.loginStatus = printResp.Data.errorMessage;
  101. }
  102. },
  103. err => {
  104. console.log("Error occured"+err);
  105. }
  106. );
  107. }
  108.  
  109.  
  110. generateOtpSubmit() {
  111. this.otpsubmitted = true;
  112. this.generateOtp();
  113. }
  114.  
  115. onLoginSubmit(){
  116. this.loginSubmitted = true;
  117. this.logSubmit();
  118. }
  119. }
  120.  
  121. import {ApplicationComponent} from './application/application.component';
  122. import {NavigationComponent} from './navigation/navigation.component';
  123. import { HomepageComponent } from './homepage/homepage.component';
  124. import {AppComponent} from './app.component';
  125. import {NgModule} from '@angular/core';
  126. import {RouterModule, Routes} from '@angular/router';
  127. import { CommonModule } from '@angular/common';
  128.  
  129.  
  130. const routes: Routes = [
  131. {path: 'home', component: HomepageComponent},
  132. {path: 'application', component: ApplicationComponent},
  133. {path: 'navigation', component: NavigationComponent},
  134. ];
  135.  
  136. @NgModule({
  137. imports: [CommonModule,RouterModule.forRoot(routes)],
  138. exports: [RouterModule],
  139. declarations: []
  140. })
  141.  
  142. export class AppRoutingModule {}
  143.  
  144. import { BrowserModule } from '@angular/platform-browser';
  145. import { AppRoutingModule } from './app-routing.module';
  146. import { Router } from '@angular/router';
  147. import { NgModule } from '@angular/core';
  148. import { FormsModule } from '@angular/forms';
  149. import { AppComponent } from './app.component';
  150. import { HttpModule } from '@angular/http';
  151. import { HttpClientModule } from '@angular/common/http';
  152. import { HomepageComponent } from './homepage/homepage.component';
  153. import { ApplicationComponent } from './application/application.component';
  154. import { NavigationComponent } from './navigation/navigation.component';
  155. import { SearchuserComponent } from './searchuser/searchuser.component';
  156.  
  157. @NgModule({
  158. declarations: [
  159. AppComponent,
  160. HomepageComponent,
  161. ApplicationComponent,
  162. NavigationComponent,
  163. SearchuserComponent
  164. ],
  165. imports: [
  166. BrowserModule,
  167. FormsModule,
  168. HttpClientModule,
  169. HttpModule,
  170. AppRoutingModule
  171. ],
  172. bootstrap: [AppComponent]
  173. })
  174. export class AppModule { }
  175.  
  176. <p>
  177. homepage works!
  178. </p>
  179.  
  180. <!doctype html>
  181. <html lang="en">
  182. <head>
  183. <meta charset="utf-8">
  184. <title>CyberSecurityVw</title>
  185. <base href="/">
  186.  
  187. <meta name="viewport" content="width=device-width, initial-scale=1">
  188. <link rel="icon" type="image/x-icon" href="favicon.ico">
  189. </head>
  190. <body>
  191. <app-root></app-root>
  192. </body>
  193. </html>
Add Comment
Please, Sign In to add comment