コード例 #1
0
ファイル: UserHandler.cs プロジェクト: RoviABC/ABInvVP
        public BaseAPIResponse CheckLoginStatus(int userId, string ip)
        {
            var result = new BaseAPIResponse();

            try
            {
                UsersHelper help = new UsersHelper();
                List<ABiAdminUsers> list = help.getUsersByID(userId);
                if (list != null && list.Count > 0)
                {
                    ABiAdminUsers obj = list[0];
                    if (!obj.Status)
                    {
                        result.ResponseCode = (int)APIResponseCode.User_Locked;
                        result.ResponseMessage = "用户被锁或用户不存在";
                    }
                    else if (obj.LoginStatus != "1" || obj.LastLogin < DateTime.Now.AddMinutes(-15))
                    {
                        result.ResponseCode = (int)APIResponseCode.Login_Expired;
                        result.ResponseMessage = "登录过期,请重新登录";
                    }
                    else
                    {
                        obj.LastLogin = DateTime.Now;
                        obj.LoginStatus = "1";
                        obj.IPAddress = ip;//Request.UserHostAddress;
                        help.updateUsersLastLogin(obj);

                        result.ResponseCode = (int)APIResponseCode.Success;
                        result.ResponseMessage = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                result.ResponseCode = (int)APIResponseCode.System_Error;
                result.ResponseMessage = ex.Message;
            }

            return result;
        }
コード例 #2
0
ファイル: BasePage.cs プロジェクト: RoviABC/ABInvVP
 /// <summary>
 /// 验证登陆信息,单点登陆及防止非法登陆
 /// </summary>
 public void CheckUser(HttpCookie cookie)
 {
     UsersHelper help=new UsersHelper();
     List<ABiAdminUsers> list = help.getUsersByID(this.UserID);
     if (list != null && list.Count > 0)
     {
         ABiAdminUsers obj = list[0];
         if (obj.LastLogin<DateTime.Now.AddMinutes(-15))
             this.GoLogin("登陆已失效,您被强制退出");
         else
         {
             obj.LastLogin = DateTime.Now;
             obj.LoginStatus = "1";
             obj.IPAddress = Request.UserHostAddress;
             help.updateUsersLastLogin(obj);
             cookie.Value = obj.LastLogin.ToString();
             Response.AppendCookie(cookie);
         }
     }
     else
         this.GoLogin(String.Format("登陆已失效,请重新登陆"));
 }