--
Dim UserTable As DataTable = DataTables("userinfos") \'定义一个变量,用于存储用户随机身份ID,以及最后一次活动时间.
Static ClearTime As Date
If (Date.Now - ClearTime).TotalMinutes >= 12000 Then \'清除超过30分钟没有操作的登录信息
UserTable.DeleteFor("ActiveTime < #" & Date.Now.AddMinutes(-12000) & "#")
ClearTime = Date.Now()
End If \'通用事件头
Dim fl As String = "d:\\web\\" & e.path
If filesys.FileExists(fl)
Dim idx As Integer = fl.LastIndexOf(".")
Dim ext As String = fl.SubString(idx)
Select Case ext
Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar"
e.WriteFile(fl)
Return \'这里必须返回
End Select
End If
Dim wb As New weui \'身份验证
Dim UserName As String
Dim Password As String
Dim UserID As String
If e.Path = "denglu.html" \'验证用户名和密码
If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then
Dim Verified As Boolean \'用于标记用户是否通过了身份验证
UserName = e.PostValues("username")
Password = e.PostValues("password")
If UserName <> "" And Password <> "" Then
Dim dr1 As DataRow = DataTables("users").SQLFind("[name] = \'" & UserName & "\' and [Password] = \'" & Password & "\'")
If dr1 IsNot Nothing Then
Verified = True
Else
Verified =False
End If
Else
Verified = False
End If
If Verified Then
UserID = Rand.NextString(16)\'生成随机用户ID
UserName = EncryptText(username,"liaoyamin","liaozihao") \'将用户名加密.
Dim dr As DataRow = UserTable.Find("UserName = \'" & UserName & "\'")
If dr IsNot Nothing Then \'如果是重复登录,删除以前的登录信息
dr.Delete()
End If
dr = UserTable.AddNew()
dr("UserName") = UserName
dr("UserID") = UserId
dr("ActiveTime") = Date.Now \'记录登录时间
wb.AppendCookie("username",UserName,1200) \'将用户名和密码写入cookie
wb.AppendCookie("userid",UserID,1200)
wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页
e.WriteString(wb.Build) \'生成网页
Return \'必须的
End If
End If
Else If e.Path<> "wefox" \'其它页面从Cookie提取登录信息进行验证
UserName = e.Cookies("username") \'从cookie中获取用户名
UserID = e.Cookies("userid") \'从cookie中获取 随机ID
Dim dr As DataRow = UserTable.Find("UserName = \'" & UserName & "\'")
If dr IsNot Nothing AndAlso dr("UserID") = UserID Then \'如果通过验证,更新活动时候,继续访问其它页面.
dr("ActiveTime") = Date.Now \'更新活动时间
Else \'如果验证失败
wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
e.WriteString(wb.Build) \'生成网页
Return \'必须的
End If
End If
Select Case e.path \'开始生成网页
Case "wefox"
Functions.Execute("wefox事件",e)
Case "denglu.html" \'登录页面
Functions.Execute("登录界面",e)
Case "exit.htm" \'退出登录
Functions.Execute("退出登录",e)
Case "shouye.html" \'首页
Functions.Execute("首页",e)
Case "zhoujihuazhujiemian.html"
Functions.Execute("周计划主界面",e)
Case "zhoujihuabianji.html"
Functions.Execute("周计划编辑",e)
Case "zhoujihuaxinzeng.html"
Functions.Execute("周计划新增",e)
Case "zhoujihuaxiazhoujihua.html"
Functions.Execute("下周计划",e)
Case "zhoujihuachaxun.html"
Functions.Execute("周计划查询",e)
Case "zhoujihualist.html"
Functions.Execute("周计划list",e)
Case "zhoujihuachaxunjieguo.html"
Functions.Execute("周计划查询结果",e)
Case "test.html"
Functions.Execute("test",e)
End Select