我正尝试在单独的前端使用ng-token-auth (Angular 1),以允许在Ruby on Rails 5.0后端重置密码和确认帐户电子邮件地址。
单击访问身份验证api的链接后,我将被重定向至以下链接:
http://localhost:8080/?client_id=<client_id>&config=default&expiry=<expiry_stamp>reset_password=true&token=<token>&uid=<email address>#/reset-password
/#/reset-password部分位于重置链接的末尾。
我认为为了让angular和我的函数正常工作,我需要类似于:http://localhost:8080/#/reset-password?client_id=&config=&expiry=&reset_password=&token=&uid=的东西。
在app/views/devise/mailer/reset_password_instructions.html.erb中,我有以下模板代码:
<p><%= t(:hello).capitalize %> <%= @resource.email %>!</p>
<p><%= t '.request_reset_link_msg' %></p>
<p><%= link_to t('.password_change_link'), edit_password_url(@resource, reset_password_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url'].to_s).html_safe %></p>
<p><%= t '.ignore_mail_msg' %></p>
<p><%= t '.no_changes_msg' %></p>在我的前端app.js中,我使用以下内容配置$authProvider:
function AuthSetup($authProvider) {
$authProvider.configure({
apiUrl: 'http://localhost:3000',
passwordResetSuccessUrl: 'http://localhost:8080/#/reset-password'
});
}我非常感谢任何人能提供的任何帮助或指导。谢谢。
发布于 2017-02-10 20:39:03
抱歉,回复晚了。我所做的就是覆盖Rails后端的Devise::ConfirmationController,它对我很有效。
分享下面的代码片段:
class User::ConfirmationsController < Devise::ConfirmationsController
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource)
respond_with_navigational(resource){ redirect_to after_confirmation_path }
else
redirect_to after_confirmation_path, notice: 'Not a valid token'
end
end
protected
def after_confirmation_path
return 'http://localhost:4000' if Rails.env.dev?
'http://example.com'
end
end如果令牌是有效的,那么它将登录用户,并将他们重定向到您的angular代码正在运行的前端站点,如果令牌无效,则会将他们重定向到带有flash消息的站点。如果你需要任何帮助来理解这段代码,请告诉我。
https://stackoverflow.com/questions/42058555
复制相似问题