public function check() { error_log($this->app->request->getPath()); if ($this->app->request->getPath() != $this->app->urlFor('uri_install')) { // Test database connection try { \UserFrosting\Database::connection(); } catch (\PDOException $e) { $this->app->redirect($this->app->urlFor('uri_install')); } } }
/** * Delete this group from the database, along with any linked user and authorization rules * */ public function delete() { // Remove all user associations $this->users()->detach(); // Remove all group auth rules $auth_table = Database::getSchemaTable('authorize_group')->name; Capsule::table($auth_table)->where("group_id", $this->id)->delete(); // Reassign any primary users to the current default primary group $default_primary_group = Group::where('is_default', GROUP_DEFAULT_PRIMARY)->first(); $user_table = Database::getSchemaTable('user')->name; Capsule::table($user_table)->where('primary_group_id', $this->id)->update(["primary_group_id" => $default_primary_group->id]); // TODO: assign user to the default primary group as well? // Delete the group $result = parent::delete(); return $result; }
\UserFrosting\UFModel::$app = $app; // Initialize database properties $table_user = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "user", ["user_name", "display_name", "email", "title", "locale", "primary_group_id", "secret_token", "flag_verified", "flag_enabled", "flag_password_reset", "created_at", "updated_at", "password"]); $table_user_event = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "user_event", ["user_id", "event_type", "occurred_at", "description"]); $table_group = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "group", ["name", "is_default", "can_delete", "theme", "landing_page", "new_user_title", "icon"]); $table_group_user = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "group_user"); $table_configuration = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "configuration"); $table_authorize_user = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "authorize_user"); $table_authorize_group = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "authorize_group"); \UserFrosting\Database::setSchemaTable("user", $table_user); \UserFrosting\Database::setSchemaTable("user_event", $table_user_event); \UserFrosting\Database::setSchemaTable("group", $table_group); \UserFrosting\Database::setSchemaTable("group_user", $table_group_user); \UserFrosting\Database::setSchemaTable("configuration", $table_configuration); \UserFrosting\Database::setSchemaTable("authorize_user", $table_authorize_user); \UserFrosting\Database::setSchemaTable("authorize_group", $table_authorize_group); // Info for RememberMe table $app->remember_me_table = ['tableName' => $app->config('db')['db_prefix'] . "user_rememberme", 'credentialColumn' => 'user_id', 'tokenColumn' => 'token', 'persistentTokenColumn' => 'persistent_token', 'expiresColumn' => 'expires']; /* Event Types "sign_up", "sign_in", "verification_request", "password_reset_request", */ /* Load UserFrosting site settings */ // Default settings $setting_values = ['userfrosting' => ['site_title' => 'UserFrosting', 'admin_email' => '*****@*****.**', 'email_login' => '1', 'can_register' => '1', 'enable_captcha' => '1', 'require_activation' => '1', 'resend_activation_threshold' => '0', 'reset_password_timeout' => '10800', 'create_password_expiration' => '86400', 'default_locale' => 'en_US', 'guest_theme' => 'default', 'minify_css' => '0', 'minify_js' => '0', 'version' => '0.3.1.10', 'author' => 'Alex Weissman', 'show_terms_on_register' => '1', 'site_location' => 'The State of Indiana']]; $setting_descriptions = ['userfrosting' => ["site_title" => "The title of the site. By default, displayed in the title tag, as well as the upper left corner of every user page.", "admin_email" => "The administrative email for the site. Automated emails, such as verification emails and password reset links, will come from this address.", "email_login" => "Specify whether users can login via email address or username instead of just username.", "can_register" => "Specify whether public registration of new accounts is enabled. Enable if you have a service that users can sign up for, disable if you only want accounts to be created by you or an admin.", "enable_captcha" => "Specify whether new users must complete a captcha code when registering for an account.", "require_activation" => "Specify whether email verification is required for newly registered accounts. Accounts created by another user never need to be verified.", "resend_activation_threshold" => "The time, in seconds, that a user must wait before requesting that the account verification email be resent.", "reset_password_timeout" => "The time, in seconds, before a user's password reset token expires.", "create_password_expiration" => "The time, in seconds, before a new user's password creation token expires.", "default_locale" => "The default language for newly registered users.", "guest_theme" => "The template theme to use for unauthenticated (guest) users.", "minify_css" => "Specify whether to use concatenated, minified CSS (production) or raw CSS includes (dev).", "minify_js" => "Specify whether to use concatenated, minified JS (production) or raw JS includes (dev).", "version" => "The current version of UserFrosting.", "author" => "The author of the site. Will be used in the site's author meta tag.", "show_terms_on_register" => "Specify whether or not to show terms and conditions when registering.", "site_location" => "The nation or state in which legal jurisdiction for this site falls."]]; // Create the site settings object. If the database cannot be accessed or has not yet been set up, use the default settings. $app->site = new \UserFrosting\SiteSettings($setting_values, $setting_descriptions); // Create the page schema object
$table_votes_coleg = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "votes_coleg"); $table_votes_osi = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "votes_osi"); $table_votes_pbidea = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "votes_pbidea"); \UserFrosting\Database::setTable("user", $table_user); \UserFrosting\Database::setTable("group", $table_group); \UserFrosting\Database::setTable("group_user", $table_group_user); \UserFrosting\Database::setTable("configuration", $table_configuration); \UserFrosting\Database::setTable("authorize_user", $table_authorize_user); \UserFrosting\Database::setTable("authorize_group", $table_authorize_group); \UserFrosting\Database::setTable("bud", $table_bud); \UserFrosting\Database::setTable("votes_bud", $table_votes_bud); \UserFrosting\Database::setTable("coleg", $table_coleg); \UserFrosting\Database::setTable("votes_coleg", $table_votes_coleg); \UserFrosting\Database::setTable("osi", $table_osi); \UserFrosting\Database::setTable("votes_osi", $table_votes_osi); \UserFrosting\Database::setTable("pbidea", $table_pbidea); // Initialize static loader classes \UserFrosting\UserLoader::init($table_user); \UserFrosting\GroupLoader::init($table_group); \UserFrosting\BudLoader::init($table_bud); \UserFrosting\ColegLoader::init($table_coleg); \UserFrosting\OsiLoader::init($table_osi); \UserFrosting\PBideaLoader::init($table_pbidea); /* Load UserFrosting site settings */ // Default settings $setting_values = ['userfrosting' => ['site_title' => 'UserFrosting', 'admin_email' => '*****@*****.**', 'email_login' => '1', 'can_register' => '1', 'enable_captcha' => '1', 'require_activation' => '1', 'resend_activation_threshold' => '0', 'reset_password_timeout' => '10800', 'default_locale' => 'en_US', 'minify_css' => '0', 'minify_js' => '0', 'version' => '0.3.0', 'author' => 'Alex Weissman', 'show_terms_on_register' => '1', 'site_location' => 'The State of Indiana']]; $setting_descriptions = ['userfrosting' => ["site_title" => "The title of the site. By default, displayed in the title tag, as well as the upper left corner of every user page.", "admin_email" => "The administrative email for the site. Automated emails, such as activation emails and password reset links, will come from this address.", "email_login" => "Specify whether users can login via email address or username instead of just username.", "can_register" => "Specify whether public registration of new accounts is enabled. Enable if you have a service that users can sign up for, disable if you only want accounts to be created by you or an admin.", "enable_captcha" => "Specify whether new users must complete a captcha code when registering for an account.", "require_activation" => "Specify whether email activation is required for newly registered accounts. Accounts created on the admin side never need to be activated.", "resend_activation_threshold" => "The time, in seconds, that a user must wait before requesting that the activation email be resent.", "reset_password_timeout" => "The time, in seconds, before a user's password reminder email expires.", "default_locale" => "The default language for newly registered users.", "minify_css" => "Specify whether to use concatenated, minified CSS (production) or raw CSS includes (dev).", "minify_js" => "Specify whether to use concatenated, minified JS (production) or raw JS includes (dev).", "version" => "The current version of UserFrosting.", "author" => "The author of the site. Will be used in the site's author meta tag.", "show_terms_on_register" => "Specify whether or not to show terms and conditions when registering.", "site_location" => "The nation or state in which legal jurisdiction for this site falls."]]; // Load site settings $app->site = new \UserFrosting\SiteSettings($setting_values, $setting_descriptions); // Store to DB if not consistent if (!$app->site->isConsistent()) {
/** * Delete this user from the database, along with any linked groups and authorization rules * * @return bool true if the deletion was successful, false otherwise. */ public function delete() { // Remove all group associations $this->groups()->detach(); // Remove all user auth rules $auth_table = Database::getSchemaTable('authorize_user')->name; Capsule::table($auth_table)->where("user_id", $this->id)->delete(); // Remove all user events $event_table = Database::getSchemaTable('user_event')->name; Capsule::table($event_table)->where("user_id", $this->id)->delete(); // Delete the user $result = parent::delete(); return $result; }
// This if-block just checks that the path for initialize.php is correct. Remove this once you know what you're doing. if (!file_exists($init_path)) { echo "<h2>We can't seem to find our way to initialize.php! Please check the require_once statement at the top of index.php, and make sure it contains the correct path to initialize.php.</h2><br>"; } require_once $init_path; use UserFrosting as UF; // Front page $app->get('/', function () use($app) { // This if-block detects if mod_rewrite is enabled. // This is just an anti-noob device, remove it if you know how to read the docs and/or breathe through your nose. if (isset($_SERVER['SERVER_TYPE']) && $_SERVER['SERVER_TYPE'] == "Apache" && !isset($_SERVER['HTTP_MOD_REWRITE'])) { $app->render('errors/bad-config.twig'); exit; } // Check that we can connect to the DB. Again, you can remove this if you know what you're doing. if (!UF\Database::testConnection()) { // In case the error is because someone is trying to reinstall with new db info while still logged in, log them out session_destroy(); // TODO: log out from remember me as well. $controller = new UF\AccountController($app); return $controller->pageDatabaseError(); } // Forward to installation if not complete // TODO: Is there any way to detect that installation was complete, but the DB is malfunctioning? if (!isset($app->site->install_status) || $app->site->install_status == "pending") { $app->redirect($app->urlFor('uri_install')); } // Forward to the user's landing page (if logged in), otherwise take them to the home page // This is probably where you, the developer, would start making changes if you need to change the default behavior. if ($app->user->isGuest()) { $controller = new UF\AccountController($app);
/** * Get an array of system information for UserFrosting. * * @return array An array containing a list of information, such as software version, application path, etc. */ public function getSystemInfo() { $results = []; $results['UserFrosting Version'] = $this->version; $results['Web Server'] = $_SERVER['SERVER_SOFTWARE']; $results['PHP Version'] = phpversion(); $dbinfo = Database::getInfo(); $results['Database Version'] = $dbinfo['db_type'] . " " . $dbinfo['db_version']; $results['Database Name'] = $dbinfo['db_name']; $results['Table Prefix'] = $dbinfo['table_prefix']; $environment = static::$app->environment(); $results['Application Root'] = static::$app->config('base.path'); $results['Document Root'] = $this->uri['public']; return $results; }
} } /* Import UserFrosting variables as global Twig variables */ $twig = $app->view()->getEnvironment(); $twig->addFilter(new \Twig_SimpleFilter('cast_to_array', function ($stdClassObject) { $response = array(); foreach ((array) $stdClassObject as $key => $value) { $response[str_replace('*', '', $key)] = $value; } return $response; })); $loader = $twig->getLoader(); // First look in user's theme... $loader->addPath($app->config('plugins.path') . "/UserFrosting-OAuth/templates"); $table_user_oauth = new UF\DatabaseTable($app->config('db')['db_prefix'] . "user_oauth", ["provider", "user_id", "uid", "email", "first_name", "last_name", "picture_url", "oauth_details", "created_at"]); UF\Database::setSchemaTable("user_oauth", $table_user_oauth); // Define routes // This is the GET route for the "login with ___" button $app->get('/oauth/:provider/login', function ($provider) use($app) { $controller = getProviderController($provider, 'login', $app); // Store this action so we remember what we're doing after we get the authorization code $_SESSION['oauth_action'] = "login"; $get = $app->request->get(); // If we received an authorization code, then resume our action if (isset($get['code'])) { // If we're logging them in, just call that method and it will automatically redirect us $controller->login(); } else { // Otherwise, request an authorization code return $controller->authorize(); }
/** * 0.3.1 - Updating groups to use dashboard instead of the old accounts page. */ echo '(0.3.1) Updating groups to use new dashboard in ' . \UserFrosting\Database::getSchemaTable('group')->name . ': '; $connection->statement("UPDATE `" . \UserFrosting\Database::getSchemaTable('group')->name . "`\n SET `landing_page` = 'dashboard' WHERE `landing_page` = 'account'; ") or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); echo 'Done.' . PHP_EOL; /** * 0.3.1.5 - Add default value for secret_token. */ echo '(0.3.1.5) Creating default value for secret_token: '; $connection->statement("ALTER TABLE `" . \UserFrosting\Database::getSchemaTable('user')->name . "`\n CHANGE `secret_token` `secret_token` varchar(32) NOT NULL DEFAULT ''\n COMMENT 'The current one-time use token for various user activities confirmed via email.'") or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); echo 'Done.' . PHP_EOL; /** * 0.3.1.7 - Change from "default_theme" to "guest_theme". */ echo '(0.3.1.7) Updating "default_theme" to "guest_theme": '; if (isset($settings['default_theme'])) { $settings['guest_theme'] = $settings['default_theme']; $settings->save(); $connection->statement('DELETE FROM `' . \UserFrosting\Database::getSchemaTable('configuration')->name . '` WHERE `name` = \'default_theme\'') or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); } echo 'Done.' . PHP_EOL; /** * Latest - Update the version number in the database. */ $settings = SiteSettings::all()->first(); echo PHP_EOL . '(' . $versionTargetDatabase . ') Updating database version: '; $settings['version'] = $versionTargetDatabase; $settings->save() or die('Failed.' . PHP_EOL . PHP_EOL . 'Exiting.'); echo 'Done.' . PHP_EOL; echo PHP_EOL . 'Conversion complete!' . PHP_EOL;
/** * For excluding certain columns in a query. */ public function scopeExclude($query, $value = []) { $columns = array_merge(['id'], Database::getSchemaTable(static::$_table_id)->columns); return $query->select(array_diff($columns, (array) $value)); }
/** * For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id. */ public static function queryBuilder() { // Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects) Capsule::connection()->setFetchMode(\PDO::FETCH_ASSOC); $table = Database::getSchemaTable(static::$_table_id)->name; return Capsule::table($table); }
$table_car = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "car", ["created_at", "updated_at", "user_id", "title", "email", "phone", "maxPassengerCount"]); $table_group_user = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "group_user"); $table_configuration = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "configuration"); $table_authorize_user = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "authorize_user"); $table_authorize_group = new \UserFrosting\DatabaseTable($app->config('db')['db_prefix'] . "authorize_group"); \UserFrosting\Database::setSchemaTable("user", $table_user); \UserFrosting\Database::setSchemaTable("user_event", $table_user_event); \UserFrosting\Database::setSchemaTable("group", $table_group); \UserFrosting\Database::setSchemaTable("group_user", $table_group_user); \UserFrosting\Database::setSchemaTable("configuration", $table_configuration); \UserFrosting\Database::setSchemaTable("authorize_user", $table_authorize_user); \UserFrosting\Database::setSchemaTable("authorize_group", $table_authorize_group); \UserFrosting\Database::setSchemaTable("booking", $table_booking); \UserFrosting\Database::setSchemaTable("geolock", $table_geolock); \UserFrosting\Database::setSchemaTable("pricing", $table_pricing); \UserFrosting\Database::setSchemaTable("car", $table_car); // Info for RememberMe table $app->remember_me_table = ['tableName' => $app->config('db')['db_prefix'] . "user_rememberme", 'credentialColumn' => 'user_id', 'tokenColumn' => 'token', 'persistentTokenColumn' => 'persistent_token', 'expiresColumn' => 'expires']; /* Event Types "sign_up", "sign_in", "verification_request", "password_reset_request", */ /* Load UserFrosting site settings */ // Default settings $setting_values = ['userfrosting' => ['site_title' => 'Taxibo', 'admin_email' => '*****@*****.**', 'email_login' => '1', 'can_register' => '0', 'enable_captcha' => '1', 'require_activation' => '1', 'resend_activation_threshold' => '0', 'reset_password_timeout' => '10800', 'create_password_expiration' => '86400', 'default_locale' => 'sv_SE', 'guest_theme' => 'default', 'minify_css' => '0', 'minify_js' => '0', 'version' => '0.3.1.11', 'author' => 'Allan Th. Andersen', 'show_terms_on_register' => '1', 'site_location' => 'Scandinavia - Denmark/Sweden/Norge']]; $setting_descriptions = ['userfrosting' => ["site_title" => "The title of the site. By default, displayed in the title tag, as well as the upper left corner of every user page.", "admin_email" => "The administrative email for the site. Automated emails, such as verification emails and password reset links, will come from this address.", "email_login" => "Specify whether users can login via email address or username instead of just username.", "can_register" => "Specify whether public registration of new accounts is enabled. Enable if you have a service that users can sign up for, disable if you only want accounts to be created by you or an admin.", "enable_captcha" => "Specify whether new users must complete a captcha code when registering for an account.", "require_activation" => "Specify whether email verification is required for newly registered accounts. Accounts created by another user never need to be verified.", "resend_activation_threshold" => "The time, in seconds, that a user must wait before requesting that the account verification email be resent.", "reset_password_timeout" => "The time, in seconds, before a user's password reset token expires.", "create_password_expiration" => "The time, in seconds, before a new user's password creation token expires.", "default_locale" => "The default language for newly registered users.", "guest_theme" => "The template theme to use for unauthenticated (guest) users.", "minify_css" => "Specify whether to use concatenated, minified CSS (production) or raw CSS includes (dev).", "minify_js" => "Specify whether to use concatenated, minified JS (production) or raw JS includes (dev).", "version" => "The current version of UserFrosting.", "author" => "The author of the site. Will be used in the site's author meta tag.", "show_terms_on_register" => "Specify whether or not to show terms and conditions when registering.", "site_location" => "The nation or state in which legal jurisdiction for this site falls."]]; // Create the site settings object. If the database cannot be accessed or has not yet been set up, use the default settings. $app->site = new \UserFrosting\SiteSettings($setting_values, $setting_descriptions); // Create the page schema object