Resource icon

Login as User 1.2.7

No permission to download
thank you,

The error comes right mrcrypt the configuration level.
Add well exeption of modules.

Otherwise the mrcrypt not encrypt the connection and return the error javascript
 
I come to your attention an error.
Once connected to a user logout tab does not work.

Error

I come to your attention an error.
Once connected to a user logout tab does not work.

Logout ?


Code:
<xen:title>{xen:phrase liam_loginasuser}</xen:title>

<form method="post" action="{xen:link 'lau/loginasuser'}" class="xenForm formOverlay AutoValidator" data-redirect="on">
    <fieldset>
        <xen:if is="{$username}">
            <dl class="ctrlUnit fullWidth">
                <dt></dt>
                <dd style="padding-left: 0px; padding-right: 0px;">
                    <p style="text-align:center; color: red;">{xen:phrase liam_lau_mgr}</p>
                </dd>
            </dl>
        </xen:if>
    
        <dl class="ctrlUnit fullWidth">
            <dt></dt>
            <dd style="padding-left: 0px; padding-right: 0px;">
                <label for="lau_username">{xen:phrase lau_username}:</label>
                <input type="text" id="macros_hide_qr" value="{$username}" class="textCtrl AutoComplete AcSingle" name="lau_username" <xen:if is="{$username}">disabled</xen:if>/>
            </dd>
        </dl>
    
        <dl class="ctrlUnit fullWidth">
            <dt></dt>
            <dd style="padding-left: 0px; padding-right: 0px;">
                <label for="lau_reason">{xen:phrase lau_reason}:</label>
                <textarea id="lau_reason" class="textCtrl" name="lau_reason" cols="3" rows="3"></textarea>
            </dd>
        </dl>
    </fieldset>

    <input type="hidden" name="form" value="form">

    <dl class="ctrlUnit submitUnit">
        <dt></dt>
        <dd>
            <input type="submit" value="{xen:phrase liam_loginasuser}" class="button primary" accesskey="s">
            <input type="reset" class="button OverlayCloser" value="{xen:phrase cancel}">
        </dd>
    </dl>
</form>

PHP:
public function actionLogOutAsUser()
    {
        $originalhash = XenForo_Helper_Cookie::getCookie('liamloginasuser');

        if ($originalhash === false)
        {
            return $this->responseError(new XenForo_Phrase('liam_lau_cfouid'));
        }

        $key = 'liamloginasuser';
        $almostoriginalid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($originalhash), MCRYPT_MODE_CBC, md5(md5($key))), "\0");

        if ($almostoriginalid <= 0)
        {
            return $this->responseError("Fatal error occured.");
        }

        $originalid = $almostoriginalid - 5;

        if (!LiamLoginAsUser_ControllerPublic_LoginAsUser::hasPermission($originalid))
        {
            return $this->responseNoPermission();
        }

        $session = XenForo_Application::getSession();
        $options = XenForo_Application::getOptions();

        if ($options->liamlaupm)
        {
            $model = XenForo_Model::create('XenForo_Model_User');
            $rootuserfull = $model->getVisitingUserById($originalid);
            $rootuserfull['permissions'] = XenForo_Permission::unserializePermissions($rootuserfull['global_permission_cache']);
            $reason = $session->get('liam_lau_oldreason');

            //var_dump($rootuserfull);

            $visitor = XenForo_Visitor::getInstance();

            $message = new XenForo_Phrase('liam_loginasuser_pmmessage', array(

                    'reason' => $reason
            ));
            $message = $message->render();
            $subject = new XenForo_Phrase('liam_loginasuser_pmsubject');
            $subject = $subject->render();

            /* @var $pmdw XenForo_DataWriter_ConversationMaster */
            $pmdw = XenForo_DataWriter::create('XenForo_DataWriter_ConversationMaster');
            $pmdw->setExtraData(XenForo_DataWriter_ConversationMaster::DATA_ACTION_USER, $rootuserfull);
            $pmdw->setExtraData(XenForo_DataWriter_ConversationMaster::DATA_MESSAGE, $message);
            $pmdw->set('user_id', $originalid);
            $pmdw->set('username', $rootuserfull['username']);
            $pmdw->set('title', $subject);
            $pmdw->set('open_invite', false);
            $pmdw->set('conversation_open', 1);

            $pmdw->addRecipientUserNames(array(

                    $visitor['username']

            ));

            $messageDw = $pmdw->getFirstMessageDw();
            $messageDw->set('message', $message);

            $pmdw->save();

            $convomodel = XenForo_Model::create('XenForo_Model_Conversation');
            $conversation = $pmdw->getMergedData();

            $convomodel->markConversationAsRead($conversation['conversation_id'], $originalid, XenForo_Application::$time);
        }

        unset($rootuserfull);

        XenForo_Helper_Cookie::setCookie('liamloginasuser', false);

        /* @var $sessionmodel XenForo_Model_Session */
        $sessionmodel = XenForo_Model::create('XenForo_Model_Session');

        $sessionmodel->processLastActivityUpdateForLogOut(XenForo_Visitor::getUserId());
        $session->delete();

        $session = XenForo_Session::startPublicSession();
        XenForo_Visitor::setup($originalid);
        $session->changeUserId($originalid);

        return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(), new XenForo_Phrase('liam_lau_lioa'));
    }
 
Last edited:
After upgrading to 1.2.1 PL1 it doesn't let me login to any user, generates server errors in ACP instead.

Rich (BB code):
ErrorException: Fatal Error: Call to undefined function mcrypt_encrypt() - library/LiamLoginAsUser/ControllerPublic/LoginAsUser.php:161

Stack Trace 
#0 [internal function]: XenForo_Application::handleFatalError()
#1 {main}

Request State 
array(3) {
["url"] => string(37) "http://localhost/lau/loginasuser"
["_GET"] => array(0) {
}
["_POST"] => array(7) {
["lau_username"] => string(5) "pink"
["lau_reason"] => string(0) ""
["form"] => string(4) "form"
["_xfRequestUri"] => string(11) "/resources/"
["_xfNoRedirect"] => string(1) "1"
["_xfToken"] => string(8) "********"
["_xfResponseType"] => string(4) "json"
}
}
 
You need the mcrypt php module, however as you're the second person without the module I'll look for an alternative @Veer.

Liam
 
Thank you @Liam W its working now (y)

I have a suggestion in mind, and I feel it is worth considering. When we login as user, our (admin's) IP is saved in that user account, and also when we post as user, the admin's IP is used and stored. That is not ideal in my opinion. Because it does share IPs and then we found difficulties in multiple id detections via IP, IP banning etc. So my suggestion is to not use admin's IP information, use user's IP instead. :)
 
Thank you @Liam W its working now (y)

I have a suggestion in mind, and I feel it is worth considering. When we login as user, our (admin's) IP is saved in that user account, and also when we post as user, the admin's IP is used and stored. That is not ideal in my opinion. Because it does share IPs and then we found difficulties in multiple id detections via IP, IP banning etc. So my suggestion is to not use admin's IP information, use user's IP instead. :)

I'll have a look into it :)

Liam
 
Issue Found:
When logging in as a User that does not have the Login As user premission, the "Logout As User" option disappears and now you have to log out entirely and log back in as yourself.
 
Here's a feature request...

I'd like to have the option for an admin to login to a user's account without a PM being sent, however, I'd like for a PM to be sent if a moderator logins to an account.
 
This works also on Admin CP? I need to have a secret super admin and a "Login as User" it's useful for fast login.
 
Top Bottom