示例#1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipUserExtended.ValidateUser(model.UserName, model.Password))
                {
                    MembershipUserExtended.GetUser(model.UserName, true);
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        public ActionResult Edit(UserRoleViewModel userRoleModel)
        {
            var model         = userRoleModel.UserModel;
            var selectedRoles = userRoleModel.Roles;

            if (ModelState.IsValid)
            {
                try
                {
                    if (selectedRoles.Any())
                    {
                        var mUser = Membership.GetUser(model.UserName);
                        if (mUser != null)
                        {
                            mUser.Email = model.Email;

                            MembershipUserExtended.Update(mUser, model.FirstName, model.LastName,
                                                          model.Title, model.HourlyRate, model.Address, model.City,
                                                          model.State, model.Zip, model.Phone);
                        }
                        else
                        {
                            userRoleModel.Roles = Roles.GetAllRoles().ToList();
                            ModelState.AddModelError("", "Couldn't find user");
                            return(View(userRoleModel));
                        }
                        //delete all saved roles before adding new ones
                        var userSavedRoles = Roles.GetRolesForUser(model.UserName);
                        if (userSavedRoles.Any())
                        {
                            Roles.RemoveUserFromRoles(model.UserName, userSavedRoles);
                        }

                        Roles.AddUserToRoles(model.UserName, selectedRoles.ToArray());

                        var user = MembershipUserExtended.GetUser(model.UserName, false);

                        userRoleModel.UserModel = new UserModel(user);
                        userRoleModel.Roles     = Roles.GetAllRoles().ToList();
                        ViewBag.Message         = "Changes have been saved successfully";
                    }
                    else
                    {
                        userRoleModel.Roles = Roles.GetAllRoles().ToList();
                        ModelState.AddModelError("", "User must belong to atleast one Role.");
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = string.Empty;
                    ModelState.AddModelError("", ex.Message);
                }
            }
            else
            {
                userRoleModel.Roles = Roles.GetAllRoles().ToList();
            }
            // If we got this far, something failed, redisplay form
            return(View(userRoleModel));
        }
示例#3
0
        public ActionResult GetMenu()
        {
            var user = MembershipUserExtended.GetUser(HttpContext.User.Identity.Name, false);

            var userMenus = new WebMenuRole().GetMenuItemsForRoles(user.UserRoles);

            return(PartialView("_MenuPartial", userMenus));
        }
示例#4
0
 public UserRoleViewModel(string userName)
 {
     UserModel            = new UserModel(MembershipUserExtended.GetUser(userName, false));
     Roles                = System.Web.Security.Roles.GetAllRoles().ToList();
     WeeklyTimeTrackModel = TimeTrackManager.GetCurrentWeekClockInOutTime(userName);
 }