Custome message for Banned user

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Custome message for Banned user

Post by bruceholt » 2020-08-22 03:54

I am trying to set a custom message that if a user is banned for whatever reason, that a custom message displays instead of "Your previous login attempt failed. Try again." that is in the language file.

I still need the original message in case the user has entered wrong username or password.

I have searched files that I think it might be in but cannot see a mention of banned.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Custome message for Banned user

Post by bruceholt » 2020-08-29 21:51

Any ideas, anyone? :shock:

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Custome message for Banned user

Post by pbottcher » 2020-09-01 20:21

Hi,

you can try this:

in hooks/__global.php set:

Code: Select all

	function login_failed($attempt, &$args){
		$banned=sqlvalue("SELECT isBanned from membership_users where memberID='".$attempt['username']."'");
		if ($banned) redirect("index.php?loginFailed=2");
	}
in login.php change

Code: Select all

<?php if($_GET['loginFailed']) { ?>
	<div class="alert alert-danger"><?php echo $Translation['login failed']; ?></div>
<?php } ?>
to

Code: Select all

<?php if($_GET['loginFailed']==2) { ?>
	<div class="alert alert-danger"><?php echo 'PUT YOUR MESSAGE FOR BANNED USERS HERE'; ?></div>
<?php } else { ?>
	<div class="alert alert-danger"><?php echo $Translation['login failed']; ?></div>
<?php } ?>
Please remember that the login.php will be overwritten when you recreate your files.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Custome message for Banned user

Post by bruceholt » 2020-09-02 09:25

Hi Pascal,

The message works beautifully when the user is banned but when signing in and out (for a user that is not banned) it shows the default message "Your previous login attempt failed. Try again." all of the time.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Custome message for Banned user

Post by pbottcher » 2020-09-02 11:10

Hi Bruce,

sorry, pls use

Code: Select all

<?php if($_GET['loginFailed']==2) { ?>
	<div class="alert alert-danger"><?php echo 'PUT YOUR MESSAGE FOR BANNED USERS HERE'; ?></div>
<?php } elseif($_GET['loginFailed']==1  { ?>
	<div class="alert alert-danger"><?php echo $Translation['login failed']; ?></div>
<?php } ?>
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Custome message for Banned user

Post by bruceholt » 2020-09-03 09:13

Hi Pascal,

Unfortunately that is returning an error:

( ! ) Parse error: syntax error, unexpected '{' in C:\wamp64\www\farmrex\login.php on line 6

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Custome message for Banned user

Post by pbottcher » 2020-09-03 10:56

Hi Bruce,

sorry, there is a missing )

Code: Select all

<?php if($_GET['loginFailed']==2) { ?>
	<div class="alert alert-danger"><?php echo 'PUT YOUR MESSAGE FOR BANNED USERS HERE'; ?></div>
<?php } elseif($_GET['loginFailed']==1)  { ?>
	<div class="alert alert-danger"><?php echo $Translation['login failed']; ?></div>
<?php } ?>
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Custome message for Banned user

Post by bruceholt » 2020-09-04 09:40

Thanks Pascal. Works perfect.

Post Reply