Exemple #1
0
        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!"));
            }
        }
Exemple #2
0
        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!"));
            }
        }
Exemple #3
0
        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());
            }
        }
Exemple #4
0
        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"
                });
            }
        }
Exemple #5
0
        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!"));
            }
        }
Exemple #6
0
        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())));
        }
Exemple #7
0
        public async Task <ActionResult <TSCategory> > Get(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "category/get")] 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, "Requested Category", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            return(await CosmosAPI.cosmosDBClientCategory.GetCategory(tsCategory, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
        }
Exemple #8
0
        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!"));
            }
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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!"));
            }
        }
Exemple #12
0
        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);
            }
        }
Exemple #13
0
        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!"));
            }
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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());
            }
        }
Exemple #16
0
        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!"));
            }
        }
        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());
            }
        }