示例#1
0
        public ActionResult ResetPassword(Capital.Domain.ResetPassword model)
        {
            if (ModelState.IsValid)
            {
                Capital.Domain.User user = new Capital.Domain.User()
                {
                    ConfirmPassword = model.Password,
                    UserId          = UserID,
                    UserPassword    = model.Password,
                    UserSalt        = ConfigurationManager.AppSettings["salt"].ToString(),
                };
                int res = 0;
                if (user.UserPassword != null && user.UserPassword != "")
                {
                    string salt           = ConfigurationManager.AppSettings["salt"].ToString();
                    string saltpassword   = String.Concat(salt, user.UserPassword);
                    string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(saltpassword, "sha1");

                    user.UserPassword = hashedPassword;
                    user.UserSalt     = salt;
                }

                res = (new UserRepository()).UpdateUserPassword(user);
            }
            return(RedirectToAction("LogOff"));
        }
示例#2
0
        public async Task <ActionResult> Register(Capital.Domain.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Capital.Domain.User user = new Capital.Domain.User()
                {
                    ConfirmPassword = model.Password,
                    UserEmail       = model.Email,
                    UserId          = model.UserId,
                    UserName        = model.UserName,
                    UserPassword    = model.Password,
                    UserRole        = model.UserRole,
                    UserSalt        = ConfigurationManager.AppSettings["salt"].ToString(),
                    SalesMgId       = model.SalesMgId,
                    Module          = model.Module,
                    Reporting       = model.Reporting
                };
                int res = 0;
                if ((user.UserId ?? 0) == 0)
                {
                    string salt           = ConfigurationManager.AppSettings["salt"].ToString();
                    string saltpassword   = String.Concat(salt, user.UserPassword);
                    string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(saltpassword, "sha1");

                    user.UserPassword = hashedPassword;
                    user.UserSalt     = salt;
                    user.Forms        = model.Forms.Where(x => x.hasPermission).ToList();
                    res = (new UserRepository()).InsertUser(user);
                    TempData["Success"] = "Saved Successfully!";
                }
                else
                {
                    if (user.UserPassword != null && user.UserPassword != "")
                    {
                        string salt           = ConfigurationManager.AppSettings["salt"].ToString();
                        string saltpassword   = String.Concat(salt, user.UserPassword);
                        string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(saltpassword, "sha1");

                        user.UserPassword = hashedPassword;
                        user.UserSalt     = salt;
                    }
                    user.Forms          = model.Forms.Where(x => x.hasPermission).ToList();
                    res                 = (new UserRepository()).UpdateUser(user);
                    TempData["Success"] = "Updated Successfully!";
                }
                if (res > 0)
                {
                    return(RedirectToAction("UserList"));
                }
            }
            var allErrors = ModelState.Values.SelectMany(v => v.Errors);

            ViewBag.UserRole = new SelectList((new UserRepository()).GetUserRole(), "RoleId", "RoleName");
            ViewBag.Employee = new SelectList((new SalesManagerRepository()).GetSalesManagers(), "SalesMgId", "SalesMgName");
            // If we got this far, something failed, redisplay form
            return(View(model));
        }