-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.cpp
More file actions
74 lines (67 loc) · 2.19 KB
/
profile.cpp
File metadata and controls
74 lines (67 loc) · 2.19 KB
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
#include "profile.h"
#include "ui_profile.h"
#include <QMessageBox>
#include "userstorage.h"
Profile::Profile(const QString& _username, GameMenu *parentPage, QWidget *parent)
: QDialog(parent)
, ui(new Ui::Profile)
, gamemenu(parentPage)
, username(_username)
{
ui->setupUi(this);
loadUserData();
}
Profile::~Profile()
{
delete ui;
}
void Profile::on_cancelButton_clicked()
{
gamemenu->show();
this->hide();
}
void Profile::on_EditButtom_clicked()
{
QString newName = ui->nameLine->text().trimmed();
QString newLastName = ui->lastnameLine->text().trimmed();
QString newPhone = ui->phonenoLine->text().trimmed();
QString newEmail = ui->emailLine->text().trimmed();
if (newName.isEmpty() || newLastName.isEmpty() || newPhone.isEmpty() || newEmail.isEmpty()) {
QMessageBox::warning(this, "Incomplete Data", "Please fill all fields.");
return;
}
QStringList newFields = {
username,
oldHashedPassword,
newName,
newLastName,
newPhone,
newEmail
};
if (UserStorage::updateUserProfile(username, newFields)) {
QMessageBox::information(this, "Success", "Profile edited!");
this->hide();
gamemenu->show();
} else {
QMessageBox::critical(this, "Error", "Could not update profile.");
}
}
void Profile::loadUserData()
{
QStringList fields;
if (UserStorage::loadUserProfile(username, fields)) {
if (fields.size() >= 6) {
oldHashedPassword = fields[1];
ui->nameLine->setText(fields[2]);
ui->lastnameLine->setText(fields[3]);
ui->phonenoLine->setText(fields[4]);
ui->emailLine->setText(fields[5]);
} else {
QMessageBox::critical(this, "Error", "User data corrupted!");
this->close();
}
} else {
QMessageBox::critical(this, "Error", "User not found!");
this->close();
}
}