0

I know that this has been asked a few times in the past but the solutions provided all worked for ExpressionEngine2. Now that I'm working on v3, I have a problem that I hope somebody could help me with.

I am using a standard login form using Solspace's User module. When you login or logout you are presented with a system message page explaining that you have logged in/out. I know these system message pages are customizable to an extent but what I'd really like is to bypass them completely.

Has anyone found a way to do this? It just adds an unnecessary step that I'd like to get rid of if possible.

Thanks

2

I've created a really basic extension to bypass the default message. It redirects to an account page on login and the home page on logout but this could be modified to point to any URL (i.e. a custom message landing page)

I've included a link to the download but should that expire you'll need to copy/save these two files into system/user/addons/loginbypass/

ext.loginbypass.php

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Loginbypass_ext
{
    var $name = 'Login Bypass';
    var $version = '1.0.0';
    var $description = 'Bypasses default ExpressionEngine login/logout messages';

    public function activate_extension()
    {
        /**
         * As far as I understand, these two hooks take place after authentication
         * so you don't need to worry about any of that
         **/
        $this->add_hook('member_member_login_single');
        $this->add_hook('member_member_logout');
    }

    public function disable_extension()
    {
        ee()->db->where('class', __CLASS__);
        ee()->db->delete('extensions');
    }

    public function update_extension($current = '')
    {
        if ($current == '' || (version_compare($current, $this->version) === 0))
        {
            return false;
        }
    }

    public function member_member_login_single()
    {
        ee()->load->helper('url');

        // Change $url to wherever you need to redirect on login
        $url = site_url() . 'account';
        // Side note: this should be site_url('account') but it isn't working for my install

        redirect($url);
        return FALSE;
    }

    public function member_member_logout()
    {
        ee()->load->helper('url');

        // Change $url to wherever you need to redirect on logout
        $url = site_url();
        redirect($url);
        return FALSE;
    }

    private function add_hook($name, $priority = 10)
    {
        ee()->db->insert('extensions', 
            array(
                'class'    => __CLASS__,
                'method'   => $name,
                'hook'     => $name,
                'settings' => '',
                'priority' => $priority,
                'version'  => $this->version,
                'enabled'  => 'y'
            )
        );
    }
}

addon.setup.php

<?php
return array(
    'author'         => 'Kieran McClung',
    'author_url'     => 'https://github.com/kieranmcclung',
    'docs_url'       => 'https://github.com/kieranmcclung/ee-loginbypass',
    'name'           => 'Login Bypass',
    'description'    => 'Bypasses default ExpressionEngine login/logout messages',
    'version'        => '1.0.0',
    'namespace'      => 'Loginbypass',
    'settings_exist' => FALSE
);

Download link for extension

| improve this answer | |

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.