Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { LoginService } from '../../services/login/login.service';
  3. import { ChatService } from '../../services/chat/chat.service';
  4. import { User } from '../../../User';
  5. import { Router } from '@angular/router';
  6. import {initialRouterNavigation} from "@angular/router/src/router_module";
  7. import {ChatComponent} from "../chat/chat.component";
  8. import 'rxjs/add/operator/toPromise';
  9.  
  10. @Component({
  11. moduleId: module.id,
  12. selector: 'login',
  13. templateUrl: 'login.component.html',
  14. providers: [LoginService,ChatService]
  15. })
  16.  
  17. export class LoginComponent {
  18. //initialisation de notre classe/modele User/ts
  19.  
  20. user : User;
  21. email : string;
  22. newEmail : string;
  23. pseudo : string;
  24. newPassword : string;
  25. secretAnswer : string;
  26.  
  27. ConfirmPassword: string;
  28. isGood:boolean;
  29. isSecret = false;
  30.  
  31. isResetPass=false;
  32.  
  33. constructor(private loginService:LoginService, private router:Router){
  34.  
  35. console.log("yaaaaaaaaaaaaaaaaaaaa ");
  36. }
  37.  
  38. isResetPassword(){
  39. this.isResetPass = true;
  40. return this.isResetPass;
  41. }
  42.  
  43. isSecretOK(){
  44. let userByEmail={
  45. email : this.newEmail
  46. }
  47.  
  48. this.loginService.getUserByEmail(userByEmail).then(userRes=>{
  49. console.log("login component userRes: "+userRes.pseudo);
  50. if(userRes.secret == this.secretAnswer){
  51. this.isSecret = true;
  52. }else {
  53. this.isSecret = false;
  54. }
  55. });
  56. }
  57.  
  58. reset(){
  59. let newUser={
  60. email : this.newEmail,
  61. password : this.newPassword,
  62. secret : this.secretAnswer
  63. }
  64.  
  65. this.loginService.resetPassword(newUser).then(userRes=>{
  66. console.log("login component userRes: "+userRes.pseudo);
  67. this.user = userRes;
  68. this.isSecret = false;
  69. this.isResetPass = false;
  70. this.user.password ='';
  71. });
  72.  
  73. }
  74.  
  75. isTrue(email,password){
  76. let newUser={
  77. email : this.user.email,
  78. password : this.user.password,
  79. }
  80. console.log("login comp email: "+email);
  81.  
  82. this.loginService.getUser(newUser).then(userLogged=>{
  83. console.log(userLogged.exist);
  84. if(userLogged.exist){
  85. this.router.navigate(['/home',userLogged.pseudo]);
  86. }else{
  87. this.router.navigate([]);
  88. }
  89. });
  90. }
  91. /*
  92. validSecret(nEmail,secret){
  93. let newUser={
  94. email : nEmail,
  95. secret : secret
  96. };
  97.  
  98. this.loginService.validSecret(newUser).then(secretIsValid=>{
  99. console.log(secretIsValid);
  100. if(secretIsValid){
  101. this.isSecret = true;
  102. return this.isSecret;
  103. }else{
  104. this.isSecret = false;
  105. return this.isSecret;
  106. }
  107. });
  108. }
  109. */
  110.  
  111. /*
  112. isTrue(pseudo,password){
  113. let newUser={
  114. pseudo : this.user.pseudo,
  115. password : this.user.password
  116. }
  117. console.log("login comp pseudo: "+pseudo);
  118.  
  119. this.loginService.getUser(newUser).then(logged=>{
  120. console.log(logged);
  121. if(logged){
  122. this.router.navigate(['/profil']);
  123. }else{
  124. this.router.navigate([]);
  125. }
  126. });
  127. }
  128. */
  129. ngOnInit() {
  130. this.user = {
  131. _id: '',
  132. pseudo: '',
  133. email: '',
  134. password: '',
  135. picture:'',
  136. bio:'',
  137. birthday: new Date(''),
  138. status:'',
  139. exist:true,
  140. secret:''
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement