首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >登录多页网站(安全栈)

登录多页网站(安全栈)
EN

Stack Overflow用户
提问于 2022-11-30 21:09:09
回答 1查看 69关注 0票数 1

是否有人使用StackOverflow 上Maxime Mangel为多页应用程序指定的Elmish路由(在我的例子中是安全堆栈),但使用了登录页?

同时,您是否使用埃尔米什书中这里指定的可访问性(匿名/登录)哲学?

如果是这样的话,您可能使用与Elmish不同的编码(就像我所做的那样),但无论如何,您可能需要在主页(Main.fs)中获得可用的登录结果来实现可访问性逻辑。Elmish使用(在Login.fs中)一个具有活动模式let (|UserLoggedIn|_|) = ...的函数,该函数从主页面或主页(请看这里)调用。

但这在我的应用程序里行不通。

所以我的问题是:

如何将登录结果从登录页面(Login.fs)转移到主页(Main.fs)?

您可以在下面的代码中很容易地发现我的登录结果:

Login.fs //客户端

代码语言:javascript
复制
let update (msg: Msg) (model: Model) : Model * Cmd<Msg> =

    match msg with
    | SetUsrInput value -> { model with InputUsr = value }, Cmd.none
    | SetPswInput value -> { model with InputPsw = value }, Cmd.none
    | SendUsrPswToServer ->
        let buttonClickEvent = SharedLoginValues.create model.InputUsr model.InputPsw
        let cmd = Cmd.OfAsync.perform getLoginApi.login buttonClickEvent GetLoginResults 
        model, cmd   
    | GetLoginResults value -> 
        let result =           
            match value with
            | SharedApi.UsernameOrPasswordIncorrect    -> { model with User = ApplicationUser.Anonymous}
            | SharedApi.LoggedIn user ->                  { model with User = ApplicationUser.LoggedIn user}     
        result, Cmd.ofMsg AskServerForSecurityTokenFile

同时,我使用一个解决方法,以达到我保存在服务器上的登录结果。尽管可访问性逻辑如预期的那样工作,但解决方法似乎很麻烦--我已经在登录页面中获得了登录结果,所以为什么两次访问它们…

在这里,应该使用登录结果的是Main.fs中可访问性逻辑的代码。顺便说一句,这段代码比Elmish书中的代码要简单得多,这让我很惊讶。

Main.fs //客户端

代码语言:javascript
复制
let private setRoute (optRoute: RouterM.Route option) model = 
                                             
    let model =
        let applicationUser = 
            //model.GetSecurityTokenFile -> this is the workaround
            // - results from the login page should be matched here instead
            match model.GetSecurityTokenFile with
            | true  -> LoggedIn model.user
            | false -> Anonymous

        let currentRoute =
            //model.GetSecurityTokenFile -> this is the workaround
            // - results from the login page should be matched here instead
            match model.GetSecurityTokenFile with
            | true  -> optRoute
            | false -> Some RouterM.Route.Home //or to a login page

        {
            model with CurrentRoute = currentRoute
                                      User = applicationUser  
        }                          

好吧,只要2倍的match,就这样了。还是我错过了什么?

代码语言:javascript
复制
match optRoute with
//...some code       

| Some (RouterM.Route.CMSRozcestnik cmsRozcestnikId) ->               
    match model.User with
    | Anonymous ->  
               let (homeModel, homeCmd) = Home.init () //or Login.init      
               { model with ActivePage = Page.Home homeModel }, cmd2 HomeMsg homeCmd AskServerForDeletingSecurityTokenFile
    | LoggedIn user  ->
               let (cmsRozcestnikModel, cmsRozcestnikCmd) = CMSRozcestnik.init cmsRozcestnikId 
               { model with ActivePage = Page.CMSRozcestnik cmsRozcestnikModel }, Cmd.map CMSRozcestnikMsg cmsRozcestnikCmd 
    | _     -> let (homeModel, homeCmd) = Home.init () //or Login.init      
               { model with ActivePage = Page.Home homeModel }, cmd2 HomeMsg homeCmd AskServerForDeletingSecurityTokenFile  

如果需要,整个代码都在GitHub:https://github.com/MiroslavHustak/SAFE-Stack-simple-multipage-website-with-CMS-

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-12-01 17:37:27

我已经收到了我的问题从马克西姆曼格尔通过F#斯拉克的答案。查看下面链接中的“让孩子与父通信”一节,并注意消息ExternalMsg。然后将代码实现到您的系统中。它适用于我的密码。

https://medium.com/@MangelMaxime/my-tips-for-working-with-elmish-ab8d193d52fd

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74634183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档