Guest User

Untitled

a guest
Jun 2nd, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. /**
  2. * Created by Thierry on 28/05/2017.
  3. */
  4. import { Component, OnInit } from '@angular/core';
  5. import { RegisterService } from '../../services/register/register.service';
  6. import { ChatService } from '../../services/chat/chat.service';
  7. import { ProfilService } from '../../services/profil/profil.service';
  8. import { User } from '../../../User';
  9. import { Router } from '@angular/router';
  10. import 'rxjs/add/operator/toPromise';
  11.  
  12. @Component({
  13. moduleId: module.id,
  14. selector: 'profil',
  15. templateUrl: 'profil.component.html',
  16. providers: [ProfilService,ChatService]
  17. })
  18.  
  19. export class ProfilComponent {
  20. //initialisation de notre classe/modele User/ts
  21.  
  22. user : User;
  23. email : string;
  24. pseudo : string;
  25. password: string;
  26. oldPassword: string;
  27. ConfirmPassword: string;
  28. namePicture = '';
  29. isNewUser : boolean;
  30. constructor(private profilService:ProfilService, private registerService:RegisterService, private router:Router){
  31. this.ngOnInit();
  32. }
  33. isNew(pseudo){
  34. pseudo = this.user.pseudo;
  35. console.log("this.isNewUser dans register component: " + this.isNewUser);
  36. if(/*pseudo != null &&this.isNewUser != true*/ this.isNewUser == undefined /*|| this.isNewUser == false*/) {
  37. this.registerService.isNew(pseudo).then(isNewUs => {
  38. //console.log("dans register component" + isNewUs);
  39. if (isNewUs) {
  40. this.isNewUser =isNewUs;
  41. return false;
  42. } else {
  43. this.isNewUser =isNewUs;
  44. return true;
  45. }
  46. });
  47. }else {
  48. if(this.isNewUser){
  49. return false;
  50. }else if(this.isNewUser == false){
  51. return true;
  52. }
  53. }
  54. }
  55. modifyUser(email,pseudo,password,picture){
  56.  
  57. email = this.user.email;
  58. pseudo = this.user.pseudo;
  59. password = this.user.password;
  60. picture = this.user.picture;
  61.  
  62. console.log(email);
  63. console.log(pseudo);
  64.  
  65. //this.profilService.modifyUser(this.user);
  66.  
  67. this.profilService.modifyUser(this.user).then(userModified=>{
  68. console.log("profil component : "+userModified.pseudo);
  69. this.user = userModified;
  70. });
  71.  
  72. }
  73.  
  74. ngOnInit() {
  75. this.user = {
  76. _id: '',
  77. pseudo: '',
  78. email: '',
  79. password: '',
  80. picture:''
  81. }
  82.  
  83. this.profilService.getLoginUsername()
  84. .subscribe(user => {
  85. var myUser = JSON.parse(JSON.stringify(user));
  86.  
  87. this.user = myUser;
  88. this.user.password = '';
  89. this.user.picture = 'http://localhost:3000/public/'+myUser.picture;
  90. });
  91. }
  92. }
Add Comment
Please, Sign In to add comment