Foxtable(狐表)用户栏目专家坐堂 → 内部函数


  共有2176人关注过本帖树形打印复制链接

主题:内部函数

帅哥哟,离线,有人找我吗?
BG小白
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:603 积分:4090 威望:0 精华:0 注册:2019/11/14 23:06:00
内部函数  发帖心情 Post By:2021/5/31 17:10:00 [只看该作者]

我把http://www.foxtable.com/mobilehelp/ 让登录变得更安全里面的代码放在了内部函数
HttpRequest事件代码里面添加了下面的代码
Dim wb As New WeUI '定义一个基于weui框架的网页生成器
Select Case e.Path
    Case "logon.htm",""
        Functions.Execute("登录",e)  
    Case "test.htm"
        Functions.Execute("测试",e)  
End Select
访问正常,但是登录后就提示foxtable web server has started(error 404).无法正常进入default.htm,这个是什么原因啊

 回到顶部
帅哥哟,离线,有人找我吗?
BG小白
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:603 积分:4090 威望:0 精华:0 注册:2019/11/14 23:06:00
  发帖心情 Post By:2021/5/31 17:12:00 [只看该作者]

函数代码
Dim e As RequestEventArgs = args(0)
Static UserTable As DataTable '定义一个变量,用于存储用户随机身份ID,以及最后一次活动时间.
Static ClearTime As Date
If UserTable Is Nothing Then '创建用于记录登录信息的临时表
    ClearTime = Date.Now()
    Dim dtb As New DataTableBuilder("UserInfos")
    dtb.AddDef("UserName", Gettype(String), 255)
    dtb.AddDef("UserID",Gettype(String),16)
    dtb.AddDef("ActiveTime",Gettype(Date))
    UserTable = dtb.Build(True)
End If
If (Date.Now - ClearTime).TotalMinutes >= 30 Then '清除超过30分钟没有操作的登录信息
    UserTable.DeleteFor("ActiveTime < #" & Date.Now.AddMinutes(-30) & "#")
    ClearTime = Date.Now()
End If
Dim wb As New weui
'身份验证
Dim UserName As String
Dim Password As String
Dim UserID As String
If e.Path = "logon.htm" '验证用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        Dim Verified As Boolean '用于标记用户是否通过了身份验证
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
        Dim dr1 As DataRow '数据库对比用户代码
        dr1 = DataTables("users").sqlFind("Name = '" & UserName & "'") 
        If dr1 IsNot Nothing AndAlso dr1("password").contains(password) Then
            Verified  = True
        End If
        If Verified Then
            UserID = Rand.NextString(16) '生成随机用户ID
            UserName = EncryptText(UserName,"123","123") '将用户名加密.
            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) '将用户名和密码写入cookie
            wb.AppendCookie("userid",UserID)
            wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
            e.WriteString(wb.Build) '生成网页
            Return"" '必须的
        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
'开始生成网页
Select Case e.path
    Case "logon.htm" '登录页面
        wb.AddPageTitle("","pageheader","管理系统","")
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then '判断是否是验证失败后的重新登录
            wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 '如果用户通过登录按钮访问,则给用户一个2秒的提示.
        End If
        wb.AddForm("","form1","logon.htm")
        With wb.AddInputGroup("form1","ipg1")
            .AddInput("username","户名","text")
            .AddInput("password","密码","password")
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "登录", "submit")
        End With
    Case "exit.htm" '退出登录
        wb.DeleteCookie("username") '清除cookie中原来的用户名和密码
        wb.DeleteCookie("password")
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '然后直接跳转到登录页面
    Case "", "default.htm" '首页
        wb.AddPageTitle("","pageheader","管理系统","")
        With wb.AddGrid("","g1")
            .Add("c1","测试", "./images/png-1549.png").Attribute = ""
            .Add("c2","暂未开通", "./images/png-1550.png").Attribute = ""
            .Add("c3","暂未开通", "./images/png-1551.png").Attribute = ""
            .Add("c4","暂未开通", "./images/png-1552.png").Attribute = ""
            .Add("c5","暂未开通", "./images/png-1553.png").Attribute = ""
            .Add("c6","暂未开通", "./images/png-1554.png").Attribute = ""
            .Add("c7","暂未开通", "./images/png-1555.png"). Attribute = ""
            .Add("c8","暂未开通", "./images/png-1556.png").Attribute = ""
            .Add("c12","退出", "./images/png-0670.png", "exit.htm") '退出登录
        End With
End Select
e.WriteString(wb.Build) '生成网页
[此贴子已经被作者于2021/5/31 17:12:57编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107135 积分:544918 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/5/31 17:29:00 [只看该作者]

Dim wb As New WeUI '定义一个基于weui框架的网页生成器
Select Case e.Path
    Case "logon.htm","","exit.htm","所有其它需要验证的页面..........
        Functions.Execute("登录",e)  
……

另外如果不理解代码逻辑的,不建议把用户验证放到函数里处理。



 回到顶部
帅哥哟,离线,有人找我吗?
BG小白
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:603 积分:4090 威望:0 精华:0 注册:2019/11/14 23:06:00
  发帖心情 Post By:2021/5/31 18:13:00 [只看该作者]

谢谢蓝老师
[此贴子已经被作者于2021/5/31 18:14:36编辑过]

 回到顶部