Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. | app.component.css
  2. | app.component.html
  3. | app.component.ts
  4. | app.module.ts
  5. | app.routing.ts
  6. | index.ts
  7. |
  8. +---errors
  9. | error.component.html
  10. | error.component.ts
  11. | error.model.ts
  12. | error.service.ts
  13. |
  14. +---protected
  15. | protected.component.ts
  16. | protected.guard.ts
  17. |
  18. +---shared
  19. | auth.service.ts
  20. | header.component.ts
  21. | index.ts
  22. | user.interface.ts
  23. |
  24. ---unprotected
  25. signin.component.ts
  26. signup.component.ts
  27.  
  28. export class Error {
  29. constructor(public title: string, public message: string) {}
  30. }
  31.  
  32. export class ErrorComponent implements OnInit{
  33. error: Error;
  34. display = 'none';
  35.  
  36. constructor(private errorService: ErrorService) {}
  37.  
  38. onErrorHandled() {
  39. this.display = 'none';
  40. }
  41.  
  42. ngOnInit() {
  43. this.errorService.errorOccurred.subscribe(
  44. (error: Error) => {
  45. this.error = error;
  46. this.display = 'block';
  47. }
  48. );
  49. }
  50. }
  51.  
  52. <div class="backdrop" [ngStyle]="{'display': display}"></div>
  53. <div class="modal" tabindex="-1" role="dialog" [ngStyle]="{'display': display}">
  54. <div class="modal-dialog" role="document">
  55. <div class="modal-content">
  56. <div class="modal-header">
  57. <button type="button" class="close" aria-label="Close" (click)="onErrorHandled()"><span aria-hidden="true">&times;</span></button>
  58. <h4 class="modal-title">{{ error?.title }}</h4>
  59. </div>
  60. <div class="modal-body">
  61. <p>{{ error?.message }}</p>
  62. </div>
  63. <div class="modal-footer">
  64. <button type="button" class="btn btn-default" data-dismiss="modal" (click)="onErrorHandled()">Close</button>
  65. </div>
  66. </div><!-- /.modal-content -->
  67. </div><!-- /.modal-dialog -->
  68. </div><!-- /.modal -->
  69.  
  70. declare var firebase: any;
  71.  
  72. @Injectable()
  73. export class AuthService {
  74.  
  75. constructor(private router: Router, private errorService: ErrorService) {}
  76.  
  77. signupUser(user:User) {
  78. firebase.auth().createUserWithEmailAndPassword(user.email, user.password)
  79. .catch(function (error) {
  80. this.errorService.handleError(error.json());
  81. return Observable.throw(error.json());
  82. });
  83. }
  84. signinUser(user:User) {
  85. firebase.auth().signInWithEmailAndPassword(user.email, user.password)
  86. .catch(function (error) {
  87. this.errorService.handleError(error.json());
  88. return Observable.throw(error.json());
  89. });
  90. }
  91. }
  92.  
  93. this.errorService.handleError(error.json());
  94. return Observable.throw(error.json());
  95.  
  96. console.log(error)
  97.  
  98. .catch(function(error) {
  99. // Handle Errors here.
  100. var errorCode = error.code;
  101. var errorMessage = error.message;
  102. // The email of the user's account used.
  103. var email = error.email;
  104. // The firebase.auth.AuthCredential type that was used.
  105. var credential = error.credential;
  106. // ...
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement