mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-10-29 18:02:29 +00:00
Completing RESTAPI refactor.
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
|
||||
namespace OpenWifi {
|
||||
void RESTAPI_oauth2Handler::DoGet() {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
try {
|
||||
if (!IsAuthorized()) {
|
||||
UnAuthorized("Not authorized.");
|
||||
@@ -59,26 +58,15 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
void RESTAPI_oauth2Handler::DoPost() {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
try {
|
||||
|
||||
// Extract the info for login...
|
||||
std::cout << __LINE__ << std::endl;
|
||||
auto Obj = ParseStream();
|
||||
std::cout << __LINE__ << std::endl;
|
||||
auto userId = GetS(RESTAPI::Protocol::USERID, Obj);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
auto password = GetS(RESTAPI::Protocol::PASSWORD, Obj);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
auto newPassword = GetS(RESTAPI::Protocol::NEWPASSWORD, Obj);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
Poco::toLowerInPlace(userId);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
|
||||
std::cout << __LINE__ << std::endl;
|
||||
|
||||
if(GetBoolParameter(RESTAPI::Protocol::REQUIREMENTS, false)) {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(RESTAPI::Protocol::PASSWORDPATTERN, AuthService()->PasswordValidationExpression());
|
||||
Answer.set(RESTAPI::Protocol::ACCESSPOLICY, RESTAPI_Server()->GetAccessPolicy());
|
||||
@@ -86,10 +74,8 @@ namespace OpenWifi {
|
||||
ReturnObject(Answer);
|
||||
return;
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
|
||||
if(GetBoolParameter(RESTAPI::Protocol::FORGOTPASSWORD,false)) {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
// Send an email to the userId
|
||||
SecurityObjects::UserInfoAndPolicy UInfo;
|
||||
if(AuthService::SendEmailToUser(userId,AuthService::FORGOT_PASSWORD))
|
||||
@@ -98,23 +84,18 @@ namespace OpenWifi {
|
||||
Poco::JSON::Object ReturnObj;
|
||||
UInfo.webtoken.to_json(ReturnObj);
|
||||
ReturnObject(ReturnObj);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
SecurityObjects::UserInfoAndPolicy UInfo;
|
||||
std::cout << __LINE__ << std::endl;
|
||||
|
||||
auto Code=AuthService()->Authorize(userId, password, newPassword, UInfo);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
if (Code==AuthService::SUCCESS) {
|
||||
Poco::JSON::Object ReturnObj;
|
||||
UInfo.webtoken.to_json(ReturnObj);
|
||||
ReturnObject(ReturnObj);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
switch(Code) {
|
||||
case AuthService::INVALID_CREDENTIALS: UnAuthorized("Unrecognized credentials (username/password)."); break;
|
||||
case AuthService::PASSWORD_INVALID: UnAuthorized("Invalid password."); break;
|
||||
@@ -125,12 +106,9 @@ namespace OpenWifi {
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
} catch(const Poco::Exception &E) {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
Logger_.log(E);
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
BadRequest("Internal error has occurred. Please try later.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user