Skip to content

Commit

Permalink
Re-authentication flow to trigger credential page
Browse files Browse the repository at this point in the history
The re-authentication flow now triggers the credentials page
since it doesn’t need to ask for username.
  • Loading branch information
vboctor committed Apr 16, 2017
1 parent 1d1c9ad commit 0247210
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
29 changes: 21 additions & 8 deletions core/authentication_api.php
Expand Up @@ -177,15 +177,28 @@ function auth_login_page( $p_query_string = '' ) {
$t_auth_flags = auth_flags();
$t_login_page = $t_auth_flags->getLoginPage();

if( !is_blank( $p_query_string ) ) {
if( stripos( $t_login_page, '?' ) !== false ) {
$t_login_page .= '&' . $p_query_string;
} else {
$t_login_page .= '?' . $p_query_string;
}
return helper_url_combine( $t_login_page, $p_query_string );
}

/**
* Gets the page that asks the user for credentials based on the user's authentication model.
*
* @param string $p_query_string The query string, can be empty.
* @param int|null $p_user_id The user id or null for current logged in user.
* @return string The credentials page with query string.
*/
function auth_credential_page( $p_query_string = '', $p_user_id = null ) {
if( is_null( $p_user_id ) ) {
$p_user_id = auth_get_current_user_id();
}

$t_url = 'login_password_page.php';
if( $p_user_id === NO_USER || !user_exists( $p_user_id ) ) {
return helper_url_combine( $t_url, $p_query_string );
}

return $t_login_page;
# TODO: consult with auth plugins
return helper_url_combine( $t_url, $p_query_string );
}

/**
Expand Down Expand Up @@ -998,7 +1011,7 @@ function auth_reauthenticate() {
);

# redirect to login page
print_header_redirect( auth_login_page( $t_query_params ) );
print_header_redirect( auth_credential_page( $t_query_params ) );
}
}

Expand Down
20 changes: 20 additions & 0 deletions core/helper_api.php
Expand Up @@ -705,3 +705,23 @@ function helper_filter_by_prefix( array $p_set, $p_prefix ) {
return $t_matches;
}

/**
* Combine a Mantis page with a query string. This handles the case where the page is a native
* page or a plugin page.
* @param string $p_page The page (relative or full)
* @param string $p_query_string The query string
* @return string The combined url.
*/
function helper_url_combine( $p_page, $p_query_string ) {
$t_url = $p_page;

if( !is_blank( $p_query_string ) ) {
if( stripos( $p_page, '?' ) !== false ) {
$t_url .= '&' . $p_query_string;
} else {
$t_url .= '?' . $p_query_string;
}
}

return $t_url;
}
23 changes: 15 additions & 8 deletions login_password_page.php
Expand Up @@ -77,22 +77,29 @@
print_header_redirect( $t_redirect_url );
}

/*
TODO: Redirect to appropriate auth page based on provided username, if doesn't exist fallback
to native password page (this page).
# Get the user id and based on the user decide whether to continue with native password credential
# page or one provided by a plugin.
$t_user_id = auth_get_user_id_from_login_name( $t_username );
if( $t_user_id === false ) {
if( $t_user_id !== false && auth_credential_page() != 'login_password_page.php' ) {
$t_query_args = array(
'error' => 1,
'return' => $f_return,
'username' => $t_username,
'cookie_error' => $f_cookie_error,
'reauthenticate' => $f_reauthenticate,
);

if( !is_blank( $f_error ) ) {
$t_query_args['error'] = $f_error;
}

if( !is_blank( $f_cookie_error ) ) {
$t_query_args['cookie_error'] = $f_cookie_error;
}

$t_query_text = http_build_query( $t_query_args, '', '&' );

$t_redirect_url = auth_login_page( $t_query_text );
$t_redirect_url = auth_credential_page( $t_query_text, $t_user_id );
print_header_redirect( $t_redirect_url );
}
*/

if( config_get_global( 'email_login_enabled' ) ) {
$t_username_label = lang_get( 'username_or_email' );
Expand Down

0 comments on commit 0247210

Please sign in to comment.