コード例 #1
0
        public void Add(string userName, string barcode, string password, string firstName, int homeBranchID, int roleID, string email, bool isActive, bool canApproveDocument)
        {
            Employee emp = new Employee();

            emp.UserName           = userName;
            emp.Barcode            = barcode;
            emp.FirstName          = firstName;
            emp.HomeBranchID       = homeBranchID;
            emp.RoleID             = roleID;
            emp.Email              = email;
            emp.IsActive           = isActive;
            emp.CanApproveDocument = canApproveDocument;
            EntityHelper.SetAuditFieldForInsert(emp, principal.Identity.Name);
            context.Add(emp);

            var userAtBranch = new UserAtBranch()
            {
                BranchID = homeBranchID, UserName = userName
            };

            context.Add(userAtBranch);

            context.SaveChanges();

            securityProvider.ChangePassword(userName, password);
        }
コード例 #2
0
        public void ChangePassword()
        {
            //given
            var me        = SeedData.CreateAdminUser(Context);
            var dummyUser = SeedData.CreateUser(Context, "Terminator", "Asta la vista");
            ISecurityProvider provider = new SecurityProvider(Context, me);
            //when
            var setNewPassword = provider.ChangePassword(dummyUser.Id, "John Connor");

            //then
            setNewPassword.ShouldBeTrue();
        }
コード例 #3
0
 public ActionResult ChangePassword(ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (securityProvider.ValidateUser(CurrentUserName, model.OldPassword))
         {
             securityProvider.ChangePassword(CurrentUserName, model.NewPassword);
             return(RedirectToAction("ChangePasswordConfirmation"));
         }
         ModelState.AddModelError(this.GetType().FullName, "Unable to validate current password");
     }
     return(RedirectToAction("ChangePassword"));
 }
コード例 #4
0
 public ActionResult ChangePassword(ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (securityProvider.ValidateUser(CurrentUserName, model.OldPassword))
         {
             securityProvider.ChangePassword(CurrentUserName, model.NewPassword);
             return(RedirectToAction("ChangePasswordSuccess"));
         }
         else
         {
             TempData["message"] = "Password lama salah.";
             RedirectToAction("ChangePassword");
         }
     }
     return(RedirectToAction("ChangePassword"));
 }
コード例 #5
0
 public ActionResult ChangePassword(ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (securityProvider.ValidateUser(CurrentUserName, model.OldPassword))
         {
             securityProvider.ChangePassword(CurrentUserName, model.NewPassword);
             ModelState.Clear();
             return(RedirectToAction("ChangePasswordSuccess"));
         }
         else
         {
             ModelState.AddModelError("", "Current/old password is invalid");
             RedirectToAction("ChangePassword");
         }
     }
     return(RedirectToAction("ChangePassword"));
 }
コード例 #6
0
        public ActionResult ChangePassword(FormCollection form, ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (securityProvider.ValidateUser(User.Identity.Name, model.NewPassword))
                    {
                        securityProvider.ChangePassword(User.Identity.Name, model.NewPassword);
                        return(RedirectToAction("ChangePasswordSuccess"));
                    }

                    ModelState.AddModelError(String.Empty, "Old password is invalid.");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(String.Empty, ex.Message);
                    Logger.ErrorException(ex.Message, ex);
                }
            }
            return(RedirectToAction("ChangePassword"));
        }