Ejemplo n.º 1
0
        public async Task <ActionResult <IEnumerable <TSUser> > > GetAll(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "user/getall")] 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()));


            Guid UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(UserID, "Requested all users", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            List <TSUser> users = new List <TSUser>();


            users = await CosmosAPI.cosmosDBClientUser.GetAllUsers(TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            return(users);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Delete(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "todo/delete")] 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, "delete todo", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            bool b = await CosmosAPI.cosmosDBClientTodo.DeleteTodo(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", false, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                return(new OkObjectResult("OK"));
            }
            else
            {
                return(new OkObjectResult("Error:Can't add new todo!"));
            }
        }
Ejemplo n.º 4
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());
            }
        }
Ejemplo n.º 5
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!"));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <TSEmail> > CheckEmail(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user/checkemail")] HttpRequest req,
            ILogger log)
        {
            TSEmail result = new TSEmail
            {
                To            = string.Empty,
                OperationCode = 0
            };

            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()));

                result.Result = "Error";
                return(result);
            }
            else
            {
                if (string.IsNullOrEmpty(tsEmail.To))
                {
                    await CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, "tsEmail to is empty!", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                    result.Result = "Error";
                    return(result);
                }
            }

            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 Email", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            CosmosDocUser user = await CosmosAPI.cosmosDBClientUser.FindUserByEmail(tsEmail.To, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            if (user is null)
            {
                result.Result = "OK";
            }
            else
            {
                result.Result = "Email already exists";
            }

            return(result);
        }
Ejemplo n.º 7
0
        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());
            }
        }