diff --git a/build b/build index da2d398..3f10ffe 100644 --- a/build +++ b/build @@ -1 +1 @@ -14 \ No newline at end of file +15 \ No newline at end of file diff --git a/openpapi/owsec.yaml b/openpapi/owsec.yaml index 7c23a8c..ae8bc20 100644 --- a/openpapi/owsec.yaml +++ b/openpapi/owsec.yaml @@ -355,6 +355,9 @@ components: format: int64 userTypeProprietaryInfo: $ref: '#/components/schemas/UserLoginLoginExtensions' + signupUUID: + type: string + format: uuid UserList: type: object @@ -1465,8 +1468,8 @@ paths: schema: type: integer format: int64 - required: required - example: 1,2,3 + example: 1,2,3 + required: true responses: 200: description: Succesful posting of response. @@ -1505,16 +1508,7 @@ paths: required: true responses: 200: - description: Success signup post - content: - application/json: - schema: - type: - object - properties: - signupUUID: - type: string - format: uuid + $ref: '#/components/schemas/UserInfo' 400: $ref: '#/components/responses/BadRequest' 403: diff --git a/src/ActionLinkManager.cpp b/src/ActionLinkManager.cpp index 8fc30ea..0a8357f 100644 --- a/src/ActionLinkManager.cpp +++ b/src/ActionLinkManager.cpp @@ -39,13 +39,10 @@ namespace OpenWifi { continue; for(auto &i:Links) { - std::cout << "Sending email " << __LINE__ << std::endl; if(!Running_) break; - std::cout << "Sending email " << __LINE__ << std::endl; SecurityObjects::UserInfo UInfo; - std::cout << "Sending email " << __LINE__ << std::endl; if((i.action==OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD || i.action==OpenWifi::SecurityObjects::LinkActions::VERIFY_EMAIL) && !StorageService()->UserDB().GetUserById(i.userId,UInfo)) { StorageService()->ActionLinksDB().CancelAction(i.id); @@ -57,7 +54,6 @@ namespace OpenWifi { continue; } - std::cout << "Sending email " << __LINE__ << std::endl; switch(i.action) { case OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD: { if(AuthService::SendEmailToUser(i.id, UInfo.email, AuthService::FORGOT_PASSWORD)) { @@ -92,18 +88,14 @@ namespace OpenWifi { break; case OpenWifi::SecurityObjects::LinkActions::SUB_SIGNUP: { - std::cout << "Sending email " << __LINE__ << std::endl; if(AuthService::SendEmailToSubUser(i.id, UInfo.email, AuthService::SIGNUP_VERIFICATION)) { - std::cout << "Sending email " << __LINE__ << std::endl; Logger().information(Poco::format("Send new subscriber email verification link to %s",UInfo.email)); } - std::cout << "Sending email " << __LINE__ << std::endl; StorageService()->ActionLinksDB().SentAction(i.id); } break; default: { - std::cout << "Sending email " << __LINE__ << std::endl; StorageService()->ActionLinksDB().SentAction(i.id); } } diff --git a/src/AuthService.cpp b/src/AuthService.cpp index b58cae7..d58904b 100644 --- a/src/AuthService.cpp +++ b/src/AuthService.cpp @@ -548,15 +548,12 @@ namespace OpenWifi { case SIGNUP_VERIFICATION: { MessageAttributes Attrs; - std::cout << "Signup verification " << __LINE__ << std::endl; Attrs[RECIPIENT_EMAIL] = UInfo.email; Attrs[LOGO] = GetLogoAssetURI(); Attrs[SUBJECT] = "EMail Address Verification"; Attrs[ACTION_LINK] = MicroService::instance().GetPublicAPIEndPoint() + "/actionLink?action=signup_verification&id=" + LinkId ; - std::cout << "Signup verification " << __LINE__ << std::endl; SMTPMailerService()->SendMessage(UInfo.email, "signup_verification.txt", Attrs); UInfo.waitingForEmailCheck = true; - std::cout << "Signup verification " << __LINE__ << std::endl; } break; diff --git a/src/RESTAPI/RESTAPI_signup_handler.cpp b/src/RESTAPI/RESTAPI_signup_handler.cpp index ba29103..864d8db 100644 --- a/src/RESTAPI/RESTAPI_signup_handler.cpp +++ b/src/RESTAPI/RESTAPI_signup_handler.cpp @@ -13,39 +13,32 @@ namespace OpenWifi { auto UserName = GetParameter("email",""); auto signupUUID = GetParameter("signupUUID",""); - __DBG__ if(UserName.empty() || signupUUID.empty()) { - __DBG__ return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); } if(!Utils::ValidEMailAddress(UserName)) { - __DBG__ return BadRequest(RESTAPI::Errors::InvalidEmailAddress); } // Do we already exist? Can only signup once... SecurityObjects::UserInfo Existing; if(StorageService()->SubDB().GetUserByEmail(UserName,Existing)) { - __DBG__ - if(Existing.signingUp.empty()) { - __DBG__ return BadRequest(1, "Subscriber already signed up."); } if(Existing.waitingForEmailCheck) { - __DBG__ return BadRequest(2, "Waiting for email check completion."); } - __DBG__ return BadRequest(3, "Waiting for device:" + Existing.signingUp); } SecurityObjects::UserInfo NewSub; NewSub.signingUp = signupUUID; NewSub.waitingForEmailCheck = true; + NewSub.name = UserName; NewSub.modified = std::time(nullptr); NewSub.creationDate = std::time(nullptr); NewSub.id = MicroService::instance().CreateUUID(); @@ -53,9 +46,7 @@ namespace OpenWifi { NewSub.userRole = SecurityObjects::SUBSCRIBER; NewSub.changePassword = true; - __DBG__ StorageService()->SubDB().CreateRecord(NewSub); - __DBG__ Logger_.information(Poco::format("SIGNUP-PASSWORD(%s): Request for %s", Request->clientAddress().toString(), UserName)); SecurityObjects::ActionLink NewLink; @@ -67,9 +58,10 @@ namespace OpenWifi { NewLink.expires = NewLink.created + (1*60*60); // 1 hour NewLink.userAction = false; StorageService()->ActionLinksDB().CreateAction(NewLink); - __DBG__ - return OK(); + Poco::JSON::Object Answer; + NewSub.to_json(Answer); + return ReturnObject(Answer); } void RESTAPI_signup_handler::DoPut() { diff --git a/src/SMTPMailerService.cpp b/src/SMTPMailerService.cpp index 6435c0c..2a06416 100644 --- a/src/SMTPMailerService.cpp +++ b/src/SMTPMailerService.cpp @@ -65,6 +65,7 @@ namespace OpenWifi { void SMTPMailerService::run() { Running_ = true; + while(Running_) { Poco::Thread::trySleep(10000); @@ -80,16 +81,16 @@ namespace OpenWifi { if(!Running_) break; auto Recipient = i->Attrs.find(RECIPIENT_EMAIL)->second; - uint64_t Now = std::time(nullptr); - if((i->LastTry==0 || (Now-i->LastTry)>MailRetry_)) { + uint64_t now = OpenWifi::Now(); + if((i->LastTry==0 || (now-i->LastTry)>MailRetry_)) { if (SendIt(*i)) { Logger().information(Poco::format("Attempting to deliver for mail '%s'.", Recipient)); i = Messages_.erase(i); } else { - i->LastTry = Now; + i->LastTry = now; ++i; } - } else if ((Now-i->Posted)>MailAbandon_) { + } else if ((now-i->Posted)>MailAbandon_) { Logger().information(Poco::format("Mail for '%s' has timed out and will not be sent.", Recipient)); i = Messages_.erase(i); } else { @@ -141,16 +142,12 @@ namespace OpenWifi { auto Logo = Msg.Attrs.find(LOGO); if(Logo!=Msg.Attrs.end()) { try { - std::cout << "mail server ... " << __LINE__ << std::endl; Poco::File LogoFile(AuthService::GetLogoAssetFileName()); std::ifstream IF(LogoFile.path()); std::ostringstream OS; Poco::StreamCopier::copyStream(IF, OS); - std::cout << "mail server ... " << __LINE__ << std::endl; Message.addAttachment("logo", new Poco::Net::StringPartSource(OS.str(), "image/png")); - std::cout << "mail server ... " << __LINE__ << std::endl; } catch (...) { - std::cout << "mail server ... " << __LINE__ << std::endl; Logger().warning(Poco::format("Cannot add '%s' logo in email",AuthService::GetLogoAssetFileName())); } } @@ -165,26 +162,19 @@ namespace OpenWifi { Poco::Net::SSLManager::instance().initializeClient(nullptr, ptrHandler_, ptrContext); - std::cout << "mail server ... " << __LINE__ << std::endl; session.login(); - std::cout << "mail server ... " << __LINE__ << std::endl; session.startTLS(ptrContext); - std::cout << "mail server ... " << __LINE__ << std::endl; session.login(MailHost_, Poco::Net::SecureSMTPClientSession::AUTH_LOGIN, SenderLoginUserName_, SenderLoginPassword_ ); - std::cout << "mail server ... " << __LINE__ << std::endl; session.sendMessage(Message); - std::cout << "mail server ... " << __LINE__ << std::endl; session.close(); - std::cout << "mail server ... " << __LINE__ << std::endl; return true; } catch (const Poco::Exception& E) { - std::cout << "mail server ... " << __LINE__ << std::endl; Logger().log(E); } catch (const std::exception &E) { diff --git a/wwwassets/signup_verification.html b/wwwassets/signup_verification.html index 4abef98..1d4211f 100644 --- a/wwwassets/signup_verification.html +++ b/wwwassets/signup_verification.html @@ -123,17 +123,17 @@
-

Reset Password

+

Signup Completion

- +
- +
@@ -153,7 +153,7 @@ if(document.getElementById("password1").value == document.getElementById("password2").value) { return true; } else { - alert("The 2 passwords did not match. The passwords must match to reset your new password."); + alert("The 2 passwords did not match. The passwords must match to complete your signup."); return false; } } diff --git a/wwwassets/signup_verification_error.html b/wwwassets/signup_verification_error.html index 869c668..bc8cbc1 100644 --- a/wwwassets/signup_verification_error.html +++ b/wwwassets/signup_verification_error.html @@ -101,7 +101,7 @@
-

Reset Password Failed

+

Signup completion failed

ID

${UUID}