aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/userController.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2017-03-11 10:36:48 +0100
committerGravatar GitHub <noreply@github.com> 2017-03-11 10:36:48 +0100
commitbe0bcfef7e38f27284ec7b377b342ba389515964 (patch)
tree59d2d5a8e34fcb279a53a2b44fde1e36c888672d /app/Controllers/userController.php
parent5f637bd816b7323885bfe1751a1724ee59a822f6 (diff)
parentb34c318f02574b13560731035fd5a4f750aa1e9b (diff)
Merge pull request #1455 from FreshRSS/dev1.6.3
Release 1.6.3
Diffstat (limited to 'app/Controllers/userController.php')
-rw-r--r--app/Controllers/userController.php21
1 files changed, 17 insertions, 4 deletions
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 9d6ae18e6..f910cecd9 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -35,6 +35,16 @@ class FreshRSS_user_Controller extends Minz_ActionController {
}
/**
+ * The username is also used as folder name, file name, and part of SQL table name.
+ * '_' is a reserved internal username.
+ */
+ const USERNAME_PATTERN = '[0-9a-zA-Z]|[0-9a-zA-Z_]{2,38}';
+
+ public static function checkUsername($username) {
+ return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1;
+ }
+
+ /**
* This action displays the user profile page.
*/
public function profileAction() {
@@ -104,7 +114,8 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$userConfig = array();
}
- $ok = ($new_user_name != '') && ctype_alnum($new_user_name);
+ $ok = self::checkUsername($new_user_name);
+ $homeDir = join_path(DATA_PATH, 'users', $new_user_name);
if ($ok) {
$languages = Minz_Translate::availableLanguages();
@@ -114,7 +125,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$ok &= !in_array(strtoupper($new_user_name), array_map('strtoupper', listUsers())); //Not an existing user, case-insensitive
- $configPath = join_path(DATA_PATH, 'users', $new_user_name, 'config.php');
+ $configPath = join_path($homeDir, 'config.php');
$ok &= !file_exists($configPath);
}
if ($ok) {
@@ -131,7 +142,9 @@ class FreshRSS_user_Controller extends Minz_ActionController {
}
}
if ($ok) {
- mkdir(join_path(DATA_PATH, 'users', $new_user_name));
+ if (!is_dir($homeDir)) {
+ mkdir($homeDir);
+ }
$userConfig['passwordHash'] = $passwordHash;
$userConfig['apiPasswordHash'] = $apiPasswordHash;
$ok &= (file_put_contents($configPath, "<?php\n return " . var_export($userConfig, true) . ';') !== false);
@@ -187,7 +200,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$db = FreshRSS_Context::$system_conf->db;
require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');
- $ok = ctype_alnum($username);
+ $ok = self::checkUsername($username);
if ($ok) {
$default_user = FreshRSS_Context::$system_conf->default_user;
$ok &= (strcasecmp($username, $default_user) !== 0); //It is forbidden to delete the default user