2
  1. I have "manage" link that redirects to domain.com/login.
  2. "login" is custom front-end page that after logging in redirects to homepage.
  3. After logging in when I click "manage" again the domain.com/login redirects me to CP dashboard.
  4. Signing out from CP redirects me to default Craft login page.

  1. How to redirect directly to dashboard after logging in?
  2. How to redirect directly to domain.com/login or homepage after signing out?

I'm also using manager as cpTrigger, and this is my config:

'postLoginRedirect' => 'manager',
'logoutPath' => 'login',
'cpTrigger' => 'manager',

For some reason according to #1 postLoginRedirect doesn't take effect same for #2 and logoutPath, maybe I'm using them in the wrong way?

login/index.html code:

{% extends "login/_layout" %}
{% set title = "Welcome back, friend :)" %}
{% block content %}
          <div class="box">

          <form method="post" accept-charset="UTF-8">
          {{ getCsrfInput() }}
          <input type="hidden" name="action" value="users/login">

            {% if errorMessage is defined %}
             <article class="message is-danger">
              <div class="message-body">   
               {{ errorMessage }}
              </div>
             </article>
            {% endif %}

            <div class="field">
              <p class="control has-icon">
                <input class="input" id="loginName" type="text" name="loginName" placeholder="Email">
                <span class="icon">
                <i class="fa fa-envelope"></i>
                </span>
              </p>
            </div>

              <div class="field">
              <p class="control has-icon">
                <input class="input" id="password" type="password" name="password" placeholder="Password">
                <span class="icon">
                <i class="fa fa-lock"></i>
                </span>
              </p>
            </div>

              <div class="field">
              <p class="control">
              <label class="checkbox">
                <input type="checkbox" name="rememberMe" value="1">
                Keep me logged in
              </label>
              </p>
            </div>

              <hr>

              <p class="control">
                <button class="button is-primary" type="submit">Login</button>
                <a class="button is-default" href="{{ siteUrl }}">Cancel</a>

              </p>
          </form>
          </div>
            <p class="has-text-centered">
              <a href="{{ url('login/register') }}">Register an Account</a>
              | 
              <a href="{{ url('login/forgotpassword') }}">Forgot password</a>
              | 
              <a href="{{ url('contact') }}">Need help?</a>
            </p>
{% endblock %}
4
  • I'm having a hard time following. Can you share your domain.com/login template code? "How to redirect directly to dashboard after logging in?" Are you referring to Craft's dashboard or a front-end dashboard that you've created. – Brad Bell Apr 17 '17 at 21:05
  • Hi @BradBell I'm referring to the Craft dashboard. I added login/index.html template code to the question. – curious Apr 18 '17 at 14:09
  • ""login" is custom front-end page that after logging in redirects to homepage." If I'm following you, that's the current behavior you're seeing, but you want to change it to "1. How to redirect directly to dashboard after logging in?" – Brad Bell Apr 18 '17 at 21:49
  • @BradBell exactly – curious Apr 18 '17 at 21:58
1
  1. How to redirect directly to dashboard after logging in?

Since your login form is on the front-end of the site, the postLoginRedirect should do what you're looking for.

You can see the logic Craft uses to determine where to send a user after a successful login here: https://github.com/craftcms/cms/tree/master-v2/src/controllers/UsersController.php#L1599-L1614

How to redirect directly to domain.com/login or homepage after signing out?

You've got the logoutPath config setting set 'login', which is going to log a user out as soon as they hit the /login URI, which probably isn't what you're looking for.

There currently isn't a config setting to decide where to send a user after they've been logged out, but you could write a very simple plugin that listened to the onLogout event and redirected to wherever you wished.

3
  • I decided to stay hassle-free and keep only registration page. Craft login screen is good, no need to overwrite. Thank you anyway. – curious Apr 19 '17 at 10:04
  • 1
    Can I add a FR? Add a config setting for postLogoutRedirect that we can set. – Siebird May 16 '17 at 13:28
  • 1
    @Siebird - Yup... just create one here: github.com/craftcms/cms/issues – Brad Bell May 16 '17 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.