Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Thierry on 28/05/2017.
- */
- import { Component, OnInit } from '@angular/core';
- import { RegisterService } from '../../services/register/register.service';
- import { ChatService } from '../../services/chat/chat.service';
- import { ProfilService } from '../../services/profil/profil.service';
- import { User } from '../../../User';
- import { Router } from '@angular/router';
- import 'rxjs/add/operator/toPromise';
- @Component({
- moduleId: module.id,
- selector: 'profil',
- templateUrl: 'profil.component.html',
- providers: [ProfilService,ChatService]
- })
- export class ProfilComponent {
- //initialisation de notre classe/modele User/ts
- user : User;
- email : string;
- pseudo : string;
- password: string;
- oldPassword: string;
- ConfirmPassword: string;
- namePicture = '';
- isNewUser : boolean;
- constructor(private profilService:ProfilService, private registerService:RegisterService, private router:Router){
- this.ngOnInit();
- }
- isNew(pseudo){
- pseudo = this.user.pseudo;
- console.log("this.isNewUser dans register component: " + this.isNewUser);
- if(/*pseudo != null &&this.isNewUser != true*/ this.isNewUser == undefined /*|| this.isNewUser == false*/) {
- this.registerService.isNew(pseudo).then(isNewUs => {
- //console.log("dans register component" + isNewUs);
- if (isNewUs) {
- this.isNewUser =isNewUs;
- return false;
- } else {
- this.isNewUser =isNewUs;
- return true;
- }
- });
- }else {
- if(this.isNewUser){
- return false;
- }else if(this.isNewUser == false){
- return true;
- }
- }
- }
- modifyUser(email,pseudo,password,picture){
- email = this.user.email;
- pseudo = this.user.pseudo;
- password = this.user.password;
- picture = this.user.picture;
- console.log(email);
- console.log(pseudo);
- //this.profilService.modifyUser(this.user);
- this.profilService.modifyUser(this.user).then(userModified=>{
- console.log("profil component : "+userModified.pseudo);
- this.user = userModified;
- });
- }
- ngOnInit() {
- this.user = {
- _id: '',
- pseudo: '',
- email: '',
- password: '',
- picture:''
- }
- this.profilService.getLoginUsername()
- .subscribe(user => {
- var myUser = JSON.parse(JSON.stringify(user));
- this.user = myUser;
- this.user.password = '';
- this.user.picture = 'http://localhost:3000/public/'+myUser.picture;
- });
- }
- }
Add Comment
Please, Sign In to add comment