Repository navigation
Expand file tree
/
Copy pathfirstwindow.cpp
More file actions
89 lines (84 loc) · 2.27 KB
/
Copy pathfirstwindow.cpp
File metadata and controls
89 lines (84 loc) · 2.27 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "firstwindow.h"
#include "ui_firstwindow.h"
#include "userpage.h"
#include "adminpage.h"
#include "user.h"
#include <QValidator>
#include "signuppage.h"
#include "errors.h"
#include "dialog.h"
extern vector<User>vecuser;
extern User CEO;
extern QString DIALOGMSG;
FirstWindow::FirstWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::FirstWindow)
{
ui->setupUi(this);
//设置非法输入
//账号
QRegularExpression regx("[a-zA-Z0-9\-\\\_]{11}");
QValidator *validator = new QRegularExpressionValidator(regx,ui->lineEdit);
ui->lineEdit->setValidator(validator);
//密码
QRegularExpression regx2("[a-zA-Z0-9\-\\\_]{16}");
QValidator *validator2 = new QRegularExpressionValidator(regx2,ui->lineEdit_2);
ui->lineEdit_2->setValidator(validator2);
}
FirstWindow::~FirstWindow()
{
delete ui;
}
//登录按钮
void FirstWindow::on_pushButton_clicked()
{
string account = ui->lineEdit->text().toStdString();
string password = ui->lineEdit_2->text().toStdString();
//检查用户输入的账号
//管理员账号
if(account == "admin" && password == "000000") {
auto a = new adminPage;
a->show();
this->close();
}else{
try {
int flag = CEO.Login(account,password);
if(flag == 1){
this->close();
userPage *u = new userPage;
u->show();
}
else if(flag == 0){
DIALOGMSG = "密码错误";
auto d = new Dialog;
d->show();
}
else if(flag == -1){
DIALOGMSG = "该电话号码未注册";
auto d = new Dialog;
d->show();
}
} catch (fileError &e) {
DIALOGMSG = e.what();
auto d = new Dialog;
d->show();
}
}
}
//由于限制输入,回车不能用于触发登录
//注册按钮
void FirstWindow::on_pushButton_2_clicked()
{
auto s = new signUpPage;
s->show();
this->close();
}
//显示密码
void FirstWindow::on_checkBox_stateChanged(int arg1)
{
if(ui->checkBox->isChecked()){
ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
}else{
ui->lineEdit_2->setEchoMode(QLineEdit::Password);
}
}