Skip to content

Commit

Permalink
Make ‘can_use_standard_login’ as bool
Browse files Browse the repository at this point in the history
No need for threshold since auth flags are per user.
Also no need for a separate can set password, since
if standard login is enabled, we check the native auth provider
and decide that.
  • Loading branch information
vboctor committed Apr 16, 2017
1 parent ed30569 commit 90a6b73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
10 changes: 3 additions & 7 deletions core/authentication_api.php
Expand Up @@ -260,7 +260,7 @@ function auth_logout_redirect_page() {
function auth_can_set_password( $p_user_id = null ) {
$t_auth_flags = auth_flags( $p_user_id );

if( !$t_auth_flags->getCanSetPassword() ) {
if( !$t_auth_flags->getCanUseStandardLogin() ) {
return false;
}

Expand All @@ -280,12 +280,8 @@ function auth_can_set_password( $p_user_id = null ) {
* @return bool true: can login using username and passord, false otherwise.
*/
function auth_can_use_standard_login( $p_user_id = null ) {
$t_auth_flags = auth_flags();
if( $p_user_id === NO_USER ) {
return $t_auth_flags->getUseStandardLoginThreshold() === ANYBODY;
}

return access_has_global_level( $t_auth_flags->getUseStandardLoginThreshold(), $p_user_id );
$t_auth_flags = auth_flags( $p_user_id );
return $t_auth_flags->getCanUseStandardLogin();
}

/**
Expand Down
30 changes: 6 additions & 24 deletions core/classes/AuthFlags.class.php
Expand Up @@ -37,23 +37,17 @@
*/
class AuthFlags {
/**
* Indicates whether the user can set their password within MantisBT or not.
* Indicates whether user can use the native login via passwords in MantisBT database.
* @var bool|null
*/
private $can_set_password = null;
private $can_use_native_login = null;

/**
* The message to display indicating that passwords are not managed by MantisBT native passwords.
* @var string|null
*/
private $password_managed_elsewhere_message = null;

/**
* The access level or array of access levels that can use native MantisBT login.
* @var int|array|null
*/
private $access_level_can_use_standard_login = null;

/**
* The login page to use instead of the standard MantisBT login page. This can be
* a plugin page.
Expand Down Expand Up @@ -121,14 +115,6 @@ class AuthFlags {
function __construct() {
}

function setCanSetPassword( $p_enabled ) {
$this->can_set_password = $p_enabled;
}

function getCanSetPassword() {
return is_null( $this->can_set_password ) ? true : $this->can_set_password;
}

function setPasswordManagedExternallyMessage( $p_message ) {
$this->password_managed_elsewhere_message = $p_message;
}
Expand All @@ -139,16 +125,12 @@ function getPasswordManagedExternallyMessage() {
}
}

function setUserStandardLoginThreshold( $p_threshold ) {
$this->access_level_can_use_standard_login = $p_threshold;
function setCanUseStandardLogin( $p_enabled ) {
$this->can_use_native_login = $p_enabled;
}

function getUseStandardLoginThreshold() {
if( is_null( $this->access_level_can_use_standard_login ) ) {
return ANYBODY;
}

return $this->access_level_can_use_standard_login;
function getCanUseStandardLogin() {
return is_null( $this->can_use_native_login ) ? true : $this->can_use_native_login;
}

function setLoginPage( $p_page ) {
Expand Down

0 comments on commit 90a6b73

Please sign in to comment.