mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-30 18:27:49 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.8 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(RESTAPI::Errors::SMSCouldNotBeSentRetry);
 | |
|         }
 | |
| 
 | |
|         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(RESTAPI::Errors::SMSCouldNotValidate);
 | |
|         }
 | |
| 
 | |
|         if( UserInfo_.userinfo.userRole!=SecurityObjects::ROOT &&
 | |
|             UserInfo_.userinfo.userRole!=SecurityObjects::PARTNER &&
 | |
|             UserInfo_.userinfo.userRole!=SecurityObjects::ADMIN) {
 | |
|             return UnAuthorized(RESTAPI::Errors::InsufficientAccessRights,ACCESS_DENIED);
 | |
|         }
 | |
| 
 | |
|         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(RESTAPI::Errors::SMSCouldNotBeSentRetry);
 | |
|         }
 | |
|         BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
 | |
|     }
 | |
| 
 | |
| } | 
