I want my user to be redirected to the login form if he is not logged in ?
The thing is that I don't wanna do this for every action. I know there is a way so that I may define this for every controller only once ( i.e. something executes regardless of the action in my controller ) but I can't remember how.
Set a session after login successful and in edit. php check for it, if session is not set, redirect it to homepage. Show activity on this post. Show activity on this post.
function login_redirect() { // Current Page global $pagenow; // Check to see if user in not logged in and not on the login page if(! is_user_logged_in() && $pagenow != 'wp-login. php') // If user is, Redirect to Login form.
Path: /src/_components/PrivateRoute.jsx If the user is logged in the Component prop is rendered, otherwise if the user is not logged in the React Router Redirect component is rendered which redirects the user to the /login page. The requested path ( props. location ) is passed with the redirect in the state.
Use a before_filter. Place the following in your application controller.
# application_controller.rb before_filter :require_login private def require_login unless current_user redirect_to login_url end end
The code above assumes you have defined a method current_user
which returns the user record when the user is logged in.
Then, in your login controller
skip_before_filter :require_login
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With