示例#1
0
        public ActionResult Logon(LoginModel model, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_captchaShow)
                    {
                        if (!model.Captcha.ToLower().Equals(Session[ConstantKeys.CaptchaSession].ToString().ToLower()))
                        {
                            return Json(new { Status = 0, Message = "Enter security code not correct!" });
                        }
                    }
                    var userLogon = _userService.GetUserByUsername(model.UserName);
                    if (userLogon == null || userLogon.IsAdmin == false || userLogon.Active == false)
                    {
                        return Json(new { Status = 0, Message = "User name not correct!" });
                    }
                    //Encrypt password
                    var passwordEncryptInput = EncryptProvider.EncryptPassword(model.Password.Trim(), userLogon.PasswordSalt);

                    if (userLogon.Password.Equals(passwordEncryptInput))
                    {
                        _userinfo = new UserInfo();

                        _userinfo.ID = userLogon.UserId;
                        _userinfo.UserName = userLogon.UserName;
                        _userinfo.Email = userLogon.Email;
                        _userinfo.FullName = userLogon.FullName;
                        _userinfo.Image = userLogon.Image;
                        _userinfo.Active = userLogon.Active;

                        var roleDto = _roleService.Find(userLogon.RoleId);
                        //_userinfo.BitMask = new List<int>();
                        if (roleDto != null)
                        {
                            //int tempBitMask = GlobalFunctions.GetBitMaskOfUser(roleDto.MaskPermission);
                            //_userinfo.BitMask.Add(tempBitMask);

                            //check role
                            CheckPermUser(roleDto.MaskPermission, ref _userinfo);
                            _userinfo.MaskPermission = roleDto.MaskPermission;
                        }

                        System.Web.HttpContext.Current.Session[ConstantKeys.UserInfo] = _userinfo;

                        var UrlStr = Request.UrlReferrer.Query;
                        string UrlReturn = string.IsNullOrEmpty(UrlStr) ? "/admin/Dashboard/" : UrlStr.Split('=')[1];

                        return Json(new { Status = 1, ReturnUrl = (UrlReturn) });
                    }

                    else
                    {
                        return Json(new { Status = 0, Message = "User name or password not correct!" });

                    }

                }

            }
            catch (Exception)
            {
                return Json(new { Status = 0, Message = "User name or password not correct!" });
            }
            return Redirect("/");
        }
示例#2
0
 //
 // GET: /Login/
 public ActionResult Index()
 {
     var model = new LoginModel();
     model.CaptchaShow = _captchaShow;
     if (!_captchaShow)
     {
         model.Captcha = "captcha";
     }
     return View(model);
 }