Esempio n. 1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="strUserName"></param>
        /// <param name="strPassword"></param>
        /// <returns></returns>
        public CommonResult Login(string strUserName, string strPassword)
        {
            //if(strUserName.ToLower() == AllConfigServices.SettingsConfig.SuperAdminAccount && strPassword == AllConfigServices.SettingsConfig.SuperAdminPassword)
            //{
            SysFormsAuthenticationHelper <Models.User> .SetAuthSession(strUserName, new User()
            {
                //UserID = strUserName
                UserName = strUserName,
                Password = strPassword
            });

            //return CommonResult.Instance();
            //}

            strPassword = strPassword.ToMD5();
            var userInfo = db.User.Where(u => u.UserName == strUserName && u.Password == strPassword).FirstOrDefault();

            if (userInfo != null)
            {
                int intState = (int)ItemState.Disable;
                if (userInfo.State == intState)
                {
                    return(CommonResult.Instance("账号被禁用,请联系管理员"));
                }
                else
                {
                    var q = from permission in db.Permission
                            join userPermission in db.UserPermission on permission.PermissionNo equals userPermission.PermissionID
                            join user in db.User on userPermission.UserNo equals user.UserNo
                            where user.UserNo == userInfo.UserNo
                            select permission;
                    var listRole = q.ToList();
                    if (listRole.Where(lisRole => lisRole.State == intState).Count() > 0)
                    {
                        return(CommonResult.Instance("账号所属角色被禁用,请联系管理员"));
                    }
                }
            }
            else
            {
                return(CommonResult.Instance("账号或密码错误"));
            }
            //return CommonResult.Instance();
            return(CommonResult.Instance(1, "登陆成功", userInfo));
        }
Esempio n. 2
0
 /// <summary>
 /// 从客户端cookie中获取用户信息
 /// </summary>
 /// <returns></returns>
 public User GetUserByCookie()
 {
     return(SysFormsAuthenticationHelper <User> .GetUserInstance());
 }
Esempio n. 3
0
        /// <summary>
        /// 是否已登录
        /// </summary>
        /// <returns></returns>
        public bool IsLogined()
        {
            string strUserId = SysFormsAuthenticationHelper <User> .GetUserId();

            return(!string.IsNullOrEmpty(strUserId));
        }
Esempio n. 4
0
 /// <summary>
 /// 用户登出
 /// </summary>
 public void Logout()
 {
     SysFormsAuthenticationHelper <User> .SignOut();
 }
Esempio n. 5
0
 /// <summary>
 /// 从服务端session中获取用户信息
 /// </summary>
 /// <returns></returns>
 public User GetUserBySession()
 {
     return(SysFormsAuthenticationHelper <User> .GetUserSession());
 }