If e.Path = "logon.htm" '验证用户名和密码
If e.GetValues.ContainsKey("ok") Then
UserName = e.Cookies("username")
UserID = e.Cookies("userid")
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.InsertHTML("<meta http-equiv='Refresh' content='0; url=/default.htm'>") '直接跳转到首页
e.WriteString(wb.Build) '生成网页
Return '必须的
Else
wb.AppendCookie("username","") '将用户名和密码写入cookie
wb.AppendCookie("userid","")
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 = "张三" AndAlso Password = "888" Then '实际使用的时候,请改为从数据库读取用户名和密码进行比较
Verified = True
ElseIf Username = "李四" AndAlso Password="999" Then
Verified = True
End If
If Verified Then
UserID = Rand.NextString(16) '生成随机用户ID
UserName = EncryptText(UserName,"123","123") '将用户名加密.
wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
wb.AppendCookie("userid",UserID)
Dim dr As DataRow = UserTable.Find("UserName = '" & UserName & "'")
If dr IsNot Nothing Then '如果是重复登录,删除以前的登录信息
With wb.AddMsgPage("","msgpage","温馨提示","其它设备还有未完成的工作,保留请点击取消,不保留请点击确定完成登录!")
.Icon = "warn"
.AddButton("btn1","确定","logon.htm?ok=1")
.AddButton("btn2","取消","logon.htm").kind = 1
End With
e.WriteString(wb.Build) '生成网页
Return '必须的
End If
dr = UserTable.AddNew()
dr("UserName") = UserName
dr("UserID") = UserId
dr("ActiveTime") = Date.Now '记录登录时间
wb.InsertHTML("<meta http-equiv='Refresh' content='0; url=/default.htm'>") '直接跳转到首页
e.WriteString(wb.Build) '生成网页
Return '必须的
End If
End If
End If
Else '其它页面从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