12
12
#include < QNetworkReply>
13
13
#include < QJsonDocument>
14
14
#include < QJsonObject>
15
+ #include < QStandardPaths>
16
+ #include < QFile>
15
17
#include " BackendlessUserAPI.hpp"
16
18
17
19
BackendlessUserAPI::BackendlessUserAPI (QNetworkAccessManager* _networkAccessManager, QString _appId, QString _apiKey, QString _endpoint): QObject(),
18
20
networkAccessManager(_networkAccessManager),
19
21
appId(_appId),
20
22
apiKey(_apiKey),
21
23
endpoint(_endpoint) {
22
-
24
+ readTokenFromDisk ();
25
+ qDebug () << userToken;
23
26
}
24
27
25
28
void BackendlessUserAPI::registerUser (BackendlessRegisterUserRepresentable& user) {
@@ -44,8 +47,8 @@ void BackendlessUserAPI::signInUser(QString login, QString password) {
44
47
this ,
45
48
endpoint + appId + " /" + apiKey + " /users/login" ,
46
49
{
47
- {" login" , login},
48
- {" password" , password}
50
+ {" login" , new StringPostParam ( login) },
51
+ {" password" , new StringPostParam ( password) }
49
52
},
50
53
BERequestMethod::post,
51
54
[&](QNetworkReply* reply){
@@ -69,6 +72,8 @@ void BackendlessUserAPI::signInUser(QString login, QString password) {
69
72
extractResult<BackendlessSignInUser>(
70
73
replyValue,
71
74
[&](auto user) {
75
+ userToken = user.userToken ;
76
+ saveTokenOnDisk ();
72
77
emit signInUserSuccess (user);
73
78
},
74
79
[&](auto beError) {
@@ -83,6 +88,28 @@ void BackendlessUserAPI::signInUser(QString login, QString password) {
83
88
);
84
89
}
85
90
91
+ void BackendlessUserAPI::readTokenFromDisk () {
92
+ auto path = QStandardPaths::writableLocation (QStandardPaths::AppLocalDataLocation);
93
+ auto fileName = path + " /backendless_token.txt" ;
94
+ QFile file (fileName);
95
+ if (file.open (QIODevice::ReadOnly | QIODevice::Text)) {
96
+ QTextStream stream (&file);
97
+ stream >> userToken;
98
+ }
99
+ file.close ();
100
+ }
101
+
102
+ void BackendlessUserAPI::saveTokenOnDisk () {
103
+ auto path = QStandardPaths::writableLocation (QStandardPaths::AppLocalDataLocation);
104
+ auto fileName = path + " /backendless_token.txt" ;
105
+ QFile file (fileName);
106
+ if (file.open (QIODevice::WriteOnly | QIODevice::Text)) {
107
+ QTextStream stream (&file);
108
+ stream << userToken;
109
+ }
110
+ file.close ();
111
+ }
112
+
86
113
void BackendlessUserAPI::validateUserToken () {
87
114
request (
88
115
networkAccessManager,
0 commit comments