コード例 #1
0
        public ActionResult ChangePassword(ChangePasswordDto model)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();
            var username = ((Identity)ControllerContext.HttpContext.User.Identity).Name;

            var userToEdit = _securityService.GetUser(username);

            ViewBag.IsFirstLogIn = userToEdit.IsFirstLogIn;

            if (userToEdit.AccountType != Constants.AccountType.LocalLocal && userToEdit.AccountType != Constants.AccountType.LocalFinacle)
            {
                this.Danger(string.Format("{0}<br />{1}", Constants.Messages.EditNotPermittedError, "Password can only be changed on source system"), true);
                return(View(userToEdit));
            }

            _securityService.UserChangePassword(username, model.OldPassword, model.NewPassword, model.ConfirmPassword, ref states);

            if (!states.IsValid)
            {
                var errorList = ValidationHelper.BuildModelErrorList(states);
                Danger(string.Format("{0}<br />{1}", Constants.Messages.ErrorNotice, errorList), true);
                ModelState.AddModelErrors(states);
                SetAuditInfo(Helper.StripHtml(errorList, true), JsonConvert.SerializeObject(model), username);
                return(View(model));
            }
            else
            {
                Success("<b>Password change</b> was successfully saved to the database.", true);
                SetAuditInfo("Successful", JsonConvert.SerializeObject(model), username);
                return(View("ChangePasswordSuccess"));
            }
        }
コード例 #2
0
 public ActionResult EditRole(RoleViewModel model)
 {
     {
         ValidationStateDictionary states = new ValidationStateDictionary();
         var updated = _securityService.EditRole(model, ref states);
         if (!states.IsValid)
         {
             var errorList = ValidationHelper.BuildModelErrorList(states);
             Danger(string.Format("{0}<br />{1}", Constants.Messages.ErrorNotice, errorList), true);
             ModelState.AddModelErrors(states);
             SetAuditInfo(Helper.StripHtml(errorList, true), string.Empty);
             return(View(model));
         }
         else
         {
             if (updated == 0)
             {
                 Warning(Constants.Messages.ConcurrencyError, true);
             }
             else
             {
                 Success(Constants.Messages.SaveSuccessful, true);
             }
             return(RedirectToAction("EditRole", new { id = model.CurrentRole.RoleId }));
         }
     }
 }
コード例 #3
0
        public ActionResult LogIn(LogInDto model)
        {
            bool IsSuccess = false;
            var  url       = string.Empty;
            var  errorList = string.Empty;

            if (ModelState.IsValid)
            {
                ValidationStateDictionary states = new ValidationStateDictionary();
                bool isFirstLogIn = false;
                bool status       = Access.SignIn(model.Username, model.Password, model.TokenCode, _securityService, _finacleRepository, out isFirstLogIn, ref states);

                if ((!states.IsValid))
                {
                    IsSuccess = false;
                    errorList = ValidationHelper.BuildModelErrorList(states);
                    Danger(string.Format("{0}<br />{1}", Constants.Messages.ErrorNotice, errorList), true);
                    ModelState.AddModelErrors(states);
                }
                else
                {
                    if (!String.IsNullOrEmpty(model.ReturnUrl))
                    {
                        url       = model.ReturnUrl;
                        IsSuccess = true;
                    }
                    else
                    {
                        if (!isFirstLogIn)
                        {
                            var roleName = ((Identity)ControllerContext.HttpContext.User.Identity).Roles;
                            url       = Helper.GetRootURL() + "/admin";
                            IsSuccess = true;
                        }
                        else
                        {
                            url       = Helper.GetRootURL() + "/MyProfile/changepassword";
                            IsSuccess = true;
                        }
                    }
                }
            }

            model.Password = "******";
            SetAuditInfo(IsSuccess ? "Successful" : Helper.StripHtml(errorList, true),
                         JsonConvert.SerializeObject(model),
                         string.IsNullOrEmpty(model.Username) ? "not-supplied" : model.Username);

            if (IsSuccess)
            {
                return(new RedirectResult(url));
            }
            else
            {
                // If we got this far, something failed, redisplay form
                return(View(model));
            }
        }
コード例 #4
0
        public ActionResult ResetPassword(ResetPasswordDto model)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();

            _securityService.ResetPassword(model.Username, model.Email, ref states);
            if (!states.IsValid)
            {
                var errorList = ValidationHelper.BuildModelErrorList(states);
                Danger(string.Format("{0}<br />{1}", Constants.Messages.ErrorNotice, errorList), true);
                ModelState.AddModelErrors(states);
                return(View(model));
            }
            else
            {
                return(View("ResetPasswordMessage"));
            }
        }
コード例 #5
0
        public ActionResult CreateUser(User model)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();

            model.UserRole = new Role()
            {
                RoleId = model.RoleId, RoleName = (from r in _securityService.GetRoleList() where r.RoleId == model.RoleId select r.RoleName).FirstOrDefault()
            };
            model.InitiatedBy = ControllerContext.RequestContext.HttpContext.User.Identity.Name;
            if (model.AccountType == Constants.AccountType.LocalFinacle || model.AccountType == Constants.AccountType.ADLocal)
            {
                var flexcubeRecord = _flexCubeRepository.GetUserRoleFromFlexcube(model.Username);
                if (flexcubeRecord != null)
                {
                    model.BranchID = flexcubeRecord.BranchCode;
                }
            }

            if (model.AccountType == Constants.AccountType.ADLocal && !string.IsNullOrEmpty(model.Username))
            {
                if (!Access.IsUserInAD(model.Username))
                {
                    var errorMsg = "The user does not exist on AD or AD service could not be reached.";
                    Danger(errorMsg, true);
                    SetAuditInfo(errorMsg, string.Empty);
                    return(View(model));
                }
            }
            _securityService.AddUser(model, ref states);
            if (!states.IsValid)
            {
                model.UserRole = new Role()
                {
                    RoleId = model.RoleId
                };
                ModelState.AddModelErrors(states);
                var errorList = ValidationHelper.BuildModelErrorList(states);
                SetAuditInfo(Helper.StripHtml(errorList, true), string.Empty);
                return(View(model));
            }
            else
            {
                Success(Constants.Messages.AddSuccessful, true);
                return(RedirectToAction("EditUser", new { id = model.Username }));
            }
        }
コード例 #6
0
        public ActionResult DeleteRole(Guid id)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();

            _securityService.DeleteRole(id, ref states);
            if (!states.IsValid)
            {
                var errorList = ValidationHelper.BuildModelErrorList(states);
                Danger(string.Format("{0}<br />{1}", Constants.Messages.ErrorNotice, errorList), true);
                return(RedirectToAction("ListRole"));
            }
            else
            {
                Success(Constants.Messages.DeleteSuccessful, true);
                return(RedirectToAction("ListRole"));
            }
        }
コード例 #7
0
        private ActionResult ExecuteAction(RemittanceCashPickup model, string approvalStatus)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();

            var models           = _cashPickupService.RetrieveReference(model.ReferenceNumber);
            var dbApprovalStatus = Constants.ApprovalStatus.Pending;

            //the user that put a record in pending mode will always be stored as initiated by - meaning the db will be updated.
            var permitEdit = Access.CanEdit(Constants.Modules.RemitlyPayout, model.InitiatedBy, dbApprovalStatus, model.IsDeleted);

            if (permitEdit)
            {
                model.ApprovedStatus = approvalStatus;

                var updated = _cashPickupService.EditRemittance(model.ReferenceNumber);
                if (!states.IsValid)
                {
                    model.UserRole = new Role()
                    {
                        RoleId = model.RoleId
                    };
                    ModelState.AddModelErrors(states);
                    var errorList = ValidationHelper.BuildModelErrorList(states);
                    SetAuditInfo(Helper.StripHtml(errorList, true), string.Empty);
                    return(View(model));
                }
                else
                {
                    if (updated == null)
                    {
                        Warning(Constants.Messages.ConcurrencyError, true);
                    }
                    else
                    {
                        Success(Constants.Messages.SaveSuccessful, true);
                    }
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                Warning(Constants.Messages.EditNotPermittedError, true);
                return(RedirectToAction("Index"));
            }
        }
コード例 #8
0
        private ActionResult ExecuteAction(User model, string approvalStatus)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();

            model = _securityService.GetUser(model.Username);
            var dbApprovalStatus = Constants.ApprovalStatus.Pending;

            //the user that put a record in pending mode will always be stored as initiated by - meaning the db will be updated.
            var permitEdit = Access.InApprovableState(Constants.Modules.UserSetup, model.InitiatedBy, dbApprovalStatus, model.IsDeleted);

            if (permitEdit)
            {
                model.ApprovalStatus = approvalStatus;

                var updated = _securityService.EditUser(model, ref states);
                if (!states.IsValid)
                {
                    model.UserRole = new Role()
                    {
                        RoleId = model.RoleId
                    };
                    ModelState.AddModelErrors(states);
                    var errorList = ValidationHelper.BuildModelErrorList(states);
                    SetAuditInfo(Helper.StripHtml(errorList, true), string.Empty);
                    return(View(model));
                }
                else
                {
                    if (updated == 0)
                    {
                        Warning(Constants.Messages.ConcurrencyError, true);
                    }
                    else
                    {
                        Success(Constants.Messages.SaveSuccessful, true);
                    }
                    return(RedirectToAction("ListUser"));
                }
            }
            else
            {
                Warning(Constants.Messages.EditNotPermittedError, true);
                return(RedirectToAction("ListUser"));
            }
        }
コード例 #9
0
        public ActionResult EditUser(User model)
        {
            ValidationStateDictionary states = new ValidationStateDictionary();

            model.UserRole = new Role()
            {
                RoleId = model.RoleId, RoleName = (from r in _securityService.GetRoleList() where r.RoleId == model.RoleId select r.RoleName).FirstOrDefault()
            };
            model.InitiatedBy = ControllerContext.RequestContext.HttpContext.User.Identity.Name;

            if (Access.IsFormEditable(Constants.Modules.UserSetup, model.ApprovalStatus))
            {
                var updated = _securityService.EditUser(model, ref states);
                if (!states.IsValid)
                {
                    model.UserRole = new Role()
                    {
                        RoleId = model.RoleId
                    };
                    ModelState.AddModelErrors(states);
                    var errorList = ValidationHelper.BuildModelErrorList(states);
                    SetAuditInfo(Helper.StripHtml(errorList, true), string.Empty);
                    return(View(model));
                }
                else
                {
                    if (updated == 0)
                    {
                        Warning(Constants.Messages.ConcurrencyError, true);
                    }
                    else
                    {
                        Success(Constants.Messages.SaveSuccessful, true);
                    }
                    return(RedirectToAction("EditUser", new { id = model.Username }));
                }
            }
            else
            {
                Warning(Constants.Messages.EditNotPermittedError, true);
                return(RedirectToAction("EditUser", new { id = model.Username }));
            }
        }