Skip to content
Browse files

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

…reate project page.

If MantisBT is pre-installed, the user lands in My View Page without knowing what to do.
We should handle the "first login" experience in MantisBT itself rather than the installation
and provide a helpful getting started over time. For now, we should start with auto-redirecting
to create project page if user is administrator and there aren't at least 1 project in the database.

The cost of this check is one cheap query on the projects table that returns 0 or 1 entries
which is only run at login of an administrator.
  • Loading branch information...
1 parent e60809f commit fb121e83b48f4cc22a9c9af257d23d1ae9b25388 @vboctor vboctor committed
Showing with 32 additions and 4 deletions.
  1. +1 −1 admin/install.php
  2. +21 −0 core/project_api.php
  3. +10 −3 login_cookie_test.php
View
2 admin/install.php
@@ -992,7 +992,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>
+<p>Please log in as the administrator and <a href="../login_page.php">create</a> your first project.</p>
<?php
}
View
21 core/project_api.php
@@ -68,6 +68,27 @@
$g_cache_project_missing = array();
$g_cache_project_all = false;
+/**
+ * Checks if there are no projects defined.
+ * @return bool true if there are no projects defined, false otherwise.
+ * @access public
+ */
+function project_table_empty() {
+ global $g_cache_project;
+
+ # If projects already cached, use the cache.
+ if ( isset( $g_cache_project ) && count( $g_cache_project ) > 0 ) {
+ return false;
+ }
+
+ # Otherwise, check if the projects table contains at least one project.
+ $t_project_table = db_get_table( 'project' );
+ $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
13 login_cookie_test.php
@@ -40,11 +40,18 @@
require_api( 'print_api.php' );
require_api( 'string_api.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_table_empty() ) {
+ $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 fb121e8

Please sign in to comment.
Something went wrong with that request. Please try again.