Пример #1
0
 public IActionResult ModifyUser(ModifyUserModel model)
 {
     if (!AuthorizeService.AuthorizeUser(User, model.Id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             Response response = UserService.UpdateUser(model.Id, model.Username);
             if (response.IsSuccessful)
             {
                 return(RedirectToAction("Success"));
             }
             else
             {
                 ModelState.AddModelError(string.Empty, response.Message);
                 return(View(model));
             }
         }
         else
         {
             return(View(model));
         }
     }
 }
Пример #2
0
 public IActionResult Modify(ModifyCurrentUserModel model)
 {
     if (!AuthorizeService.AuthorizeUser(User, model.Id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             User     user     = ModelConverter.ConvertFromUserModifyCurrnetUserModel(model);
             Response response = UserService.UpdateUser(user);
             if (response.IsSuccessful)
             {
                 return(RedirectToAction("Success"));
             }
             else
             {
                 ModelState.AddModelError(string.Empty, response.Message);
                 return(View(model));
             }
         }
         else
         {
             return(View(model));
         }
     }
 }
        public IActionResult Modify(int id)
        {
            if (AuthorizeService.AuthorizeUser(User, id))
            {
                return(RedirectToAction("AccessDenied", "Auth"));
            }
            var user       = userService.GetById(id);
            var modifyUser = ModelConverter.ConvertToUserModifyModel(user);

            return(View(modifyUser));
        }
Пример #4
0
        public IActionResult Details(int id)
        {
            if (!AuthorizeService.AuthorizeUser(User, id))
            {
                return(RedirectToAction("Auth", "AccessDenied"));
            }

            var user      = UsersService.GetById(id);
            var viewModel = ModelConvertor.ConvertToUserDetailsModel(user);

            return(View(viewModel));
        }
Пример #5
0
        public IActionResult ChangePassword(int id)
        {
            if (!AuthorizeService.AuthorizeUser(User, id))
            {
                return(RedirectToAction("Auth", "AccessDenied"));
            }

            var model = new UserChangePassModel();

            model.Id = id;
            return(View(model));
        }
Пример #6
0
 public IActionResult Modify(int id)
 {
     if (!AuthorizeService.AuthorizeUser(User, id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         ModifyCurrentUserModel model = ModelConverter.ConvertToModifyCurrentUserModel(UserService.GetById(id));
         return(View(model));
     }
 }
Пример #7
0
 public IActionResult GiveAdminRole(int id)
 {
     if (!AuthorizeService.AuthorizeUser(User, id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         UserService.GiveAdminRole(id);
         return(RedirectToAction("ModifyUsers"));
     }
 }
Пример #8
0
 public IActionResult Details(int id)
 {
     if (!AuthorizeService.AuthorizeUser(User, id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         User             user  = UserService.GetById(id);
         UserDetailsModel model = ModelConverter.ConvertToUserDetailsModel(user);
         return(View(model));
     }
 }
Пример #9
0
        public IActionResult Delete(int id)
        {
            if (!AuthorizeService.AuthorizeUser(User, id))
            {
                return(RedirectToAction("Auth", "AccessDenied"));
            }

            UsersService.Delete(id);

            if (Convert.ToInt32(User.FindFirst("Id").Value) == id)
            {
                return(RedirectToAction("Auth", "SignOut"));
            }
            return(RedirectToAction("UserModified"));
        }
Пример #10
0
        public IActionResult ChangePassword(UserChangePassModel userChangePassModel)
        {
            if (!AuthorizeService.AuthorizeUser(User, userChangePassModel.Id))
            {
                return(RedirectToAction("Auth", "AccessDenied"));
            }

            if (ModelState.IsValid)
            {
                UsersService.ChangePassword(userChangePassModel.Id, userChangePassModel.Password);
                return(RedirectToAction("UserModified"));
            }

            return(View(userChangePassModel));
        }
Пример #11
0
        public IActionResult Delete(int id)
        {
            if (!AuthorizeService.AuthorizeUser(User, id))
            {
                return(RedirectToAction("AccessDenied", "Auth"));
            }
            userService.Delete(id);

            if (Convert.ToInt32(User.FindFirst("Id").Value) == id)
            {
                RedirectToAction("SignOut", "Auth");
            }

            return(RedirectToAction("SuccessfulUserChange"));
        }
Пример #12
0
        public IActionResult Delete(int id)
        {
            if (!AuthorizeService.AuthorizeUser(User, id))
            {
                return(RedirectToAction("AccessDenied", "Auth"));
            }

            usersService.Delete(id);

            logsService.Log("Delete", $"Requested for user id: {id}", Convert.ToInt32(User.FindFirst("Id").Value));

            if (Convert.ToInt32(User.FindFirst("Id").Value) == id)
            {
                return(RedirectToAction("SignOut", "Auth"));
            }

            return(RedirectToAction("SuccessfulUserChange"));
        }
Пример #13
0
 public IActionResult ChangePassword(ChangePassword model)
 {
     if (!AuthorizeService.AuthorizeUser(User, model.Id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             UserService.ChangePassword(model.Id, model.Password);
             return(RedirectToAction("Success"));
         }
         else
         {
             return(View(model));
         }
     }
 }
Пример #14
0
 public IActionResult RemoveAdminRole(int id)
 {
     if (!AuthorizeService.AuthorizeUser(User, id))
     {
         return(RedirectToAction("AccessDenied", "Auth"));
     }
     else
     {
         UserService.RemoveAdminRole(id);
     }
     if (Convert.ToInt32(User.FindFirst("Id").Value) == id)
     {
         return(RedirectToAction("SignOut", "Auth"));
     }
     else
     {
         return(RedirectToAction("ModifyUsers"));
     }
 }
Пример #15
0
        public IActionResult Modify(UserModifyModel model)
        {
            if (AuthorizeService.AuthorizeUser(User, model.Id))
            {
                return(RedirectToAction("AccessDenied", "Auth"));
            }
            if (ModelState.IsValid)
            {
                var user   = ModelConverter.ConvertFromUserModifyModel(model);
                var result = userService.ModifyUser(user);
                if (result.Status)
                {
                    RedirectToAction("SuccessfulUserChange");
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }

            return(View(model));
        }