Cas' Community

Andere Informatie

Not a true plugin but a simple solution to enable admin-approval for new users

Started by administrator, 22 Apr 2024, 12:09:25

Previous topic - Next topic

administrator

How to activate admin approval for new users
Tested on Mantis 2.26.1 using php 8.2

When a new user register him/her-self on the Mantis site, tha account is created like normal.
Only difference is that the account is not yet enabled.
That needs to be done by someone with rights to get in user management.
These new accounts are trackable by filtering on the text as defined by $s_new_account (added to the language file, see below).
Do ensure that you want to see the disabled accounts too.
So all you need to do is to enabe the account and prefeably remove the temp realname (not mandatory).
That's it, now the new user can logon with the passowrd provided earlier.

Since the Mantis dev team is thinking about a more sophisticated solution (hence no real interest in this option) , I make this simple solution available as is.

Enjoy,
Cas

in core/config.php add the following lines:
/**
 * Initiate Admin approval for new users
 * When this is enabled, users that signup need to be validated by the admkin
 * @global integer $g_admin_approval
 */
$g_admin_approval = ON;

in core/constant_inc.php add the following line:
define( 'ERROR_ACCOUNT_DISABLED', 817 );

In lang/strings_english.txt add the following lines:
$s_admin_approval_msg = 'Congratulations, you have registered successfully ! After review by the administrator , you will be sent a confirmation e-mail to verify your e-mail address. Visiting the link sent to you in this e-mail will activate your account.';
$s_new_account = '=New Account=';
$MANTIS_ERROR[ERROR_ACCOUNT_DISABLED] = 'Your account has not yet been approved by the Administration, please come back later.';

In signup.php make the following change:
Replace the line
<?php echo lang_get'password_emailed_msg' ?>
with
<?php
if ( 
config_get_global'admin_approval') ) {
echo lang_get'admin_approval_msg' ) ;
} else {
echo lang_get'password_emailed_msg' ) ;
}
?>


in verify.php add the following.
Find line stating
$f_confirm_hash = gpc_get_string( 'confirm_hash' );
After that insert:
# check if account needs to be enabled first
if ( !user_is_enabled( $f_user_id ) ) {
trigger_error( ERROR_ACCOUNT_DISABLED, ERROR );
}

Finally in core user_api.php lookup function user_signup.
Within that function, you simply replace the following line:
return user_create( $p_username, $t_password, $p_email, auth_signup_access_level() );
with
# check if user approval is required, if so do not enable user yet
if (config_get_global( 'admin_approval') ) {
return user_create( $p_username, $t_password, $p_email, auth_signup_access_level(), false, false, lang_get( 'new_account' ) );
} else {
return user_create( $p_username, $t_password, $p_email, auth_signup_access_level() );
}
   
   

Powered by EzPortal