Skip to content

Commit 42e29db

Browse files
committedDec 31, 2011
Add Account Unlock button to manage_user_edit_page.php
The button is displayed when it is not possible to reset the user's password as defined by custom function auth_can_change_password(), $g_max_failed_login_count > 0 and the user's failed login count is higher than this threshold. Prior to this, in the case where it is not possible to reset a user's password and $g_max_failed_login_count > 0, the administrator's only way to reset the failed login count was direct SQL update. This was introduced by commit aa48e0c. Fixes #13690
1 parent 454c1f1 commit 42e29db

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed
 

‎lang/strings_english.txt

+2
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ If you requested this verification, visit the following URL to change your passw
896896

897897
# manage_user_page.php
898898
'edit_user_title' => 'Edit User',
899+
'account_unlock_button' => 'Unlock Account',
899900
'reset_password_button' => 'Reset Password',
900901
'delete_user_button' => 'Delete User',
901902
'reset_password_msg' => 'Reset Password sends the confirmation URL via e-mail.',
@@ -908,6 +909,7 @@ If you requested this verification, visit the following URL to change your passw
908909
'account_reset_protected_msg' => 'Account protected. Cannot reset the password.',
909910
'account_reset_msg' => 'A confirmation request has been sent to the selected user\'s e-mail address. Using this, the user will be able to change their password.',
910911
'account_reset_msg2' => 'Account password has been set to blank...',
912+
'account_unlock_msg' => 'The account has been unlocked.',
911913

912914
# manage_user_update.php
913915
'manage_user_protected_msg' => 'Account protected. Access level and enabled protected. Otherwise, account has been updated...',

‎manage_user_edit_page.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,34 @@
171171
</form>
172172
</div>
173173

174+
<?php
175+
// User action buttons: RESET/UNLOCK and DELETE
176+
177+
$t_reset = helper_call_custom_function( 'auth_can_change_password', array() );
178+
$t_unlock = OFF != config_get( 'max_failed_login_count' ) && $t_user['failed_login_count'] > 0;
179+
$t_delete = !( ( user_is_administrator( $t_user_id ) && ( user_count_level( config_get_global( 'admin_site_threshold' ) ) <= 1 ) ) );
180+
181+
if( $t_reset || $t_unlock || $t_delete ) {
182+
?>
174183
<div id="manage-user-actions-div" class="form-container">
175-
<?php if( helper_call_custom_function( 'auth_can_change_password', array() ) ) { ?>
184+
185+
<!-- Reset/Unlock Button -->
186+
<?php if( $t_reset || $t_unlock ) { ?>
176187
<form id="manage-user-reset-form" method="post" action="manage_user_reset.php" class="action-button">
177188
<fieldset>
178-
<?php echo form_security_field( 'manage_user_reset' ) ?>
179-
<input type="hidden" name="user_id" value="<?php echo $t_user['id'] ?>" />
189+
<?php echo form_security_field( 'manage_user_reset' ) ?>
190+
<input type="hidden" name="user_id" value="<?php echo $t_user['id'] ?>" />
191+
<?php if( $t_reset ) { ?>
180192
<span><input type="submit" class="button" value="<?php echo lang_get( 'reset_password_button' ) ?>" /></span>
193+
<?php } else { ?>
194+
<span><input type="submit" class="button" value="<?php echo lang_get( 'account_unlock_button' ) ?>" /></span>
195+
<?php } ?>
181196
</fieldset>
182197
</form>
183198
<?php } ?>
184199

185200
<!-- Delete Button -->
186-
<?php if ( !( ( user_is_administrator( $t_user_id ) && ( user_count_level( config_get_global( 'admin_site_threshold' ) ) <= 1 ) ) ) ) { ?>
201+
<?php if ( $t_delete ) { ?>
187202
<form id="manage-user-delete-form" method="post" action="manage_user_delete.php" class="action-button">
188203
<fieldset>
189204
<?php echo form_security_field( 'manage_user_delete' ) ?>
@@ -193,8 +208,9 @@
193208
</form>
194209
<?php } ?>
195210
</div>
211+
<?php } ?>
196212

197-
<?php if( !$t_ldap ) { ?>
213+
<?php if( $t_reset ) { ?>
198214
<div class="important-msg">
199215
<?php
200216
if ( ( ON == config_get( 'send_reset_password' ) ) && ( ON == config_get( 'enable_email_notification' ) ) ) {

‎manage_user_reset.php

+22-12
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@
6363
# current user.
6464
access_ensure_global_level( $t_user['access_level'] );
6565

66-
if ( !helper_call_custom_function( 'auth_can_change_password', array() ) ) {
67-
trigger_error( ERROR_LOST_PASSWORD_NOT_ENABLED, ERROR );
66+
# If the password can be changed, we reset it, otherwise we unlock
67+
# the account (i.e. reset failed login count)
68+
$t_reset = helper_call_custom_function( 'auth_can_change_password', array() );
69+
if ( $t_reset ) {
70+
$t_result = user_reset_password( $f_user_id );
71+
} else {
72+
$t_result = user_reset_failed_login_count_to_zero( $f_user_id );
6873
}
6974

7075
$t_result = user_reset_password( $f_user_id );
@@ -77,18 +82,23 @@
7782
echo '<br />';
7883
echo '<div>';
7984

80-
if ( false == $t_result ) {
81-
# PROTECTED
82-
echo lang_get( 'account_reset_protected_msg' ) . '<br />';
83-
} else {
84-
# SUCCESS
85-
if ( ( ON == config_get( 'send_reset_password' ) ) && ( ON == config_get( 'enable_email_notification' ) ) ) {
86-
# send the new random password via email
87-
echo lang_get( 'account_reset_msg' ) . '<br />';
85+
if( $t_reset ) {
86+
if ( false == $t_result ) {
87+
# PROTECTED
88+
echo lang_get( 'account_reset_protected_msg' ) . '<br />';
8889
} else {
89-
# email notification disabled, then set the password to blank
90-
echo lang_get( 'account_reset_msg2' ) . '<br />';
90+
# SUCCESSFUL RESET
91+
if ( ( ON == config_get( 'send_reset_password' ) ) && ( ON == config_get( 'enable_email_notification' ) ) ) {
92+
# send the new random password via email
93+
echo lang_get( 'account_reset_msg' ) . '<br />';
94+
} else {
95+
# email notification disabled, then set the password to blank
96+
echo lang_get( 'account_reset_msg2' ) . '<br />';
97+
}
9198
}
99+
} else {
100+
# UNLOCK
101+
echo lang_get( 'account_unlock_msg' ) . '<br />';
92102
}
93103

94104
print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );

0 commit comments

Comments
 (0)
Please sign in to comment.