-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.cpp
95 lines (88 loc) · 2.54 KB
/
signup.cpp
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
87
88
89
90
91
92
93
94
95
#include "signup.h"
#include "ui_signup.h"
#include "file.h"
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QCryptographicHash>
#include <QMessageBox>
#include <QDebug>
Signup::Signup(QDialog *parent)
: QDialog(parent)
, ui(new Ui::Form), last(nullptr)
{
ui->setupUi(this);
ui->repeat_2->setEchoMode(QLineEdit::Password);
ui->password_2->setEchoMode(QLineEdit::Password);
QRegularExpression re("\\w{3,20}");
QRegularExpressionValidator val(re);
ui->username_2->setValidator(&val);
ui->password_2->setValidator(&val);
ui->repeat_2->setValidator(&val);
// ui->forwards->show();
// ui->backwards->show();
// setModal(true);
// show();
// exec();
}
Signup::~Signup() {
if (last != nullptr) {
last->close();
delete last;
last = nullptr;
}
delete ui;
}
void Signup::on_forwards_clicked() {
if (last != nullptr) {
last->close();
delete last;
last = nullptr;
}
if (ui->username_2->text().length() < 3) {
QLabel *hint = new QLabel(this);
last = hint;
hint->setText("用户名过短。");
hint->setGeometry(130, 210, 200, 30);
hint->show();
return;
}
if (ui->password_2->text().length() < 3) {
QLabel *hint = new QLabel(this);
last = hint;
hint->setText("密码过短。");
hint->setGeometry(130, 210, 200, 30);
hint->show();
return;
}
if (ui->password_2->text() != ui->repeat_2->text()) {
QLabel *hint = new QLabel(this);
last = hint;
hint->setText("两次输入的密码不一致。");
hint->setGeometry(130, 210, 200, 30);
hint->show();
return;
}
auto it = IO.readSingleProfile(ui->username_2->text());
if (it.username != "") {
QLabel *hint = new QLabel(this);
last = hint;
hint->setText("该用户名已被占用。");
hint->setGeometry(130, 210, 200, 30);
hint->show();
return;
}
QMessageBox::information(this, tr("注册成功"),
tr("您现在可以从“本地登录”处登录了。"), QMessageBox::Ok);
close();
GameState ret;
ret.EXP = 1000;
ret.username = ui->username_2->text().toStdString();
ret.password_md5 = QCryptographicHash::hash((ui->password_2->text() +
ui->username_2->text()).toLatin1(), QCryptographicHash::Md5).toStdString();
IO.writeSingleProfile(ret);
return;
}
void Signup::on_backwards_clicked() {
close();
return;
}