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
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:

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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) {

View File

@@ -123,17 +123,17 @@
<form action="/api/v1/actionLink?action=signup_completion" method="post" onsubmit="return validatePassword()">
<input type="hidden" id="custId" name="id" value="${UUID}">
<div class="grid-container">
<h2>Reset Password</h2>
<h2>Signup Completion</h2>
<div class="passwordlabel">
<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 class="passwordlabel">
<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>
</div>
<div class="passwordlabel">
<button type="submit">Reset Password</button>
<button type="submit">Complete Signup</button>
</div>
<div class="rulestext">
@@ -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;
}
}

View File

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