-
Notifications
You must be signed in to change notification settings - Fork 6
/
Login.cpp
97 lines (86 loc) · 2.19 KB
/
Login.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
96
97
#include "Login.h"
#include "ui_login.h"
#include <QMessageBox>
#include <QWidget>
Login::Login(QWidget *parent) :
QDialog(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
setFixedSize(400, 300);
setWindowTitle("登录");
ui->userNameLineEdit->setFocus();
ui->loginButton->setDefault(true);
admin = new adminDialog();
gameEntrance = new userNameDialog();
re = new registerDialog();
connect(this, SIGNAL(findUserName(int)), gameEntrance, SLOT(looking(int)));
}
Login::~Login()
{
delete ui;
}
void Login::on_loginButton_clicked()
{
if (ui->pwdLineEdit->text().isEmpty())
{
QMessageBox::information(this, "请输入密码", "请先输入密码", QMessageBox::Ok);
ui->pwdLineEdit->setFocus();
}
if (ui->userNameLineEdit->text().isEmpty())
{
QMessageBox::information(this, "请输入用户名", "请先输入用户名", QMessageBox::Ok);
ui->userNameLineEdit->setFocus();
}
getInfo();
login();
}
void Login::getInfo()
{
QString paths = QDir::currentPath();
QString namePath = paths + "/info/userName.txt";
QString pwdPath = paths + "/info/passWord.txt";
QFile nameFile(namePath);
QFile pwdFile(pwdPath);
QTextStream nameIO(&nameFile);
QTextStream pwdIO(&pwdFile);
nameFile.open(QIODevice::ReadOnly);
pwdFile.open(QIODevice::ReadOnly);
while (!nameIO.atEnd())
{
userNames.push_back(nameIO.readLine());
passWords.push_back(pwdIO.readLine());
}
}
void Login::login()
{
if (ui->pwdLineEdit->text() == "admin" and ui->userNameLineEdit->text() == "admin")
{
admin->show();
hide();
close();
return;
}
for (int i = 0; i < userNames.size(); i++)
{
if (ui->userNameLineEdit->text() == userNames.at(i) and ui->pwdLineEdit->text() == passWords.at(i))
{
gameEntrance->show();
emit findUserName(i);
hide();
return;
}
}
reLoad();
}
void Login::reLoad()
{
ui->userNameLineEdit->clear();
ui->pwdLineEdit->clear();
QMessageBox::warning(this, "waring", "账号或密码错误", QMessageBox::Yes);
}
void Login::on_registButton_clicked()
{
re->show();
//hide();
}