@yuliyepes
Ok let's try to work this out.
I think a prehook will not work because you are effectively trying to prevent login in a login form, does this make sense? I suppose a prehook could stop the entire form from processing, but its not really what is needed.
I think what you need is a standalone snippet and form which accepts and saves the inputed data, checks for any active sessions of the user, and then responds. It would look like your login on your site, the user will try to login there.
Then the response is either run login snippet (and can use the data already saved, it might still need a click by the user unless the login form can automatically run), or a message saying, user already has an active session, please close it before logging in.
I cannot write php myself, but basically
save form values,
get user table, look up user and check for sessions, or get active sessions data from the database and search for username.
IF session/username doesn't exist, then run/display login snippet/button
ELSE
username/session exists, then show message
You'd want to be sure there is no real login except for ones with this snippet standing as a gateway
HTH, let us know how you are getting along.
Quote from: yuliyepes at Jan 08, 2019, 04:34 PMIt should be easy but not. I need do not allowed the login if the user already has a session initiated (in another browser o device), because by default modx let me login many sessions.
So I have this snippet on my preHooks login:
$formFields = $hook->getValues();
$username = $formFields['username']; //take username login
$modx->user = $modx->getObject('modUser', array( //query this username
'username' => $username,
));
if ($modx->user->isAuthenticated('web') == true) { // this is empty
$modx->sendUnauthorizedPage();
}
return true;
I really appreciate any help