'通用事件头
Dim fl As String = ProjectPath & "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 Verified As Boolean '用于标记用户是否通过了身份验证
Dim UserName As String = e.Cookies("username") '从cookie中获取用户名
Dim Password As String = e.Cookies("password") '从cookie中获取用户密码
If e.Path = "logon.htm" '如果是通过登录页面访问,从PostValues即可中提取用户名和密码
If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then
UserName = e.PostValues("username")
Password = MD5Encrypt(e.PostValues("password"))
End If
End If
'读取数据库验证用户密码进行比较
If UserName IsNot Nothing Then
UserName = System.Text.RegularExpressions.Regex.replace(UserName,"[+\-'#%/]", "") '过滤掉非法字符
End If
Dim dr As DataRow
Dim filter As String = "[name] = '" & UserName & "'"
dr = DataTables("Uesers").Find(filter)
If dr IsNot Nothing Then
If Password = dr("pw") Then
Verified = True
End If
End If
If Verified AndAlso e.Path = "logon.htm" Then '如果用户访问的是登录页,且身份验证成功
wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
wb.AppendCookie("password",Password)
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
e.WriteString(wb.Build) '生成网页
Return '必须的
ElseIf Verified = False
If e.path = "newuser.htm"
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到注册页
Else If e.path = "reset.htm" Then
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到重置页
Else If e.Path <> "logon.htm" Then '如果用户身份验证失败,且访问的不是登录页面
wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面
e.WriteString(wb.Build) '生成网页
Return '必须的
End If
End If
'开始生成网页
Select Case e.path
Case "logon.htm" '登录页面
Functions.Execute("Logon",e)
Case "exit.htm" '退出登录
Functions.Execute("exit",e)
Case "","default.htm" '首页
Functions.Execute("Default",e,UserName)
Case "addnew.htm" '增加
Functions.Execute("AddNew",e,UserName)
Case "edit.htm" '编辑
Functions.Execute("Edit",e,UserName)
Case "delete.htm" '删除行
Functions.Execute("Delete",e,UserName)
Case "list.htm" '查看详情
Functions.Execute("List",e,UserName)
Case "gimima.htm" '更改密码
Functions.Execute("GiMima",e,UserName)
Case "newuser.htm" '查看详情
Functions.Execute("NewUser",e)
Case "reset.htm"
Functions.Execute("Reset",e)
End Select
e.WriteString(wb.Build) '生成网页