【问题标题】:ng-token-auth and devise token auth confirmation redirect urlng-token-auth 并设计令牌身份验证确认重定向 url
【发布时间】:2017-06-23 22:01:57
【问题描述】:

我知道这个问题被问了很多,而且我看到了很多似乎不适用于我的问题的解决方案,所以如果我遗漏了什么,我深表歉意。

当使用带有 ng-token-auth 和 devise-token-auth 的 Devise 视图发送确认电子邮件时,确认电子邮件链接没有redirect_url,点击它时会显示一个错误页面,但是确认 api调用成功。

ng-token-auth 我设置的配置中: confirmationSuccessUrl: 'http://localhost:8000/#!/login'

devise_token_auth.rb 我还设置了: config.default_confirm_success_url = 'http://localhost:8000/#!/login'

我还尝试按照许多其他解决方案中的建议覆盖ConfirmationsController,但均无济于事。

通过在confrimation_url 调用中添加redirect_url 来编辑设计视图confirmation_instructions.html.erb,我有一个临时工作:

confirmation_url(@resource, redirect_url:'http://localhost:8000/#!/login', confirmation_token: @token)

提前致谢,如果我可以提供任何其他信息,请告诉我。

【问题讨论】:

    标签: ruby-on-rails angularjs devise


    【解决方案1】:

    似乎链接总是发送HTTP 406,所以对象总是有错误,但并不总是消息。目前,我已经通过重写确认控制器来实现(一个丑陋的)解决方案:

     def show
        self.resource = resource_class.confirm_by_token(params[:confirmation_token])
        yield resource if block_given?
    
        if resource.errors.messages.empty?
            set_flash_message!(:notice, :confirmed)
            #respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
            if signed_in?(resource_name)
                #signed_in_root_path(root_path)
                redirect_to root_path + '#!/users/' + resource.id.to_s
            else
                redirect_to root_path + '#!/login'
            end
        else
            respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
        end
    end
    

    这将在最坏的情况下重定向到登录页面。由于确认 api 调用实际上正在工作,用户可以登录。如果失败,我可以显示一条消息,指示他们应该尝试重新发送确认电子邮件。

    如果有人知道更好的解决方案或我做错了什么导致HTTP 406,请告诉我!

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 2013-03-01
      • 1970-01-01
      • 2021-12-29
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多