Foxtable(狐表)用户栏目专家坐堂 → 移动页面逻辑问题


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

主题:移动页面逻辑问题

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


加好友 发短信
等级:七尾狐 帖子:1536 积分:10849 威望:0 精华:0 注册:2016/9/12 11:18:00
移动页面逻辑问题  发帖心情 Post By:2017/3/9 13:57:00 [只看该作者]

具体移动页面如下:
1.首页:展示所有商品
2.商品详情:展示具体商品详细情况(商品详情页功能:如果会员登录了,可以购买;若未登录,转向登录页面;
3.登录:(会员在登录页面添加中级的"username""password"Cookies,并Dim Verified As Boolean '标记用户是否通过了身份验证;登录后,即跳转回到商品详情页面,我的问题是:回到商品详情页面后,还需再验证e.Cookies("username")、e.Cookies("password"),或者是再验证Verified,确认会员是否已经登录?会员等详细信息,比如性别、地址等等,是不是也需要添加导cookies里?
4.注册:
5.完善资料:注册后,完善资料用

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/3/9 14:36:00 [只看该作者]

 直接用帮助文档的例子,就能实现你的功能。每次进入的时候,都会验证用户和密码的。

 

http://www.foxtable.com/mobilehelp/scr/0138.htm

 

http://www.foxtable.com/mobilehelp/scr/0154.htm

 


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


加好友 发短信
等级:七尾狐 帖子:1536 积分:10849 威望:0 精华:0 注册:2016/9/12 11:18:00
  发帖心情 Post By:2017/3/9 15:32:00 [只看该作者]

下面是移动开发指南设计首页和登录页面的一段代码
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 = e.PostValues("password")
    End 
If

End
 If

Dim dr As DataRow = DataTables("密码表").Find("用户名 = '" & username & "'")    ‘前面请教了,这里已经修改过了

If dr IsNot Nothing AndAlso dr("密码") = password then

    Verified  = True

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 AndAlso e.Path <> "logon.htm" Then '如果用户身份验证失败,且访问的不是登录页面
    wb.InsertHTML("<meta http-equiv='Refresh' c>"
'
那么直接跳转到登录页面
    e.WriteString(wb.Build) 
'
生成网页
    Return 
'
必须的
End
 If
下面是函数调用页面的一段代码
Select Case e.Path
    Case "index.htm"                      '首页
        Functions.Execute("index",e)
    Case "details.htm"                    '详情页面
        Functions.Execute("details",e)
    Case "login.htm"                      '登录页面
        Functions.Execute("login",e)
    Case "getback.htm"                    '找回密码页面
        Functions.Execute("getback",e)
    Case "register.htm"                   '注册第1页,手机注册
        Functions.Execute("register",e)
    Case "protocol.htm"                   '注册第2页,服务协议
        Functions.Execute("protocol",e)
    Case "fillout.htm"                    '注册第3页,完善资料
        Functions.Execute("fillout",e)
    Case "images.htm"                     '注册第4页,上传照片
        Functions.Execute("images",e)
End Select
上述所有代码放到httprequest下,进入每个函数调用页面,都会验证用户和密码,对么?
[此贴子已经被作者于2017/3/9 15:36:17编辑过]

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/3/9 15:41:00 [只看该作者]

 是的。

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/3/9 15:48:00 [只看该作者]

不过,尽量不要每次都find,这样会影响效率。判断cookies是否有值,有值就直接跳过好了。


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


加好友 发短信
等级:七尾狐 帖子:1536 积分:10849 威望:0 精华:0 注册:2016/9/12 11:18:00
  发帖心情 Post By:2017/3/9 20:35:00 [只看该作者]

以下代码放到httprequest中,考虑5楼的效率问题,将3楼代码做了7处改动,具体见下面粉色字体,还请帮看看,谢谢!
Dim fl As String = "e:\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  '(1.删除此行,是否可以? 好像这里不需要框架) 
Dim Verified As Boolean = False '用于标记用户是否通过了身份验证(2.考虑到每次访问页面,都执行此行代码,每次都重新定义且赋值为空,把这个变量定义到全局变量,当Verified为false时,执行下面的代码)
If Verified = False Then
    Dim UserName As String = e.Cookies("username") '从cookie中获取用户名  (3.我感觉这里不需要赋值,因为都是登录后Verified为true,才赋值)
    Dim Password As String = e.Cookies("password") '从cookie中获取用户密码(4.我感觉这里不需要赋值,因为都是登录后Verified为true,才赋值)
    If e.Path = "login.htm" '如果是通过登录页面访问,从PostValues即可中提取用户名和密码(5.我的登录页面是login.htm,改为login.htm)
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then
            UserName = e.PostValues("username")
            Password = e.PostValues("password")
        End If
    End If
    Dim dr As DataRow = DataTables("密码表").Find("用户名 = '" & username & "'") 
    If dr IsNot Nothing AndAlso dr("密码") = password Then
        Verified  = True
    End If
    If Verified AndAlso e.Path = "login.htm"  Then '如果用户访问的是登录页,且身份验证成功
        wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
        wb.AppendCookie("password",Password)
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页(6.我的主页是127.0.0.1/index.htm,请教此行怎么写?)
        e.WriteString(wb.Build) '生成网页
        Return '必须的
    ElseIf Verified = False AndAlso e.Path <> "login.htm" Then '如果用户身份验证失败,且访问的不是登录页面
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面(7.我的登录页是127.0.0.1/login.htm,请教此行怎么写?)
        e.WriteString(wb.Build) '生成网页
        Return '必须的
    End If
End If
Select Case e.Path
    Case "index.htm"                                      '首页
        Functions.Execute("index",e)
    Case "details.htm"                                    '详情页面
        Functions.Execute("details",e)
    Case "login.htm"                                      '登录页面
        Functions.Execute("login",e)
    Case "getback.htm"                                    '找回密码页面
        Functions.Execute("getback",e)
    Case "register.htm"                                   '注册第1页,手机注册
        Functions.Execute("register",e)
    Case "protocol.htm"                                   '注册第2页,服务协议
        Functions.Execute("protocol",e)
    Case "fillout.htm"                                    '注册第3页,完善资料
        Functions.Execute("fillout",e)
    Case "images.htm"                                     '注册第4页,上传照片
        Functions.Execute("images",e)
    Case "success.htm"                                    '注册第5页,注册成功
        Functions.Execute("success",e)
    Case "personal.htm"                                   '个人中心
        Functions.Execute("personal",e)
End Select
[此贴子已经被作者于2017/3/9 20:36:17编辑过]

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/3/9 20:44:00 [只看该作者]

1、可以不用wb,但下面的代码你就不能直接用wb了,要改成别的;用框架也没什么问题

 

2、你这种设计逻辑,是有问题的,你这个服务器项目,是任意多个人使用的,不能用全局变量,只能用cookies

 

3、看2,只能用cookies判断

 

4、看2

 

5、6、7 比如 wb.InsertHTML("<meta http-equiv='Refresh' content='0; url=/index.htm'>") '直接跳转到首页

[此贴子已经被作者于2017/3/9 20:44:03编辑过]

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


加好友 发短信
等级:七尾狐 帖子:1536 积分:10849 威望:0 精华:0 注册:2016/9/12 11:18:00
  发帖心情 Post By:2017/3/9 21:06:00 [只看该作者]

这样看来,3楼代码比较靠谱
怎么样才能不每次find?如何判断cookies是否有值,有值就直接跳过?

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/3/9 21:32:00 [只看该作者]

比如,可以直接判断

 

If e.Cookies.ContainsKey("username") Then '如果登陆成功了 username 的cookie就有值了

 

End If


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


加好友 发短信
等级:七尾狐 帖子:1536 积分:10849 威望:0 精华:0 注册:2016/9/12 11:18:00
  发帖心情 Post By:2017/3/9 21:49:00 [只看该作者]

'开始生成网页
Select
 Case e.path
    
Case "logon.htm" '登录页面
        wb.AddPageTitle("","pageheader","销售系统","由湛江辉迅基于Foxtable开发"
  (我觉得下面这行if语句,当username和password都存在,才执行。既然都存在,我无法理解,如何判断用户名密码错误的,麻烦说说,谢谢)
        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",
"
销售系统","由湛江辉迅基于Foxtable开发")
        With wb.AddGrid("","g1")
            .Add("c1",
"
增加订单""./images/button.png").Attribute = ""
            .Add("c2","
客户管理""./images/cell.png""http://www.foxtable.com")
            .Add("c3",
"
销售统计""./images/toast.png""http://www.foxtable.com")
            .Add("c4","Dialog""./images/dialog.png""http://www.foxtable.com")
            .Add("c5","Progress""./images/progress.png""http://www.foxtable.com")
            .Add("c6","Msg""./images/msg.png""http://www.foxtable.com")
            .Add("c7","Article""./images/article.png""http://www.foxtable.com")
            .Add("c8","ActionSheet""./images/actionSheet.png""http://www.foxtable.com")
            .Add("c9","Icons""./images/icons.png""http://www.foxtable.com")
            .Add("c10","Panel""./images/panel.png""http://www.foxtable.com")
            .Add("c11","Tab""./images/tab.png""http://www.foxtable.com")
            .Add("c12",
"
退出""./images/exit.png""exit.htm"'退出登录
        End 
With

End
 Select
e
.WriteString(wb.Build) '生成网页
[此贴子已经被作者于2017/3/9 21:49:35编辑过]

 回到顶部
总数 11 1 2 下一页