| 170 | } |
| 171 | |
| 172 | bool OsmOAuth::LoginUserPassword(string const & login, string const & password, SessionID const & sid) const |
| 173 | { |
| 174 | auto params = BuildPostRequest({{"username", login}, |
| 175 | {"password", password}, |
| 176 | {"referer", "/"}, |
| 177 | {"commit", "Login"}, |
| 178 | {"authenticity_token", sid.m_authenticityToken}}); |
| 179 | HttpClient request(m_baseUrl + "/login"); |
| 180 | request.SetBodyData(std::move(params), "application/x-www-form-urlencoded") |
| 181 | .SetCookies(sid.m_cookies) |
| 182 | .SetFollowRedirects(true); |
| 183 | if (!request.RunHttpRequest()) |
| 184 | MYTHROW(NetworkError, ("LoginUserPassword Network error while connecting to", request.UrlRequested())); |
| 185 | |
| 186 | // At the moment, automatic redirects handling is buggy on Androids < 4.4. |
| 187 | // set_follow_redirects(false) works only for Android and iOS, while curl still automatically follow all redirects. |
| 188 | if (request.ErrorCode() != HTTP::OK && request.ErrorCode() != HTTP::Found) |
| 189 | MYTHROW(LoginUserPasswordServerError, (DebugPrint(request))); |
| 190 | |
| 191 | // Not redirected page is a 100% signal that login and/or password are invalid. |
| 192 | if (!request.WasRedirected()) |
| 193 | return false; |
| 194 | |
| 195 | // Check if we were redirected to some 3rd party site. |
| 196 | if (request.UrlReceived().find(m_baseUrl) != 0) |
| 197 | MYTHROW(UnexpectedRedirect, (DebugPrint(request))); |
| 198 | |
| 199 | // m_baseUrl + "/login" means login and/or password are invalid. |
| 200 | return request.ServerResponse().find("/login") == string::npos; |
| 201 | } |
| 202 | |
| 203 | bool OsmOAuth::LoginSocial(string const & callbackPart, string const & socialToken, SessionID const & sid) const |
| 204 | { |
nothing calls this directly
no test coverage detected