public RESTReplyData get_public_key(RESTRequestData pReq, List <string> pArgs) { RESTReplyData replyData = new RESTReplyData(); // The HTTP response info ResponseBody respBody = new ResponseBody(); // The request's "data" response info string domainID = pArgs.Count == 1 ? pArgs[0] : null; if (Domains.Instance.TryGetDomainWithID(domainID, out DomainEntity aDomain)) { respBody.Data = new bodyDomainPublicKeyGetResponse() { public_key = aDomain.Public_Key }; } else { // return nothing! respBody.RespondFailure("unknown domain"); respBody.ErrorData("domain", "there is no domain with that ID"); // legacy HiFi compatibility replyData.Status = (int)HttpStatusCode.NotFound; // Context.Log.Debug("{0} get_domain GET: no domain! Returning: {1}", _logHeader, replyData.Body); } replyData.SetBody(respBody, pReq); return(replyData); }
public RESTReplyData get_domain(RESTRequestData pReq, List <string> pArgs) { RESTReplyData replyData = new RESTReplyData(); // The HTTP response info ResponseBody respBody = new ResponseBody(); // The request's "data" response info string domainID = pArgs.Count == 1 ? pArgs[0] : null; if (Domains.Instance.TryGetDomainWithID(domainID, out DomainEntity dobj)) { respBody.Data = new bodyDomainResponse() { domain = new bodyDomainReplyData() { id = domainID, ice_server_address = dobj.GetIceServerAddr(), name = dobj.PlaceName } }; } else { // return nothing! respBody.RespondFailure("No domain with that ID"); respBody.ErrorData("domain", "there is no domain with that ID"); replyData.Status = (int)HttpStatusCode.NotFound; } replyData.SetBody(respBody, pReq); return(replyData); }
public RESTReplyData user_create(RESTRequestData pReq, List <string> pArgs) { RESTReplyData replyData = new RESTReplyData(); // The HTTP response info ResponseBody respBody = new ResponseBody(); // The request's "data" response info if (Sessions.Instance.ShouldBeThrottled(pReq.SenderKey, Sessions.Op.ACCOUNT_CREATE)) { respBody.RespondFailure("Throttled"); respBody.ErrorData("error", "throttled"); } else { try { bodyUsersPost requestData = pReq.RequestBodyObject <bodyUsersPost>(); string userName = requestData.user["username"]; string userPassword = requestData.user["password"]; string userEmail = requestData.user["email"]; if (CheckUsernameFormat(userName)) { if (CheckEmailFormat(userEmail)) { Context.Log.Debug("{0} Creating account {1}/{2}", _logHeader, userName, userEmail); AccountEntity newAcct = Accounts.Instance.CreateAccount(userName, userPassword, userEmail); if (newAcct == null) { respBody.RespondFailure("Username already exists"); respBody.ErrorData("username", "already exists"); // legacy HiFi compatibility Context.Log.Debug("{0} Failed acct creation. Username already exists. User={1}", _logHeader, userName); } else { // Successful account creation newAcct.IPAddrOfCreator = pReq.SenderKey; newAcct.Updated(); Context.Log.Debug("{0} Successful acct creation. User={1}", _logHeader, userName); } } else { respBody.RespondFailure("Bad format for email"); respBody.ErrorData("error", "bad format for email"); } } else { respBody.RespondFailure("Bad format for username"); respBody.ErrorData("error", "bad format for username"); } } catch (Exception e) { replyData.Status = (int)HttpStatusCode.BadRequest; Context.Log.Error("{0} Badly formed create account request. {1}", _logHeader, e); } } replyData.SetBody(respBody, pReq); return(replyData); }