aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_pages/profile/profile.component.ts
blob: 4b4746786f0442441b5c893b2e2d1f6694da1da1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Component, OnInit } from '@angular/core';
import User from 'src/app/_data/User';
import { UserInfoService } from 'src/app/_services/user-info.service';

@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {

  user: User = new User();

  username: string = '';
  email: string = '';
  firstName : string = '';
  lastName : string = '';
  oldPass: string = '';
  newPass1: string = '';
  newPass2: string = '';
  photoId: string = '';

  wrongPassBool: boolean = false;
  wrongNewPassBool: boolean = false;

  constructor(private userInfoService: UserInfoService) { }

  ngOnInit(): void {
    this.userInfoService.getUsersInfo().subscribe((response) => {

      this.user = response;

      this.user.password = 'sonja123';

      this.username = this.user.username;
      this.email = this.user.email;
      this.firstName = this.user.firstName;
      this.lastName = this.user.lastName;
      this.photoId = this.user.photoId;
      console.log(this.user);
    });
  }

  saveInfoChanges() {
    let editedUser: User = {
      _id: this.user._id,
      username: this.username,
      email: this.email,
      password: this.user.password,
      firstName: this.firstName,
      lastName: this.lastName,
      photoId: "1"
    }

    this.userInfoService.changeUserInfo(editedUser).subscribe((response: any) =>{
      this.user = editedUser;
      console.log(this.user);
    }, (error: any) =>{
      console.log(error);
    });
  }

  savePasswordChanges() {
    if (this.newPass1 == '' && this.newPass2 == '') //ne zeli da promeni lozinku
      return;
    console.log("zeli da promeni lozinku");
    if (this.newPass1 != this.newPass2) { //netacno ponovio novu lozinku
      this.wrongNewPassBool = true;
      this.newPass1 = '';
      this.newPass2 = '';
      console.log("Netacno ponovljena lozinka");
      return;
    }

    this.wrongPassBool = false;
    this.wrongNewPassBool = false;

    this.userInfoService.changeUserPassword(this.oldPass, this.newPass1).subscribe((response) => {
      this.user = response;
      console.log(this.user);
    }, (error: any) => {

    });
  }

}