-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
180 lines (151 loc) · 4.56 KB
/
Copy pathsettings.cpp
File metadata and controls
180 lines (151 loc) · 4.56 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "settings.h"
#include "ui_settings.h"
#include"question_edit.h"
#include<QButtonGroup>
#include<QFile>
#include<QTextStream>
#include<QDebug>
#include<QCheckBox>
#include"user.h"
#include<QList>
#include<QMessageBox>
#include"user_info.h"
extern QList <USER> list;
extern USER succeed;
Settings::Settings(QWidget *parent) :
QDialog(parent),
ui(new Ui::Settings)
{
ui->setupUi(this);
this->setWindowTitle("设置");
if(succeed.name_permit==1){
ui->name_permit->setCheckState(Qt::Checked);
}
else{
ui->name_permit->setCheckState(Qt::Unchecked);
}
if(succeed.phone_permit==1){
ui->number_permit->setCheckState(Qt::Checked);
}
else{
ui->number_permit->setCheckState((Qt::Unchecked));
}
if(succeed.verti_way==1){
ui->no_certi->setCheckState((Qt::Checked));
ui->question->setCheckState(Qt::Unchecked);
}
else{
ui->no_certi->setCheckState((Qt::Unchecked));
ui->question->setCheckState(Qt::Checked);
}
}
Settings::~Settings()
{
delete ui;
}
void Settings::on_question_clicked(bool checked)
{
if(checked){
ui->no_certi->setCheckState(Qt::Unchecked);
question_edit *pic;
pic=new question_edit;
this->close();
pic->show();
}
else ui->no_certi->setCheckState(Qt::Checked);
}
void Settings::buttonex(){
// QButtonGroup *box1=new QButtonGroup;
// box1->setExclusive(true);
// box1->addButton(ui->all_can);
// box1->addButton(ui->only_yourself);
QButtonGroup *box2=new QButtonGroup;
box2->setExclusive(true);
box2->addButton(ui->no_certi);
box2->addButton(ui->question);
}
void Settings::on_number_permit_clicked(bool checked)
{
if(checked)succeed.phone_permit=1;
else succeed.phone_permit=0;
}
void Settings::on_no_certi_clicked(bool checked)
{
if(!checked){
succeed.verti_way=0;
question_edit *pic=new question_edit;
this->close();
pic->show();
}
else succeed.verti_way=1,succeed.question="";
}
void Settings::on_name_permit_clicked(bool checked)
{
if(checked)succeed.name_permit=1;
else succeed.name_permit=0;
}
void Settings::on_confirm_clicked()
{
QString newname=ui->newName->text();
QString psw=ui->originPsw->text();
QString newpsw=ui->newPsw->text();
int flag=1;
QRegExp rx_psw;
rx_psw.setPatternSyntax(QRegExp::RegExp);
rx_psw.setCaseSensitivity(Qt::CaseSensitive);
rx_psw.setPattern(QString("^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?![A-Z0-9]+$)(?![a-zA-Z]+$)(?![a-z0-9]+$)[a-zA-Z0-9]{8,}"));
if(newname.indexOf(" ")!=-1||newname.indexOf("-")!=-1){
QMessageBox::critical(this,tr("警告"),tr("昵称不允许有空格或 - 号"));
flag=0;
}
else if(newname!="")succeed.name=newname,flag=1;
if(psw!=succeed.password&&psw!="")QMessageBox::critical(this,tr("警告"),tr("原密码不正确,请改正!")),flag=0;
if(psw==succeed.password){
if(newpsw=="")QMessageBox::critical(this,tr("警告"),tr("新密码不能为空,请改正!")),flag=0;
else if(!rx_psw.exactMatch(newpsw)){
QMessageBox::critical(this,tr("警告"),tr("新密码应由至少8位的大小写字母和数字组成,不允许特殊字符,请改正!"));
flag=0;
}
else if(rx_psw.exactMatch(newpsw)){
succeed.password=newpsw;
flag=1;
}
}
if(flag==1){
for(int i=0;i<list.size();i++){
if(succeed.phone==list[i].phone){
list[i]=succeed;
}
}
//重写文件
QFile file1("users.txt");
if(file1.open(QIODevice::WriteOnly|QIODevice::Truncate)){
QTextStream out(&file1);
out.setCodec("UTF-8");
for(int i=0;i<list.size();i++){
out<<QString(list[i].name)<<" "
<<QString(list[i].phone)<<" "<<QString(list[i].password)<<" "<<list[i].name_permit<<" "
<<list[i].phone_permit<<" "<<list[i].verti_way<<endl;
}
//file1.flush();
file1.close();
}else{
qDebug()<<file1.errorString()<<endl;
}
QFile file2("question.txt");
if(file2.open(QIODevice::WriteOnly|QIODevice::Truncate)){
QTextStream out(&file2);
out.setCodec("UTF-8");
for(int i=0;i<list.size();i++){
if(list[i].question!="")out<<list[i].phone<<" "<<list[i].question<<endl;
}
file2.close();
}else{
qDebug()<<file1.errorString()<<endl;
}
update();
this->close();
User *pic=new User;
pic->show();
}
}