<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Option Explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../Plus/md5.asp"-->
<!--#include file="Base64.asp"-->
<%
Response.cachecontrol = "no-cache"
Response.Addheader "pragma", "no-cache"
Response.Expires = -1
Response.expiresAbsolute = Now - 1
Response.Charset = "GB2312"
Response.Addheader "Content-Type", "text/html; charset=gb2312"

Dim HSKCls
Set HSKCls = New UserLogin
HSKCls.Run()
Set HSKCls = Nothing

Class UserLogin
        Private KS
        Private KSUser, UserID
        Private UserName, PassWord, Verifycode, ExpiresDate, RndPassword, HelperName, MachineCode, Base64Str
        Private LoginVerificCodeTF
		
        Private Sub Class_Initialize()
          Set KS = New PublicCls
          Set KSUser = New UserCls
        End Sub
		
        Private Sub Class_Terminate()
         Call CloseConn
         Set KS = Nothing
         Set KSUser = Nothing
        End Sub
        
        
        Public Sub Run()
		Base64Str = Split(Base64d(Request("q")),"|^_^|")
		If Ubound(Base64Str) <> 3 Then KS.Die "[结果]提交数据有误，请联系管理员！[/结果]"
        UserName = KS.DelSql(Base64Str(0))
        PassWord = Base64Str(1)
        HelperName = Base64Str(2)
		MachineCode = KS.DelSql(Base64Str(3))
'        ExpiresDate = KS.R(KS.S("ExpiresDate"))
        RndPassword = KS.R(KS.MakeRandomChar(20))
        If HelperName <> "HSK_Helper" Then KS.Die ""
        If UserName = "" Then
           KS.Die "[结果]用户名不能为空，请输入！[/结果]"
        End If
        If PassWord = "" Then
           KS.Die "[结果]登录密码不能为空，请输入！[/结果]"
        End If
        
        PassWord = MD5(PassWord, 16)
        Dim UserRS: Set UserRS = Server.CreateObject("Adodb.RecordSet")
        UserRS.Open "Select top 1 * From KS_User Where UserName='" & UserName & "' And PassWord='" & PassWord & "'", Conn, 1, 3
        If UserRS.EOF And UserRS.BOf Then
           UserRS.Close: Set UserRS = Nothing
           KS.Die "[结果]你输入的用户名或密码有误，请重新输入！[/结果]"
        ElseIf UserRS("Locked") = 1 Then
           UserRS.Close: Set UserRS = Nothing
           KS.Die "[结果]您的账号已被管理员锁定，请与管理员联系！[/结果]"
        ElseIf UserRS("Locked") = 3 Then
           UserRS.Close: Set UserRS = Nothing
           KS.Die "[结果]您的账号还没有激活，请注意查收您的邮箱并进行激活！[/结果]"
        ElseIf UserRS("Locked") = 2 Then
           UserRS.Close: Set UserRS = Nothing
           KS.Die "[结果]您的账号还没有通过认证！[/结果]"
        Else
		
			  If Not KS.IsNul(UserRS("KS_MachineCode")) Then
				  If UserRS("KS_MachineCode") <> MachineCode Then
					  KS.Die "[结果]您本机的机器码与原绑定的机器码不相符！请在原电脑登录软件到设置选项取消绑定或登录到官网会员中心取消绑定后再重新登录！[/结果]"
				  End If
			  Else
				  UserRS("KS_MachineCode") = MachineCode
			  End If
			
              '登录成功，更新用户相应的数据
              Dim ScoreTF: ScoreTF = False
              If KS.ChkClng(KS.U_S(UserRS("GroupID"), 8)) > 0 And KS.ChkClng(KS.U_S(UserRS("GroupID"), 9)) > 0 And DateDiff("n", UserRS("LastLoginTime"), Now) >= KS.ChkClng(KS.U_S(UserRS("GroupID"), 8)) Then '判断时间
              ScoreTF = True
              End If
              UserRS("KS_LastLoginIP") = UserRS("LastLoginIP")
              UserRS("KS_LastLoginDate") = UserRS("LastLoginTime")
              UserRS("LastLoginIP") = KS.GetIP
              UserRS("LastLoginTime") = Now()
              UserRS("LoginTimes") = UserRS("LoginTimes") + 1
              UserRS("RndPassword") = RndPassword
              UserRS("IsOnline") = 1
              '判断上一次是不是通过充值卡充值
              If UserRS("UserCardID") <> 0 Then
                Dim RSCard, ValidUnit, ExpireGroupID
                Set RSCard = Conn.Execute("Select top 1 * From KS_UserCard Where ID=" & UserRS("UserCardID"))
                If Not RSCard.EOF Then
                   ValidUnit = RSCard("ValidUnit")
                   ExpireGroupID = RSCard("ExpireGroupID")
                   If ValidUnit = 1 Then                    '点券
                     If UserRS("Point") <= 0 And ExpireGroupID <> 0 Then
                       UserRS("GroupID") = ExpireGroupID
                       UserRS("UserCardID") = 0
                       UserRS("ChargeType") = KS.ChkClng(KS.U_G(ExpireGroupID, "chargetype"))
                     End If
                   ElseIf ValidUnit = 2 Then                 '有效天数
                     If UserRS("Edays") - DateDiff("D", UserRS("BeginDate"), Now()) <= 0 And ExpireGroupID <> 0 Then
                       UserRS("GroupID") = ExpireGroupID
                       UserRS("UserCardID") = 0
                       UserRS("ChargeType") = KS.ChkClng(KS.U_G(ExpireGroupID, "chargetype"))
                     End If
                   ElseIf ValidUnit = 3 Then                '资金
                     If UserRS("Money") <= 0 And ExpireGroupID <> 0 Then
                       UserRS("GroupID") = ExpireGroupID
                       UserRS("UserCardID") = 0
                       UserRS("ChargeType") = KS.ChkClng(KS.U_G(ExpireGroupID, "chargetype"))
                     End If
                   End If
                End If
                RSCard.Close: Set RSCard = Nothing
              End If
              UserRS.Update
              Dim CurrScore: CurrScore = UserRS("KS_TotalScore") '修改为累计积分 by pwc 2010-12-28 原 UserRS("Score")
              Dim GroupID: GroupID = UserRS("GroupID")
              Dim PostNum: PostNum = KS.ChkClng(UserRS("PostNum"))
              Dim ClubSpecialPower: ClubSpecialPower = KS.ChkClng(UserRS("ClubSpecialPower"))
              UserID = UserRS("UserID")
              UserRS.Close
              Set UserRS = Nothing
              
              '更新论坛等级
              If ClubSpecialPower = 0 Then
                Dim RSG: Set RSG = Conn.Execute("select top 1 GradeID,UserTitle from KS_AskGrade where TypeFlag=1 and Special=0 and ClubPostNum<=" & PostNum & " And score<=" & CurrScore & " order by score desc,ClubPostNum Desc")
                If Not RSG.EOF Then
                Conn.Execute ("Update KS_User Set ClubGradeID=" & RSG(0) & " WHERE GroupID<>1 and UserName='" & UserName & "'")
                End If
              End If
              '更新问答等级
              Set RSG = Conn.Execute("select top 1 GradeID,UserTitle from KS_AskGrade where typeflag=0 and Special=0 and score<=" & CurrScore & " order by score desc,gradeid Desc")
              If Not RSG.EOF Then
                Conn.Execute ("Update KS_User Set GradeID=" & RSG(0) & ",GradeTitle='" & RSG(1) & "' WHERE UserName='" & UserName & "'")
              End If
              
              RSG.Close: Set RSG = Nothing
              
              
              
              If ScoreTF Then
                  Call KS.ScoreInOrOut(UserName, 1, KS.ChkClng(KS.U_S(GroupID, 9)), "系统", KS.ChkClng(KS.U_S(GroupID, 8)) & "分钟后,重新登录奖励获得", 0, 0)
              End If

              If EnabledSubDomain Then
               Response.Cookies(KS.SiteSN).domain = RootDomain
              Else
               Response.Cookies(KS.SiteSN).Path = "/"
              End If
              If ExpiresDate <> "" Then Response.Cookies(KS.SiteSN).Expires = Date + 365
              Response.Cookies(KS.SiteSN)("UserID") = UserID
              Response.Cookies(KS.SiteSN)("UserName") = UserName
              Response.Cookies(KS.SiteSN)("Password") = PassWord
              Response.Cookies(KS.SiteSN)("RndPassword") = RndPassword
			  Response.Cookies(KS.SiteSN)("HelperName") = HelperName
              Response.Redirect("UserInfo.Asp")
        End If
            
        End Sub
End Class
%>