MCPcopy Create free account
hub / github.com/comaps/comaps / LoginUserPassword

Method LoginUserPassword

libs/editor/osm_auth.cpp:172–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172bool 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
203bool OsmOAuth::LoginSocial(string const & callbackPart, string const & socialToken, SessionID const & sid) const
204{

Callers

nothing calls this directly

Calls 6

BuildPostRequestFunction · 0.85
ErrorCodeMethod · 0.80
WasRedirectedMethod · 0.80
DebugPrintFunction · 0.70
RunHttpRequestMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected