コード例 #1
0
 /// <summary>
 /// Rilk:Check permission to add into user information variable
 /// </summary>
 /// <param name="bitMask">bitmask of user</param>
 /// <param name="usInfo">userinfor variables</param>
 private void CheckPermUser(long bitMask, ref UserInfo usInfo)
 {
     switch (bitMask)
     {
         case (int)RoleType.SA: usInfo.IsSA = true; break;
         case (int)RoleType.Administrator: usInfo.IsAdmin = true; break;
         case (int)RoleType.Manager: usInfo.IsManager = true; break;
         default: usInfo.IsUser = true; break;
     }
 }
コード例 #2
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("/");
        }