public async Task <ActionResult> Update( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "category/update")] HttpRequest req, ILogger log) { TSCategory tsCategory = await MyFromBody <TSCategory> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "put Category", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); bool b = await CosmosAPI.cosmosDBClientCategory.UpdateCategory(tsCategory, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new Category!")); } }
public async Task <ActionResult <TSFeedback> > Get( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "feedback/get")] HttpRequest req, ILogger log) { ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid userID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(userID, "Requested Feedback", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); CosmosDocFeedback feedbackDoc = await CosmosAPI.cosmosDBClientFeedback.FindFeedback(userID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (feedbackDoc != null) { return(feedbackDoc.toTSFeedback()); } else { return(new TSFeedback()); } }
public async Task <ActionResult> Update( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "uiwordnative/update")] HttpRequest req, ILogger log) { TSUIWordNative tsUIWordNative = await MyFromBody <TSUIWordNative> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); bool b = await CosmosAPI.cosmosDBClientUIWordNative.Update(tsUIWordNative, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new todo!")); } }
public async Task <ActionResult> Delete( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "User/delete")] HttpRequest req, ILogger log) { TSUser tsUser = await MyFromBody <TSUser> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "delete user", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); bool b = await CosmosAPI.cosmosDBClientUser.DeleteUser(tsUser, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { return(new OkResult()); } else { return(new UnprocessableEntityResult()); } }
public async Task <ActionResult <IEnumerable <TSUIWordNative> > > GetAll( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "uiwordnative/getall")] HttpRequest req, ILogger log) { ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(await CosmosAPI.cosmosDBClientUIWordNative.GetAll(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); }
public async Task <ActionResult <TSEmail> > PassRecovery( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/passrecovery")] HttpRequest req, ILogger log) { TSEmail tsEmail = await MyFromBody <TSEmail> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.NotAuthorized, WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Pass Recovery", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string newPass = GlobalFunctions.GetSalt(); CosmosDocUser cosmosDocUser = await CosmosAPI.cosmosDBClientUser.FindUserByUserName(tsEmail.To, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (cosmosDocUser != null) { cosmosDocUser.Salt = GlobalFunctions.GetSalt(); cosmosDocUser.HashedPassword = GlobalFunctions.CmdHashPasswordBytes(newPass, cosmosDocUser.Salt); bool b = await CosmosAPI.cosmosDBClientUser.UpdateUserDoc(cosmosDocUser, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { tsEmail.To = cosmosDocUser.Email; TSEmail result = await TodosCosmos.LocalFunctions.SendEmail(tsEmail, string.Empty, newPass, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); result.To = string.Empty; result.OperationCode = 0; return(result); } else { return(new TSEmail { Result = "Error: Could not recover user password" }); } } else { return(new TSEmail { Result = "Error: User not found" }); } }
public async Task <ActionResult> ChangePassword( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/changepassword")] HttpRequest req, ILogger log) { TSUser tsUser = await MyFromBody <TSUser> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "change password", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string MachineID = LocalFunctions.CmdGetValueFromClaim(User.Claims, "MachineID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string IPAddress = req.HttpContext.Connection.RemoteIpAddress.ToString(); CosmosEmailedCode emailedCode = await CosmosAPI.cosmosDBClientEmailedCode.FindEmaiedCode(tsUser.Email, IPAddress, MachineID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (emailedCode != null) { if (emailedCode.Code.ToLower().Equals(tsUser.EmailedCode)) { await CosmosAPI.cosmosDBClientEmailedCode.DeleteEmailedCodes(tsUser.Email, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSUser currUser = (await CosmosAPI.cosmosDBClientUser.FindUserByID(UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))).toTSUser(); currUser.Password = tsUser.Password; if (await CosmosAPI.cosmosDBClientUser.UpdateUser(currUser, false, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))) { return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new user!")); } } else { return(new OkObjectResult("Error:Emailed code is not correct!")); } } else { await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, "EmaiedCode expected but not found", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(new OkObjectResult("Error:Server can't find emailed code to compare!")); } }
public async Task <ActionResult <IEnumerable <TSUIWordForeign> > > GetAllByLang( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "uiwordforeign/getallbylang")] HttpRequest req, ILogger log) { TSUIWordForeign tsUIWordForeign = await MyFromBody <TSUIWordForeign> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(await CosmosAPI.cosmosDBClientUIWordForeign.GetAllByLang(tsUIWordForeign.UILanguageID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); }
public async Task <ActionResult <IEnumerable <TSCategory> > > GetAll( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "category/getall")] HttpRequest req, ILogger log) { ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(Guid.Empty, "Requested public data", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Requested Categories", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(await CosmosAPI.cosmosDBClientCategory.GetAllCategories(UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); }
public async Task <ActionResult <TSStat> > Get( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stat")] HttpRequest req, ILogger log) { await CosmosAPI.cosmosDBClientSetting.SetSetting(Guid.Empty, "LatsStatRequest", "ts", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (User != null) { Guid userID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (!userID.Equals(Guid.Empty)) { if (!userName.Equals("demouser")) { TSUser tsUser = await CosmosAPI.cosmosDBClientUser.GetUser(new TSUser { ID = userID }, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (tsUser != null) { if (!tsUser.IsLive) { tsUser.IsLive = true; await CosmosAPI.cosmosDBClientUser.UpdateUser(tsUser, true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } } } } } TSStat stat = new TSStat { IPsCount = await GetStat("IPAddressesCount"), VisitsCount = await GetStat("VisitsCount"), UsersCount = await GetStat("UsersCount"), LiveUsersCount = await GetStat("LiveUsersCount"), TodosCount = await GetStat("TodosCount"), LikesCount = await GetStat("LikesCount"), DislikesCount = await GetStat("DislikesCount"), FeedbackCount = await GetStat("FeedbackCount"), }; return(stat); // return new OkObjectResult(JsonSerializer.ToString(stat)); }
public async Task <ActionResult> Logout( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "user/logout")] HttpRequest req, ILogger log) { ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "user logout", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "LiveUsersCount", false, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(new OkObjectResult("OK")); }
public async Task <ActionResult <TSTodo> > Get( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "todo/get")] HttpRequest req, ILogger log) { TSTodo tsTodo = await MyFromBody <TSTodo> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Requested todo", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(await CosmosAPI.cosmosDBClientTodo.GetTodo(tsTodo, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); }
public async Task <ActionResult <IEnumerable <TSUserOpen> > > GetLiveUsers( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "user/getliveusers")] HttpRequest req, ILogger log) { List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.NotAuthorized, WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "get live users", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(await CosmosAPI.cosmosDBClientUser.GetLiveUsers(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); }
public async Task <ActionResult> Delete( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "uilanguage/delete")] HttpRequest req, ILogger log) { TSUILanguage tsUILanguage = await MyFromBody <TSUILanguage> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); bool b = await CosmosAPI.cosmosDBClientUILanguage.Delete(tsUILanguage, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new todo!")); } }
public async Task <ActionResult <TSEmail> > CheckUserName( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/checkusername")] HttpRequest req, ILogger log) { TSEmail tsEmail = await MyFromBody <TSEmail> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.NotAuthorized, WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Check UserName", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); CosmosDocUser user = await CosmosAPI.cosmosDBClientUser.FindUserByUserName(tsEmail.To, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSEmail result = new TSEmail { To = string.Empty, OperationCode = 0 }; if (user is null) { result.Result = "OK"; } else { result.Result = "UserName already exists"; } return(result); }
public async Task <ActionResult <IEnumerable <TSFeedback> > > GetAll( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "feedback/getall")] HttpRequest req, ILogger log) { ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid userID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(userID, "Requested Feedbacks", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); List <TSFeedback> list = await CosmosAPI.cosmosDBClientFeedback.GetAllFeedback(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); foreach (var item in list) { item.UserName = CosmosAPI.cosmosDBClientUser.FindUserByID(item.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())).Result.FullName; } return(list); }
public async Task <ActionResult <TSUser> > Authorize( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/authorize")] HttpRequest req, ILogger log) { TSUser tsUser = await MyFromBody <TSUser> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Requested authentication", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSUser result = new TSUser(); tsUser.ID = UserID; result = CosmosAPI.cosmosDBClientUser.GetUser(tsUser, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())).Result; if (!result.ID.Equals(Guid.Empty)) { await CosmosAPI.cosmosDBClientFeedMessage.AddFeedMessage(RequestedActionEnum.NotifyAdmin, "New Login " + result.UserName, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "LiveUsersCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } else { result.UserName = "******"; result.FullName = "Can't find user!"; } TimeAnalyzer.LogAll(); return(result); }
public async Task <ActionResult> Add( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "todo/add")] HttpRequest req, ILogger log) { TSTodo tsTodo = await MyFromBody <TSTodo> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid userID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(userID, "post todo", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); tsTodo.ID = Guid.NewGuid(); tsTodo.CreateDate = DateTime.Now; bool b = await CosmosAPI.cosmosDBClientTodo.AddTodo(tsTodo, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { TSUser currUser = new TSUser() { ID = userID, UserName = userName, }; await CosmosAPI.cosmosDBClientUser.UpdateUserTodosCount(currUser, 1, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "TodosCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new todo!")); } }
public async Task <ActionResult <TSUIWordNative> > Get( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "uiwordnative/get")] HttpRequest req, ILogger log) { TSUIWordNative tsUIWordNative = await MyFromBody <TSUIWordNative> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSUIWordNative result = await CosmosAPI.cosmosDBClientUIWordNative.Get(tsUIWordNative, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (result is null) { return(new TSUIWordNative()); } else { return(result); } }
public async Task <ActionResult <IEnumerable <TSUILanguageShort> > > GetAllLanguages( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "googletranslator/getalllanguages")] HttpRequest req) { ClaimsPrincipal User = MyTokenValidator.Authenticate(req, AllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); IEnumerable <Language> list = await _googleTranslator.GetLanguagesAsync(); IList <TSUILanguageShort> result = new List <TSUILanguageShort>(); foreach (var item in list) { result.Add(new TSUILanguageShort { Name = item.Name, Code = item.Code }); } return(new ActionResult <IEnumerable <TSUILanguageShort> >(result.AsEnumerable())); }
public async Task <ActionResult> Add( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "uiwordnative/add")] HttpRequest req, ILogger log) { List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSUIWordNative tsUIWordNative = await MyFromBody <TSUIWordNative> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); CosmosDocUIWordNative l = await CosmosAPI.cosmosDBClientUIWordNative.FindByWord(tsUIWordNative.Word, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (l is null) { bool b = await CosmosAPI.cosmosDBClientUIWordNative.Add(tsUIWordNative, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new UIWordNative!")); } } else { return(new OkObjectResult("Error:UIWordNative with word - " + tsUIWordNative.Word + " exists already!")); } }
public async Task <ActionResult <TSEmail> > SendMail( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/sendmail")] HttpRequest req, ILogger log) { TSEmail tsEmail = await MyFromBody <TSEmail> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (tsEmail is null) { await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, "tsEmail is null", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.NotAuthorized, WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "send mail", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string MachineID = LocalFunctions.CmdGetValueFromClaim(User.Claims, "MachineID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSEmail result = await TodosCosmos.LocalFunctions.SendEmail(tsEmail, req.HttpContext.Connection.RemoteIpAddress.ToString(), MachineID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); result.To = string.Empty; result.OperationCode = 0; return(result); }
public async Task <ActionResult <TSReaction> > Add( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "reaction/add")] HttpRequest req, ILogger log) { List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid userID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); TSReaction tsReaction = await MyFromBody <TSReaction> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); tsReaction.UserID = userID; await CosmosAPI.cosmosDBClientActivity.AddActivityLog(userID, "Add or update Reaction", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (!tsReaction.UserID.Equals(Guid.Empty)) { if (userName.Equals("demouser")) { return(new TSReaction()); } } CosmosDocReaction oldReaction = await CosmosAPI.cosmosDBClientReaction.FindReaction(tsReaction.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (oldReaction is null) { tsReaction.ID = Guid.NewGuid(); bool b = await CosmosAPI.cosmosDBClientReaction.AddReaction(tsReaction, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { if (tsReaction.LikeOrDislike) { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "LikesCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } else { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "DislikesCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } } } else { tsReaction.ID = oldReaction.ID; if (oldReaction.LikeOrDislike != tsReaction.LikeOrDislike) { if (oldReaction.LikeOrDislike) { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "LikesCount", false, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } else { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "DislikesCount", false, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } bool b = await CosmosAPI.cosmosDBClientReaction.UpdateReaction(tsReaction, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { if (tsReaction.LikeOrDislike) { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "LikesCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } else { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "DislikesCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } } } } CosmosDocReaction reactionEntity = await CosmosAPI.cosmosDBClientReaction.FindReaction(tsReaction.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (reactionEntity != null) { return(reactionEntity.toTSReaction()); } else { return(new TSReaction()); } }
public async Task <ActionResult <TSFeedback> > Add( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "feedback/add")] HttpRequest req, ILogger log) { List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); TSFeedback tsFeedback = await MyFromBody <TSFeedback> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); tsFeedback.UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(tsFeedback.UserID, "Add or update Feedback", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (!tsFeedback.UserID.Equals(Guid.Empty)) { if (userName.Equals("demouser")) { return(new TSFeedback()); } } CosmosDocFeedback oldFeedback = await CosmosAPI.cosmosDBClientFeedback.FindFeedback(tsFeedback.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (oldFeedback is null) { tsFeedback.ID = Guid.NewGuid(); tsFeedback.AddDate = DateTime.UtcNow; bool b = await CosmosAPI.cosmosDBClientFeedback.AddFeedback(tsFeedback, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (b) { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "FeedbackCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } } else { if (oldFeedback.Text != tsFeedback.Text) { await CosmosAPI.cosmosDBClientFeedback.UpdateFeedback(tsFeedback, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); } } CosmosDocFeedback feedbackDoc = await CosmosAPI.cosmosDBClientFeedback.FindFeedback(tsFeedback.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (feedbackDoc != null) { return(feedbackDoc.toTSFeedback()); } else { return(new TSFeedback()); } }
public async Task <ActionResult> Add( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/add")] HttpRequest req, ILogger log) { TSUser tsUser = await MyFromBody <TSUser> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum> { WebApiUserTypesEnum.NotAuthorized, WebApiUserTypesEnum.Authorized, WebApiUserTypesEnum.Admin }; ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))); await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "post user", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string MachineID = LocalFunctions.CmdGetValueFromClaim(User.Claims, "MachineID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); string IPAddress = req.HttpContext.Connection.RemoteIpAddress.ToString(); CosmosEmailedCode emailedCode = await CosmosAPI.cosmosDBClientEmailedCode.FindEmaiedCode(tsUser.Email, IPAddress, MachineID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); if (emailedCode != null) { if (emailedCode.Code.ToLower().Equals(tsUser.EmailedCode)) { await CosmosAPI.cosmosDBClientEmailedCode.DeleteEmailedCodes(tsUser.Email, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); tsUser.ID = Guid.NewGuid(); tsUser.CreateDate = DateTime.Now; if (await CosmosAPI.cosmosDBClientUser.AddUser(tsUser, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()))) { await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "UsersCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(new OkObjectResult("OK")); } else { return(new OkObjectResult("Error:Can't add new user!")); } } else { return(new OkObjectResult("Error:Emailed code is not correct!")); } } else { await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, "EmaiedCode expected but not found", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())); return(new OkObjectResult("Error:Server can't find emailed code to compare!")); } }