<!--#include file="../Start.asp"-->
<!--#include file="../Include/PowerEasy.MD5.asp"-->
<!--#include file="../API/API_Config.asp"-->
<!--#include file="../API/API_Function.asp"-->
<%
Dim sql, rs
Dim CookieDate
Dim UserPassword, RndPassword, CheckCode, ErrStr, UserStr
dim p
p=0

UserName = Replace(ReplaceBadChar(Trim(Request("UserName"))), ".", "")
UserPassword = ReplaceBadChar(Trim(Request("UserPassword")))
CheckCode = LCase(ReplaceBadChar(Trim(Request("CheckCode"))))
CookieDate = PE_CLng(Trim(Request("CookieDate")))
If EnableCheckCodeOfLogin = True Then
    If Trim(Session("CheckCode")) = "" Then
        p = 1
        ErrStr = ErrStr & "<li>验证码超时失效。</li>"
    End If
    If CheckCode <> Session("CheckCode") Then
        p = 1
        ErrStr = ErrStr & "<li>验证码错误，请重新输入。</li>"
    End If
End If
If UserName = "" Then
    p = 1
    ErrStr = ErrStr & "<li>用户名不能为空！</li>"
End If

If UserPassword = "" Then
    p = 1
    ErrStr = ErrStr & "<li>密码不能为空！</li>"
End If
Set rs = Conn.Execute("select UserID,UserName,UserPassword,LastPresentTime,LastPresentTime,IsLocked from PE_User where UserName='" & UserName & "'")
If rs.bof And rs.EOF Then
    p = 1
    ErrStr = ErrStr & "<li>用户不存在！！！</li>"
Else
    UserPassword = MD5(UserPassword, 16)
    If UserPassword <> rs("UserPassword") Then
        p = 1
        ErrStr = ErrStr & "<li>密码错误！！！</li>"
    End If
    If rs("IsLocked") = True Then
        p = 1
        ErrStr = ErrStr & "<li>用户已经被锁住，无法登录。如果您需要解锁，请与管理员联系。</li>"
    End If
	If p = 0 Then
	   RndPassword = GetRndPassword(16)
        '更新登录状态
        Conn.Execute ("Update PE_User Set LastPassword='" & RndPassword & "',LastLoginIP='" & UserTrueIP & "',LastLoginTime=" & PE_Now & ",LoginTimes=LoginTimes+1 where UserID=" & rs("UserID") & "")
        Session("UserID") = rs("UserID")
		If PresentExpPerLogin > 0 Then
            If DateDiff("D", rs("LastPresentTime"), Now()) > 0 Or IsNull(rs("LastPresentTime")) Then
                Conn.Execute ("update PE_User set UserExp=UserExp+" & PresentExpPerLogin & ",LastPresentTime=" & PE_Now & " where UserID=" & rs("UserID") & "")
                UserExp = UserExp + PresentExpPerLogin
            End If
        End If
		'更新购物车的用户名
        Dim CartID
        CartID = ReplaceBadChar(Trim(Request.Cookies("Cart" & Site_Sn)("CartID")))
        Conn.Execute ("update PE_ShoppingCarts set UserName='" & UserName & "' where CartID='" & CartID & "'")

        If Enable_SubDomain Then
            Dim iSubDomainIndex, strSite_Sn
            For iSubDomainIndex = 0 To UBound(arrSubDomains)
                strSite_Sn = LCase(arrSubDomains(iSubDomainIndex) & Replace(Replace(DomainRoot & InstallDir, "/", ""), ".", ""))
                Response.Cookies(strSite_Sn).Domain = DomainRoot
                Select Case CookieDate
                    Case 0
                        'not save
                    Case 1
                        Response.Cookies(strSite_Sn).Expires = Date + 1
                    Case 2
                        Response.Cookies(strSite_Sn).Expires = Date + 31
                    Case 3
                        Response.Cookies(strSite_Sn).Expires = Date + 365
                End Select
                Response.Cookies(strSite_Sn)("UserName") = UserName
                Response.Cookies(strSite_Sn)("UserPassword") = UserPassword
                Response.Cookies(strSite_Sn)("LastPassword") = RndPassword
                Response.Cookies(strSite_Sn)("CookieDate") = CookieDate
            Next
        Else
            Select Case CookieDate
                Case 0
                    'not save
                Case 1
                    Response.Cookies(Site_Sn).Expires = Date + 1
                Case 2
                    Response.Cookies(Site_Sn).Expires = Date + 31
                Case 3
                    Response.Cookies(Site_Sn).Expires = Date + 365
            End Select
            Response.Cookies(Site_Sn)("UserName") = UserName
            Response.Cookies(Site_Sn)("UserPassword") = UserPassword
            Response.Cookies(Site_Sn)("LastPassword") = RndPassword
            Response.Cookies(Site_Sn)("CookieDate") = CookieDate
        End If
        UserStr="您已成功登陆，欢迎您的光临!"
	GetUser(UserName)
	dim daystr ,bastr
	If (Hour(Now) < 6) Then
        daystr="|<font color=##0066FF>凌晨好!</font>"
    ElseIf (Hour(Now) < 9) Then
        daystr="|<font color=##000099>早上好!</font>"
    ElseIf (Hour(Now) < 12) Then
        daystr="|<font color=##FF6699>上午好!</font>"
    ElseIf (Hour(Now) < 14) Then
        daystr="|<font color=##FF6600>中午好!</font>"
    ElseIf (Hour(Now) < 17) Then
        daystr="|<font color=##FF00FF>下午好!</font>"
    ElseIf (Hour(Now) < 18) Then
        daystr="|<font color=##0033FF>傍晚好!</font>"
    Else
        daystr="|<font color=##ff0000>晚上好!</font>"
    End If
		UserStr=UserStr&"|"&daystr&"|"&Balance&"|"&UserExp&"|"&PointName&"|"&UserPoint&"|"&PointUnit
		If UserChargeType > 0 Then
           If ValidNum = -1 Then
            UserStr=UserStr&"|无限期"
           Else
            UserStr=UserStr&"|"& ValidDays
           End If
		else
		    UserStr=UserStr&"|0"
        End If
		If Trim(UnsignedItems & "") = "" Then
            UserStr=UserStr&"|0"
        Else
        Dim UnsignedItemNum, arrUser
        arrUser = Split(UnsignedItems, ",")
        UnsignedItemNum = UBound(arrUser) + 1
        UserStr=UserStr&"|"& UnsignedItemNum
        End If
		If UnreadMsg > 0 Then
		   UserStr=UserStr&"|"& UnreadMsg
		else
		   UserStr=UserStr&"|0"
		end if
		
		UserStr=UserStr&"|"&LoginTimes      
	End If
End If
response.Write ErrStr&";"&UserStr
'If p = 1 Then '输出错误结果
'    Call WriteErrMsg
'    Response.End
'End If
%>