Fixing submfa method

This commit is contained in:
stephb9959
2021-12-08 22:41:24 -08:00
parent 5eecfbfd30
commit 916d5cdf13
3 changed files with 5 additions and 24 deletions

2
build
View File

@@ -1 +1 @@
99
100

View File

@@ -31,27 +31,18 @@ namespace OpenWifi {
NotFound();
}
#define DBGLINE std::cout << __FILE__ << " : " << __LINE__ << std::endl;
void RESTAPI_submfa_handler::DoPut() {
std::cout << "DoPut..." << std::endl;
try {
DBGLINE
auto Body = ParseStream();
DBGLINE
SecurityObjects::SubMfaConfig MFC;
DBGLINE
if (!MFC.from_json(Body)) {
DBGLINE
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if (MFC.type == "disabled") {
DBGLINE
SecurityObjects::UserInfo User;
StorageService()->GetUserById(UserInfo_.userinfo.Id, User);
User.userTypeProprietaryInfo.mfa.enabled = false;
@@ -59,10 +50,8 @@ namespace OpenWifi {
Poco::JSON::Object Answer;
MFC.to_json(Answer);
DBGLINE
return ReturnObject(Answer);
} else if (MFC.type == "email") {
DBGLINE
SecurityObjects::UserInfo User;
StorageService()->GetUserById(UserInfo_.userinfo.Id, User);
@@ -72,44 +61,36 @@ namespace OpenWifi {
Poco::JSON::Object Answer;
MFC.to_json(Answer);
DBGLINE
return ReturnObject(Answer);
} else if (MFC.type == "sms") {
DBGLINE
if (GetBoolParameter("startValidation", false)) {
DBGLINE
if (MFC.sms.empty()) {
return BadRequest("Missing phone number");
}
DBGLINE
if (SMSSender()->StartValidation(MFC.sms, UserInfo_.userinfo.email)) {
return OK();
} else {
return InternalError("SMS could not be sent. Verify the number or try again later.");
}
DBGLINE
} else if (GetBoolParameter("completeValidation", false)) {
auto ChallengeCode = GetParameter("challengeCode", "");
if (ChallengeCode.empty()) {
DBGLINE
return BadRequest("Missing 'challengeCode'");
}
if (MFC.sms.empty()) {
DBGLINE
return BadRequest("Missing phone number");
}
if (SMSSender()->CompleteValidation(MFC.sms, ChallengeCode, UserInfo_.userinfo.email)) {
SecurityObjects::UserInfo User;
DBGLINE
StorageService()->GetUserById(UserInfo_.userinfo.Id, User);
User.userTypeProprietaryInfo.mfa.enabled = true;
User.userTypeProprietaryInfo.mfa.method = "sms";
SecurityObjects::MobilePhoneNumber PhoneNumber;
PhoneNumber.number = MFC.sms;
PhoneNumber.primary = true;
PhoneNumber.verified = true;
User.userTypeProprietaryInfo.mfa.enabled = true;
User.userTypeProprietaryInfo.mobiles.clear();
User.userTypeProprietaryInfo.mobiles.push_back(PhoneNumber);
StorageService()->UpdateUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.Id, User);
@@ -117,17 +98,15 @@ namespace OpenWifi {
Poco::JSON::Object Answer;
MFC.to_json(Answer);
return ReturnObject(Answer);
} else {
DBGLINE
return InternalError("SMS could not be sent. Verify the number or try again later.");
}
}
}
} catch (const Poco::Exception &E) {
DBGLINE
Logger_.log(E);
}
DBGLINE
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}

View File

@@ -74,6 +74,8 @@ using namespace std::chrono_literals;
#include "ow_version.h"
#define _OWDBG_ std::cout << __FILE__ << " : " << __LINE__ << std::endl;
namespace OpenWifi {
enum UNAUTHORIZED_REASON {