-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectwithserver.cpp
More file actions
executable file
·170 lines (154 loc) · 4.8 KB
/
connectwithserver.cpp
File metadata and controls
executable file
·170 lines (154 loc) · 4.8 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
#include "connectwithserver.h"
ConnectWithServer::ConnectWithServer(QObject *parent) :
QObject(parent)
{
manager = new QNetworkAccessManager();
}
void ConnectWithServer::registration(QString firstname,QString secondname,QString mail,QString password)
{
QUrl url("http://viewaide.com/signup.php");
req.setUrl(url);
req.setRawHeader("Host", "viewaide.com");
req.setRawHeader("Content-type", "multipart/form-data, boundary=AyV04a");
req.setRawHeader("Cache-Control", "no-cache");
req.setRawHeader("Accept","*/*");
QByteArray body;
body.append("--AyV04a\r\n");
body.append("Content-disposition: form-data; name=\"firstname\"\r\n");
body.append("\r\n");
body.append(firstname);
body.append("\r\n");
body.append(secondname);
body.append("\r\n");
body.append(mail);
body.append("\r\n");
body.append(password); // ЗАШИФРУЙ МЕНЯ, РАК
body.append("\r\n");
body.append("agree");
body.append("\r\n");
body.append("--AyV04a\r\n");
body.append("Content-Transfer-Encoding: binary\r\n");
body.append("--AyV04a--");
rep=manager->post(req,body);
QEventLoop loop;
connect(rep,SIGNAL(finished()),this,SLOT(regRead()));
loop.exec();
}
void ConnectWithServer::login(QString logIn, QString password)
{
QUrl url("http://viewaide.com/login.php");
req.setUrl(url);
req.setRawHeader("Host", "viewaide.com");
req.setRawHeader("Content-type", "multipart/form-data, boundary=AyV04a");
req.setRawHeader("Cache-Control", "no-cache");
req.setRawHeader("Accept","*/*");
QByteArray body;
body.append("--AyV04a\r\n");
body.append("Content-disposition: form-data; name=\"email\"\r\n");
body.append("\r\n");
body.append(logIn);
body.append("\r\n");
body.append(password);
body.append("\r\n");
body.append("--AyV04a\r\n");
body.append("Content-Transfer-Encoding: binary\r\n");
body.append("--AyV04a--");
rep=manager->post(req, body);
QEventLoop loop;
connect(rep,SIGNAL(finished()),this,SLOT(loginRead()));
loop.exec();
}
void ConnectWithServer::uploadAllData(QString dataToServer, QString surl, QString request_name)
{
QUrl url(surl);
req.setUrl(url);
req.setRawHeader("Host", "viewaide.com");
req.setRawHeader("Content-type", "multipart/form-data, boundary=AyV04a");
req.setRawHeader("Cache-Control", "no-cache");
req.setRawHeader("Accept","*/*");
QByteArray body;
body.append("--AyV04a\r\n");
body.append("Content-disposition: form-data; name=\""+request_name+"\"\r\n");
body.append("\r\n");
body.append(dataToServer);
body.append("\r\n");
body.append("--AyV04a\r\n");
body.append("Content-Transfer-Encoding: binary\r\n");
body.append("--AyV04a--");
rep=manager->post(req, body);
QEventLoop loop;
connect(rep,SIGNAL(finished()),&loop,SLOT(quit()));
loop.exec();
}
bool ConnectWithServer::netIsWorking()
{
req.setUrl(QUrl("http://viewaide.com"));
rep=manager->get(req);
QEventLoop loop;
connect(rep, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if(rep->error()==QNetworkReply::NoError)
return true;
else
return false;
}
void ConnectWithServer::loginRead()
{
if (rep->error() == QNetworkReply::NoError)
{
QByteArray replyBytes;
replyBytes=rep->readAll();
QString message=replyBytes.constData();
QString wordTrue;
bool find(false);
for(int i=0;i<message.length();i++)
{
if((message.at(i)!=' ')&&(message.at(i)!='<')&&(message.at(i)!='>'))
wordTrue.append(message.at(i));
else
{
if(wordTrue=="true")
find=true;
wordTrue="";
}
}
if(find==true)
emit trueLogin();
else
emit falseLogin();
}
else
{
emit notConnectWithServer();
}
}
void ConnectWithServer::regRead()
{
if (rep->error() == QNetworkReply::NoError)
{
QByteArray replyBytes;
replyBytes=rep->readAll();
QString message=replyBytes.constData();
QString wordTrue;
bool find(false);
for(int i=0;i<message.length();i++)
{
if((message.at(i)!=' ')&&(message.at(i)!='<')&&(message.at(i)!='>'))
wordTrue.append(message.at(i));
else
{
if(wordTrue=="true")
find=true;
wordTrue="";
}
}
if(find==true)
emit trueReg();
else
emit falseReg();
}
else
{
emit notConnectWithServer();
}
}