Adding Subscriber Signup.

This commit is contained in:
stephb9959
2022-02-22 22:02:41 -08:00
parent 6c5863d96a
commit 151bcc9406
8 changed files with 21 additions and 56 deletions

2
build
View File

@@ -1 +1 @@
14 15

View File

@@ -355,6 +355,9 @@ components:
format: int64 format: int64
userTypeProprietaryInfo: userTypeProprietaryInfo:
$ref: '#/components/schemas/UserLoginLoginExtensions' $ref: '#/components/schemas/UserLoginLoginExtensions'
signupUUID:
type: string
format: uuid
UserList: UserList:
type: object type: object
@@ -1465,8 +1468,8 @@ paths:
schema: schema:
type: integer type: integer
format: int64 format: int64
required: required example: 1,2,3
example: 1,2,3 required: true
responses: responses:
200: 200:
description: Succesful posting of response. description: Succesful posting of response.
@@ -1505,16 +1508,7 @@ paths:
required: true required: true
responses: responses:
200: 200:
description: Success signup post $ref: '#/components/schemas/UserInfo'
content:
application/json:
schema:
type:
object
properties:
signupUUID:
type: string
format: uuid
400: 400:
$ref: '#/components/responses/BadRequest' $ref: '#/components/responses/BadRequest'
403: 403:

View File

@@ -39,13 +39,10 @@ namespace OpenWifi {
continue; continue;
for(auto &i:Links) { for(auto &i:Links) {
std::cout << "Sending email " << __LINE__ << std::endl;
if(!Running_) if(!Running_)
break; break;
std::cout << "Sending email " << __LINE__ << std::endl;
SecurityObjects::UserInfo UInfo; SecurityObjects::UserInfo UInfo;
std::cout << "Sending email " << __LINE__ << std::endl;
if((i.action==OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD || if((i.action==OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD ||
i.action==OpenWifi::SecurityObjects::LinkActions::VERIFY_EMAIL) && !StorageService()->UserDB().GetUserById(i.userId,UInfo)) { i.action==OpenWifi::SecurityObjects::LinkActions::VERIFY_EMAIL) && !StorageService()->UserDB().GetUserById(i.userId,UInfo)) {
StorageService()->ActionLinksDB().CancelAction(i.id); StorageService()->ActionLinksDB().CancelAction(i.id);
@@ -57,7 +54,6 @@ namespace OpenWifi {
continue; continue;
} }
std::cout << "Sending email " << __LINE__ << std::endl;
switch(i.action) { switch(i.action) {
case OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD: { case OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD: {
if(AuthService::SendEmailToUser(i.id, UInfo.email, AuthService::FORGOT_PASSWORD)) { if(AuthService::SendEmailToUser(i.id, UInfo.email, AuthService::FORGOT_PASSWORD)) {
@@ -92,18 +88,14 @@ namespace OpenWifi {
break; break;
case OpenWifi::SecurityObjects::LinkActions::SUB_SIGNUP: { case OpenWifi::SecurityObjects::LinkActions::SUB_SIGNUP: {
std::cout << "Sending email " << __LINE__ << std::endl;
if(AuthService::SendEmailToSubUser(i.id, UInfo.email, AuthService::SIGNUP_VERIFICATION)) { 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)); 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); StorageService()->ActionLinksDB().SentAction(i.id);
} }
break; break;
default: { default: {
std::cout << "Sending email " << __LINE__ << std::endl;
StorageService()->ActionLinksDB().SentAction(i.id); StorageService()->ActionLinksDB().SentAction(i.id);
} }
} }

View File

@@ -548,15 +548,12 @@ namespace OpenWifi {
case SIGNUP_VERIFICATION: { case SIGNUP_VERIFICATION: {
MessageAttributes Attrs; MessageAttributes Attrs;
std::cout << "Signup verification " << __LINE__ << std::endl;
Attrs[RECIPIENT_EMAIL] = UInfo.email; Attrs[RECIPIENT_EMAIL] = UInfo.email;
Attrs[LOGO] = GetLogoAssetURI(); Attrs[LOGO] = GetLogoAssetURI();
Attrs[SUBJECT] = "EMail Address Verification"; Attrs[SUBJECT] = "EMail Address Verification";
Attrs[ACTION_LINK] = MicroService::instance().GetPublicAPIEndPoint() + "/actionLink?action=signup_verification&id=" + LinkId ; 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); SMTPMailerService()->SendMessage(UInfo.email, "signup_verification.txt", Attrs);
UInfo.waitingForEmailCheck = true; UInfo.waitingForEmailCheck = true;
std::cout << "Signup verification " << __LINE__ << std::endl;
} }
break; break;

View File

@@ -13,39 +13,32 @@ namespace OpenWifi {
auto UserName = GetParameter("email",""); auto UserName = GetParameter("email","");
auto signupUUID = GetParameter("signupUUID",""); auto signupUUID = GetParameter("signupUUID","");
__DBG__
if(UserName.empty() || signupUUID.empty()) { if(UserName.empty() || signupUUID.empty()) {
__DBG__
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
} }
if(!Utils::ValidEMailAddress(UserName)) { if(!Utils::ValidEMailAddress(UserName)) {
__DBG__
return BadRequest(RESTAPI::Errors::InvalidEmailAddress); return BadRequest(RESTAPI::Errors::InvalidEmailAddress);
} }
// Do we already exist? Can only signup once... // Do we already exist? Can only signup once...
SecurityObjects::UserInfo Existing; SecurityObjects::UserInfo Existing;
if(StorageService()->SubDB().GetUserByEmail(UserName,Existing)) { if(StorageService()->SubDB().GetUserByEmail(UserName,Existing)) {
__DBG__
if(Existing.signingUp.empty()) { if(Existing.signingUp.empty()) {
__DBG__
return BadRequest(1, "Subscriber already signed up."); return BadRequest(1, "Subscriber already signed up.");
} }
if(Existing.waitingForEmailCheck) { if(Existing.waitingForEmailCheck) {
__DBG__
return BadRequest(2, "Waiting for email check completion."); return BadRequest(2, "Waiting for email check completion.");
} }
__DBG__
return BadRequest(3, "Waiting for device:" + Existing.signingUp); return BadRequest(3, "Waiting for device:" + Existing.signingUp);
} }
SecurityObjects::UserInfo NewSub; SecurityObjects::UserInfo NewSub;
NewSub.signingUp = signupUUID; NewSub.signingUp = signupUUID;
NewSub.waitingForEmailCheck = true; NewSub.waitingForEmailCheck = true;
NewSub.name = UserName;
NewSub.modified = std::time(nullptr); NewSub.modified = std::time(nullptr);
NewSub.creationDate = std::time(nullptr); NewSub.creationDate = std::time(nullptr);
NewSub.id = MicroService::instance().CreateUUID(); NewSub.id = MicroService::instance().CreateUUID();
@@ -53,9 +46,7 @@ namespace OpenWifi {
NewSub.userRole = SecurityObjects::SUBSCRIBER; NewSub.userRole = SecurityObjects::SUBSCRIBER;
NewSub.changePassword = true; NewSub.changePassword = true;
__DBG__
StorageService()->SubDB().CreateRecord(NewSub); StorageService()->SubDB().CreateRecord(NewSub);
__DBG__
Logger_.information(Poco::format("SIGNUP-PASSWORD(%s): Request for %s", Request->clientAddress().toString(), UserName)); Logger_.information(Poco::format("SIGNUP-PASSWORD(%s): Request for %s", Request->clientAddress().toString(), UserName));
SecurityObjects::ActionLink NewLink; SecurityObjects::ActionLink NewLink;
@@ -67,9 +58,10 @@ namespace OpenWifi {
NewLink.expires = NewLink.created + (1*60*60); // 1 hour NewLink.expires = NewLink.created + (1*60*60); // 1 hour
NewLink.userAction = false; NewLink.userAction = false;
StorageService()->ActionLinksDB().CreateAction(NewLink); StorageService()->ActionLinksDB().CreateAction(NewLink);
__DBG__
return OK(); Poco::JSON::Object Answer;
NewSub.to_json(Answer);
return ReturnObject(Answer);
} }
void RESTAPI_signup_handler::DoPut() { void RESTAPI_signup_handler::DoPut() {

View File

@@ -65,6 +65,7 @@ namespace OpenWifi {
void SMTPMailerService::run() { void SMTPMailerService::run() {
Running_ = true; Running_ = true;
while(Running_) { while(Running_) {
Poco::Thread::trySleep(10000); Poco::Thread::trySleep(10000);
@@ -80,16 +81,16 @@ namespace OpenWifi {
if(!Running_) if(!Running_)
break; break;
auto Recipient = i->Attrs.find(RECIPIENT_EMAIL)->second; auto Recipient = i->Attrs.find(RECIPIENT_EMAIL)->second;
uint64_t Now = std::time(nullptr); uint64_t now = OpenWifi::Now();
if((i->LastTry==0 || (Now-i->LastTry)>MailRetry_)) { if((i->LastTry==0 || (now-i->LastTry)>MailRetry_)) {
if (SendIt(*i)) { if (SendIt(*i)) {
Logger().information(Poco::format("Attempting to deliver for mail '%s'.", Recipient)); Logger().information(Poco::format("Attempting to deliver for mail '%s'.", Recipient));
i = Messages_.erase(i); i = Messages_.erase(i);
} else { } else {
i->LastTry = Now; i->LastTry = now;
++i; ++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)); Logger().information(Poco::format("Mail for '%s' has timed out and will not be sent.", Recipient));
i = Messages_.erase(i); i = Messages_.erase(i);
} else { } else {
@@ -141,16 +142,12 @@ namespace OpenWifi {
auto Logo = Msg.Attrs.find(LOGO); auto Logo = Msg.Attrs.find(LOGO);
if(Logo!=Msg.Attrs.end()) { if(Logo!=Msg.Attrs.end()) {
try { try {
std::cout << "mail server ... " << __LINE__ << std::endl;
Poco::File LogoFile(AuthService::GetLogoAssetFileName()); Poco::File LogoFile(AuthService::GetLogoAssetFileName());
std::ifstream IF(LogoFile.path()); std::ifstream IF(LogoFile.path());
std::ostringstream OS; std::ostringstream OS;
Poco::StreamCopier::copyStream(IF, OS); Poco::StreamCopier::copyStream(IF, OS);
std::cout << "mail server ... " << __LINE__ << std::endl;
Message.addAttachment("logo", new Poco::Net::StringPartSource(OS.str(), "image/png")); Message.addAttachment("logo", new Poco::Net::StringPartSource(OS.str(), "image/png"));
std::cout << "mail server ... " << __LINE__ << std::endl;
} catch (...) { } catch (...) {
std::cout << "mail server ... " << __LINE__ << std::endl;
Logger().warning(Poco::format("Cannot add '%s' logo in email",AuthService::GetLogoAssetFileName())); Logger().warning(Poco::format("Cannot add '%s' logo in email",AuthService::GetLogoAssetFileName()));
} }
} }
@@ -165,26 +162,19 @@ namespace OpenWifi {
Poco::Net::SSLManager::instance().initializeClient(nullptr, Poco::Net::SSLManager::instance().initializeClient(nullptr,
ptrHandler_, ptrHandler_,
ptrContext); ptrContext);
std::cout << "mail server ... " << __LINE__ << std::endl;
session.login(); session.login();
std::cout << "mail server ... " << __LINE__ << std::endl;
session.startTLS(ptrContext); session.startTLS(ptrContext);
std::cout << "mail server ... " << __LINE__ << std::endl;
session.login(MailHost_, session.login(MailHost_,
Poco::Net::SecureSMTPClientSession::AUTH_LOGIN, Poco::Net::SecureSMTPClientSession::AUTH_LOGIN,
SenderLoginUserName_, SenderLoginUserName_,
SenderLoginPassword_ SenderLoginPassword_
); );
std::cout << "mail server ... " << __LINE__ << std::endl;
session.sendMessage(Message); session.sendMessage(Message);
std::cout << "mail server ... " << __LINE__ << std::endl;
session.close(); session.close();
std::cout << "mail server ... " << __LINE__ << std::endl;
return true; return true;
} }
catch (const Poco::Exception& E) catch (const Poco::Exception& E)
{ {
std::cout << "mail server ... " << __LINE__ << std::endl;
Logger().log(E); Logger().log(E);
} }
catch (const std::exception &E) { catch (const std::exception &E) {

View File

@@ -123,17 +123,17 @@
<form action="/api/v1/actionLink?action=signup_completion" method="post" onsubmit="return validatePassword()"> <form action="/api/v1/actionLink?action=signup_completion" method="post" onsubmit="return validatePassword()">
<input type="hidden" id="custId" name="id" value="${UUID}"> <input type="hidden" id="custId" name="id" value="${UUID}">
<div class="grid-container"> <div class="grid-container">
<h2>Reset Password</h2> <h2>Signup Completion</h2>
<div class="passwordlabel"> <div class="passwordlabel">
<label class="passwordtext" for="password1" ><b>New Password</b></label> <label class="passwordtext" for="password1" ><b>New Password</b></label>
<input className="password-input" id="password1" type="password" placeholder="New Password" name="password1" pattern="${PASSWORD_VALIDATION}" required> <input className="password-input" id="password1" type="password" placeholder="Password" name="password1" pattern="${PASSWORD_VALIDATION}" required>
</div> </div>
<div class="passwordlabel"> <div class="passwordlabel">
<label class="passwordtext" for="password2"><b>Retype Password</b></label> <label class="passwordtext" for="password2"><b>Retype Password</b></label>
<input className="password-input" id="password2" type="password" placeholder="Retype Password" name="password2" pattern="${PASSWORD_VALIDATION}" required> <input className="password-input" id="password2" type="password" placeholder="Retype Password" name="password2" pattern="${PASSWORD_VALIDATION}" required>
</div> </div>
<div class="passwordlabel"> <div class="passwordlabel">
<button type="submit">Reset Password</button> <button type="submit">Complete Signup</button>
</div> </div>
<div class="rulestext"> <div class="rulestext">
@@ -153,7 +153,7 @@
if(document.getElementById("password1").value == document.getElementById("password2").value) { if(document.getElementById("password1").value == document.getElementById("password2").value) {
return true; return true;
} else { } 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; return false;
} }
} }

View File

@@ -101,7 +101,7 @@
<div class="info-card"> <div class="info-card">
<h1 class="info-title">Reset Password Failed</h1> <h1 class="info-title">Signup completion failed</h1>
<div> <div>
<h3>ID</h3> <h3>ID</h3>
<b>${UUID}</b> <b>${UUID}</b>