From 138f7654e18b737cb404efd30c6fe2532ae3b84b Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Tue, 26 Apr 2022 10:08:03 -0700 Subject: [PATCH] Adding new registration processing for signup. --- openapi/owprov.yaml | 3 +++ src/RESTAPI/RESTAPI_contact_handler.cpp | 2 +- src/RESTAPI/RESTAPI_signup_handler.cpp | 7 +++++++ src/RESTObjects/RESTAPI_ProvObjects.cpp | 2 ++ src/RESTObjects/RESTAPI_ProvObjects.h | 1 + src/Signup.cpp | 8 ++++++++ src/storage/storage_signup.cpp | 9 ++++++--- src/storage/storage_signup.h | 1 + 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/openapi/owprov.yaml b/openapi/owprov.yaml index bdac989..671bca6 100644 --- a/openapi/owprov.yaml +++ b/openapi/owprov.yaml @@ -1048,6 +1048,9 @@ components: userId: type: string format: uuid + operatorId: + type: string + format: uuid macAddress: type: string serialNumber: diff --git a/src/RESTAPI/RESTAPI_contact_handler.cpp b/src/RESTAPI/RESTAPI_contact_handler.cpp index 5c42032..87334d8 100644 --- a/src/RESTAPI/RESTAPI_contact_handler.cpp +++ b/src/RESTAPI/RESTAPI_contact_handler.cpp @@ -89,7 +89,7 @@ namespace OpenWifi{ return BadRequest(RESTAPI::Errors::NameMustBeSet); } - if(NewObject.entity.empty() || !StorageService()->EntityDB().Exists("id",NewObject.entity)) { + if(NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) { return BadRequest(RESTAPI::Errors::EntityMustExist); } diff --git a/src/RESTAPI/RESTAPI_signup_handler.cpp b/src/RESTAPI/RESTAPI_signup_handler.cpp index b4a8020..3de7ba6 100644 --- a/src/RESTAPI/RESTAPI_signup_handler.cpp +++ b/src/RESTAPI/RESTAPI_signup_handler.cpp @@ -33,6 +33,12 @@ namespace OpenWifi { return BadRequest(RESTAPI::Errors::InvalidRegistrationOperatorName); } + // find the operator id + ProvObjects::Operator SignupOperator; + if(!StorageService()->OperatorDB().GetRecord("registrationId", registrationId, SignupOperator)) { + return BadRequest(RESTAPI::Errors::InvalidRegistrationOperatorName); + } + // if a signup already exists for this user, we should just return its value completion SignupDB::RecordVec SEs; if(StorageService()->SignupDB().GetRecords(0,100, SEs, " email='" + UserName + "' and serialNumber='"+macAddress+"' ")) { @@ -113,6 +119,7 @@ namespace OpenWifi { SE.deviceID = deviceID; SE.registrationId = registrationId; SE.status = "waiting-for-email-verification"; + SE.operatorId = SignupOperator.info.id; SE.statusCode = ProvObjects::SignupStatusCodes::SignupWaitingForEmail; StorageService()->SignupDB().CreateRecord(SE); Signup()->AddOutstandingSignup(SE); diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index 6720636..5eb0c2c 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -896,6 +896,7 @@ namespace OpenWifi::ProvObjects { field_to_json( Obj,"statusCode", statusCode); field_to_json( Obj,"deviceID", deviceID); field_to_json( Obj,"registrationId",registrationId); + field_to_json( Obj,"operatorId",operatorId); } bool SignupEntry::from_json(const Poco::JSON::Object::Ptr &Obj) { @@ -912,6 +913,7 @@ namespace OpenWifi::ProvObjects { field_from_json( Obj,"statusCode", statusCode); field_from_json( Obj,"deviceID", deviceID); field_from_json( Obj,"registrationId",registrationId); + field_from_json( Obj,"operatorId",operatorId); return true; } catch(...) { diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 091e31c..8a936b4 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -534,6 +534,7 @@ namespace OpenWifi::ProvObjects { uint64_t statusCode=0; std::string deviceID; std::string registrationId; + std::string operatorId; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); diff --git a/src/Signup.cpp b/src/Signup.cpp index da93375..8048355 100644 --- a/src/Signup.cpp +++ b/src/Signup.cpp @@ -85,10 +85,18 @@ namespace OpenWifi { // we need to move this device to the SubscriberDevice DB ProvObjects::SubscriberDevice SD; + SD.info.id = MicroService::CreateUUID(); + SD.info.modified = SD.info.created = OpenWifi::Now(); + SD.info.name = IT.realMacAddress; + SD.operatorId = SE.operatorId; SD.serialNumber = SerialNumber; SD.realMacAddress = SE.macAddress; SD.locale = IT.locale; SD.deviceType = IT.deviceType; + SD.state = OS.str(); + SD.subscriberId = SE.userId; + StorageService()->SubscriberDeviceDB().DeleteRecord("serialNumber", SD.serialNumber); + StorageService()->SubscriberDeviceDB().CreateRecord(SD); SE.status = "signup completed"; SE.serialNumber = SerialNumber; diff --git a/src/storage/storage_signup.cpp b/src/storage/storage_signup.cpp index 6d2eb10..c10893a 100644 --- a/src/storage/storage_signup.cpp +++ b/src/storage/storage_signup.cpp @@ -31,18 +31,19 @@ namespace OpenWifi { ORM::Field{"statusCode",ORM::FieldType::FT_BIGINT}, ORM::Field{"macAddress",ORM::FieldType::FT_TEXT}, ORM::Field{"deviceID",ORM::FieldType::FT_TEXT}, - ORM::Field{"registrationId",ORM::FieldType::FT_TEXT} + ORM::Field{"registrationId",ORM::FieldType::FT_TEXT}, + ORM::Field{"operatorId",ORM::FieldType::FT_TEXT} }; const static ORM::IndexVec SignupDB_Indexes{ - { std::string("signup4_email_index"), + { std::string("signup5_email_index"), ORM::IndexEntryVec{ {std::string("email"), ORM::Indextype::ASC} } } }; SignupDB::SignupDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) noexcept : - DB(T, "signups4", SignupDB_Fields, SignupDB_Indexes, P, L, "sig") { + DB(T, "signups5", SignupDB_Fields, SignupDB_Indexes, P, L, "sig") { } bool SignupDB::GetIncompleteSignups(SignupDB::RecordVec &Signups) { @@ -137,6 +138,7 @@ template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects: Out.macAddress = In.get<14>(); Out.deviceID = In.get<15>(); Out.registrationId = In.get<16>(); + Out.operatorId = In.get<17>(); } template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects::SignupEntry>::Convert(const OpenWifi::ProvObjects::SignupEntry &In, OpenWifi::SignupDBRecordType &Out) { @@ -157,4 +159,5 @@ template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects: Out.set<14>(In.macAddress); Out.set<15>(In.deviceID); Out.set<16>(In.registrationId); + Out.set<17>(In.operatorId); } diff --git a/src/storage/storage_signup.h b/src/storage/storage_signup.h index c0dafbd..8343f1a 100644 --- a/src/storage/storage_signup.h +++ b/src/storage/storage_signup.h @@ -25,6 +25,7 @@ namespace OpenWifi { uint64_t, std::string, std::string, + std::string, std::string > SignupDBRecordType;