-
Notifications
You must be signed in to change notification settings - Fork 0
/
logindialog.cpp
81 lines (72 loc) · 1.92 KB
/
logindialog.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
#include "logindialog.h"
#include "ui_logindialog.h"
#include "mainwindow.h"
#include "adminwindow.h"
#include <QMessageBox>
#include <QLineEdit>
#define tr QString::fromLocal8Bit
using namespace sjtu;
loginDialog::loginDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::loginDialog)
{
ui->setupUi(this);
}
loginDialog::~loginDialog()
{
delete ui;
}
void loginDialog::loadRM(shared_ptr<RailwayMinistry> _rm){
rm=_rm;
}
string loginDialog::getID(){
return ui->usr->text().toStdString();
}
bool loginDialog::isAdmin(){
return ui->checkBox_2->isChecked();
}
void loginDialog::on_login_clicked()
{
string id=ui->usr->text().toStdString();
string pwd=ui->pwd->text().toStdString();
if(rm->isUser(id,pwd)){
if(ui->checkBox_2->isChecked()){
if(rm->isAdmin(id)){
accept();
}else{
QMessageBox::warning(this,QString::fromLocal8Bit("警告"),tr("你没有管理员权限"));
}
}else{
accept();
}
}else{
QMessageBox::warning(this, tr("警告!"),
tr("用户名或密码错误!"),
QMessageBox::Yes);
}
}
void loginDialog::on_reg_clicked()
{
string id=ui->usr->text().toStdString();
string pwd=ui->pwd->text().toStdString();
if(rm->regiser(id,pwd,id)){
QMessageBox::information(this, tr("提示"),
tr("注册成功!"),
QMessageBox::Yes);
}else{
QMessageBox::warning(this, tr("警告!"),
tr("用户名已使用"),
QMessageBox::Yes);
}
}
void loginDialog::on_checkBox_stateChanged(int arg1)
{
if(ui->checkBox->isChecked())
ui->pwd->setEchoMode(QLineEdit::Normal);
else
ui->pwd->setEchoMode(QLineEdit::Password);
}
void loginDialog::on_checkBox_2_stateChanged(int arg1)
{
}
#undef tr