Beispiel #1
0
        public ActionResult SignIn(string account, string password)
        {
            if (string.IsNullOrWhiteSpace(account))
            {
                throw new Exception("账号不能为空");
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("密码不能为空");
            }

            account = account.Trim();

            try
            {
                var userInfo = _accountServer.Get(account);
                if (userInfo != null && userInfo.Password == password)
                {
                    Session[ConstDefined.SessionKey] = userInfo;
                    var sessinId = StringExt.Base64Encode(userInfo.Id.ToString(), null);
                    Response.Cookies.Add(new HttpCookie(ConstDefined.CookieKey, sessinId));
                }
                else
                {
                    throw new CustomException("登录失败。账号不存在或密码不正确");
                }
            }
            catch (Exception ex)
            {
                throw new CustomException(ex.Message);
            }

            return(JsonContent(true));
        }
Beispiel #2
0
        bool CreateSession(string sessionid)
        {
            long id;
            var  str_id = StringExt.Base64Decode(sessionid, null);

            Int64.TryParse(str_id, out id);
            var user = adminServer.Get((long)id);//UserDAL.Instance.Get(id);

            if (user != null)
            {
                CurrentAccount = user.MapTo <AccountSessionInfo>();
                //将SessionID写到客户端,以备会话过期时再用它保持会话
                SessionId = sessionid;
                if (OnCreateSession != null)
                {
                    OnCreateSession.Invoke();
                }
                return(true);
            }

            return(false);
        }