| 150 | } |
| 151 | |
| 152 | bool NetworkService::login(LoginErrorCode& errorCode, std::string const& userName, std::string const& password, UserInfo const& userInfo) |
| 153 | { |
| 154 | log(Priority::Important, "network: login user '" + userName + "'"); |
| 155 | |
| 156 | httplib::SSLClient client(_serverAddress); |
| 157 | configureClient(client); |
| 158 | |
| 159 | httplib::Params params; |
| 160 | params.emplace("userName", userName); |
| 161 | params.emplace("password", password); |
| 162 | if (userInfo.gpu) { |
| 163 | params.emplace("gpu", *userInfo.gpu); |
| 164 | } |
| 165 | |
| 166 | try { |
| 167 | auto result = executeRequest([&] { return client.Post("/alien-server/login.php", params); }); |
| 168 | |
| 169 | auto boolResult = parseBoolResult(result->body); |
| 170 | if (boolResult) { |
| 171 | _loggedInUserName = userName; |
| 172 | _password = password; |
| 173 | } |
| 174 | |
| 175 | errorCode = 0; |
| 176 | std::stringstream stream(result->body); |
| 177 | boost::property_tree::ptree tree; |
| 178 | boost::property_tree::read_json(stream, tree); |
| 179 | errorCode = tree.get<LoginErrorCode>("errorCode"); |
| 180 | |
| 181 | return boolResult; |
| 182 | } catch (...) { |
| 183 | logNetworkError(); |
| 184 | return false; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | bool NetworkService::logout() |
| 189 | { |
no test coverage detected