Guest User

Untitled

a guest
Nov 21st, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { AuthService } from '../../Services/auth.service';
  4.  
  5. @Component({
  6. templateUrl: './login.component.html',
  7. })
  8. export class LoginComponent {
  9. message: string;
  10. constructor(public authService: AuthService, public router: Router) {
  11. this.setMessage();
  12. }
  13.  
  14. setMessage() {
  15. this.message = 'Logged ' + (this.authService.isLoggedIn ? 'in' : 'out');
  16. }
  17.  
  18. login() {
  19. this.message = 'Trying to log in ...';
  20.  
  21. this.authService.login().subscribe(() => {
  22. this.setMessage();
  23. if (this.authService.isLoggedIn) {
  24. // Get the redirect URL from our auth service
  25. // If no redirect has been set, use the default
  26. let redirect = this.authService.redirectUrl ? this.authService.redirectUrl : '/home';
  27.  
  28. // Redirect the user
  29. this.router.navigate([redirect]);
  30. }
  31. });
  32. }
  33.  
  34. logout() {
  35. this.authService.logout();
  36. this.setMessage();
  37. }
  38.  
  39.  
  40. }
  41.  
  42. <h1>Please login to proceed</h1>
  43. <br />
  44. <br />
  45. <form >
  46. <table border="0">
  47. <tr>
  48. <td>
  49. <div class="form-group">
  50. <label for="uname" style="display: inline-block">Username:* &emsp;</label>
  51. </div>
  52. </td>
  53. <td>
  54. <div class="form-group">
  55. <input style="display: inline-block" id="uname" type="text" class="form-control"
  56. placeholder="Username">
  57. </div>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td>
  62. <div class="form-group">
  63. <label for="pwd" style="display: inline-block">Password:* &emsp;</label>
  64. </div>
  65. </td>
  66. <td>
  67. <div class="form-group">
  68. <input style="display: inline-block" type="password" class="form-control"
  69. placeholder="Password">
  70. </div>
  71. </td>
  72. </tr>
  73. <tr>
  74. <td>
  75. <p style="color: red">* Required Fields</p>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td>
  80. <p>
  81. <button class="btn btn-info" (click)="login()" *ngIf="!authService.isLoggedIn">Login</button>
  82. </p>
  83. </td>
  84. </table>
  85. </form>
Add Comment
Please, Sign In to add comment