Permalink
Browse files

Fixes #16416: Improve first login experience by auto-redirecting to c…

…reate project page.
  • Loading branch information...
vboctor committed Sep 28, 2013
1 parent 1ac581e commit 2b5691f0775680cf945f0123da4f08857263bdcc
Showing with 29 additions and 4 deletions.
  1. +1 −1 admin/install.php
  2. +18 −0 core/project_api.php
  3. +10 −3 login_cookie_test.php
View
@@ -974,7 +974,7 @@ function InsertData( $p_table, $p_data ) {
<p><a href="../login_page.php">Continue</a> to log into Mantis</p>
<?php
} else {?>
-<p>Please log in as the administrator and <a href="../manage_proj_create_page.php">create</a> your first project.
+<p>Please log in as the administrator and <a href="../login_page.php">create</a> your first project.
<?php
}
View
@@ -55,6 +55,24 @@
$g_cache_project_missing = array();
$g_cache_project_all = false;
+# --------------------
+# Checks if there exists at least one project.
+function project_any() {
+ global $g_cache_project;
+
+ # If projects already cached, use the cache.
+ if ( isset( $g_cache_project ) && count( $g_cache_project ) > 0 ) {
+ return true;
+ }
+
+ # Otherwise, check if the projects table contains at least one project.
+ $t_project_table = db_get_table( 'mantis_project_table' );
+ $query = "SELECT * FROM $t_project_table";
+ $result = db_query_bound( $query, array(), /* limit */ 1 );
+
+ return db_num_rows( $result ) > 0;
+}
+
# --------------------
# Cache a project row if necessary and return the cached copy
# If the second parameter is true (default), trigger an error
View
@@ -27,11 +27,18 @@
*/
require_once( 'core.php' );
- $f_return = gpc_get_string( 'return', config_get( 'default_home_page' ) );
+ if ( auth_is_user_authenticated() ) {
+ $f_return = gpc_get_string( 'return' );
+ $c_return = string_prepare_header( $f_return );
- $c_return = string_prepare_header( $f_return );
+ # If this is the first login for an instance, then redirect to create project page.
+ # Use lack of projects as a hint for such scenario.
+ if ( is_blank( $f_return ) || $f_return == 'index.php' ) {
+ if ( current_user_is_administrator() && !project_any() ) {
+ $c_return = 'manage_proj_create_page.php';
+ }
+ }
- if ( auth_is_user_authenticated() ) {
$t_redirect_url = $c_return;
} else {
$t_redirect_url = 'login_page.php?cookie_error=1';

0 comments on commit 2b5691f

Please sign in to comment.