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