mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-10-30 10:22:22 +00:00
49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
//
|
|
// Created by stephane bourque on 2021-10-09.
|
|
//
|
|
|
|
#include "RESTAPI_sms_handler.h"
|
|
#include "SMSSender.h"
|
|
#include "framework/RESTAPI_errors.h"
|
|
#include "framework/MicroService.h"
|
|
|
|
namespace OpenWifi {
|
|
|
|
void OpenWifi::RESTAPI_sms_handler::DoPost() {
|
|
auto Obj = ParseStream();
|
|
|
|
std::string Arg;
|
|
if(HasParameter("validateNumber",Arg) && Arg=="true" && Obj->has("to")) {
|
|
auto Number = Obj->get("to").toString();
|
|
if(SMSSender()->StartValidation(Number, UserInfo_.userinfo.email)) {
|
|
return OK();
|
|
}
|
|
return BadRequest("SMS could not be sent to validate device, try later or change the phone number.");
|
|
}
|
|
|
|
std::string Code;
|
|
if( HasParameter("completeValidation",Arg) &&
|
|
Arg=="true" &&
|
|
HasParameter("validationCode", Code) &&
|
|
Obj->has("to")) {
|
|
auto Number = Obj->get("to").toString();
|
|
if(SMSSender()->CompleteValidation(Number, Code, UserInfo_.userinfo.email)) {
|
|
return OK();
|
|
}
|
|
return BadRequest("Code and number could not be validated");
|
|
}
|
|
|
|
if (Obj->has("to") &&
|
|
Obj->has("text")) {
|
|
|
|
std::string PhoneNumber = Obj->get("to").toString();
|
|
std::string Text = Obj->get("text").toString();
|
|
if(SMSSender()->Send(PhoneNumber, Text))
|
|
return OK();
|
|
|
|
return InternalError("SMS Message could not be sent.");
|
|
}
|
|
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
|
}
|
|
|
|
} |