jquery - How can I trigger my login modal (popover) when authentication is required? -
I am creating a Rail 4 app and using the device for authentication. When the user tries to access a URL, which requires authentication, Devise redirects the user to the login page to create a new session.
I decided to keep AJAX login requests confidential for things by configuring Devise and allowing the user to log in through a model form. Its work is far too great when the user navigates to the 'login' button in the user navbar, the model is displayed, the user enters his credentials, the AJAX request is processed, and the model is dismissed.
However, the modal login form can only be triggered by clicking on the 'Login' button in my nav bar. Whenever the user tries to reach such a URL for which authentication is required, the user is still redirected to the Divis login page. Instead of being redirected to the login page, I would like to display the login modal. Authentication is required, so how can I trigger my login mode (popover)?
Here's a quick overview that I am currently using my own login mode as a model ....
< Code> $ (function () {$ ("# modal_trigger"). LAN model ({top: 200, overlay: 0.6, closeboot button: ".modal_close"})}}; My nav bar is triggered by clicking on the login button ...
"login", "#model ", Category:" Sign-up ", ID:" modal_trigger "%> And here is the model view ...
& lt; Div class = "user_login" & gt; For the & lt;% = form_for processing, like: source_name, url: session_path (source_name), html: {id: "sign_in_user"}, Remote: true do | F | & Gt%; & Lt;% = f.label: email% & gt; & Lt;% = f.text_field: email% & gt; & Lt; Br / & gt; & Lt;% = f.label: Password% & gt; & Lt;% = f.password_field: Password% & gt; & Lt;% If devise_mapping.rememberable? & Gt%; & Lt; Div class = "checkbox" & gt; & Lt;% = f.check_box: remember_me% & gt; & Lt;% = f.label "Remember me on this computer"%> & Lt; / Div & gt; & Lt;% end% & gt; & Lt;% = f.submit "Login", Category: "BTN BTn_read"%> & Lt;% end% & gt; & Lt; / Div & gt; Thanks in advance for your knowledge! Please tell me that I need to post more code.
Based on one of the following priorities:
- I want the user to hit the target page and then show the model
- I want to first login modal show first redirect the user signup < / Li>
for preference
1- First of all the users who want to make the public public first_filter authenticator Leave the test
skip_before_filter: authenticate_user! 2- If the user is not signed, then partly triggers the model
- unless user_signed_in is not? JavaScript: $ (function Loginmodlsop () {$ ( "# modal_trigger"). Lanmodl ({top: 200, overlay: 0.6, Clojbutn: ".modal_close"})}}; 3- ure partially presenting at the end of the scene
partially presented: "partial_name" for priority
-
models add an application helpful to trigger
def link_to (name = zero option = zero, Html_options = zero, and blocks) html_options , Option, name = option, name, block_given if blog ? Option || = {} html_options = Knhwart_pakshn_to_deta_utpadnon (option, html_options) url = url_for (option) html_options [ 'href'] || = url If url.present? If not html_options [ "need_login"] and log? Html_options .delete "data-toggle" html_options.delete "data-remote" html_options.delete "data-target" html_options.delete "data-method" html_options [ 'href'] = '#' html_options [ 'onclick'] = "loginModalShow (); "Html_options ['class'] =" "If html_options ['class'] Zero? Html_options [ 'class'] = html_options [ 'class'] end content_tag (: a, name || url, html_options, and block) end -
Then you want on each link login trigger module, the following
link_to your_path, require_login: true
-
Create Part that triggers model If the user is not signed in
- until user_signed_in? : Javascript $ (function loginModelShop () {$ ("# modal_trigger"). LAN model ({top: 200, overlay: 0.6, closebutton: ".modal_close"}}}}
- Add the following
= partial render to your application layout: "partial_name"
Comments
Post a Comment