public function addAction()
 {
     if (Auth::isAuth() && (Auth::isGod() || Auth::isAdmin())) {
         // Once more, I prefer use the old school way to retrieve variables here
         // because the values sent by the form may vary in the future.
         $username = $_POST['username'];
         $password = $_POST['password'];
         $language = $_POST['language'];
         $openId = isset($_POST['openid']) ? $_POST['openid'] : '';
         $userType = $_POST['rights'];
         try {
             $params = array('username' => $username, 'password' => $password, 'language' => $language, 'openid' => $openId, 'rights' => $userType, 'copname' => Auth::getCopName());
             UsersManagement::addUser($params);
             $_SESSION['isError'] = false;
             $_SESSION['message'] = __("The user has been successfuly created.");
             DefaultFC::redirection('adminUsers/index');
         } catch (UsersManagementException $e) {
             $isError = true;
             $message = Util::buildAddEditUserErrorMessage($e);
             // Escaping to reinsert in form ...
             $username = htmlspecialchars($username, ENT_QUOTES, 'UTF-8');
             $password = htmlspecialchars($password, ENT_QUOTES, 'UTF-8');
             $language = htmlspecialchars($language, ENT_QUOTES, 'UTF-8');
             $openId = htmlspecialchars($openId, ENT_QUOTES, 'UTF-8');
             $userType = htmlspecialchars($userType, ENT_QUOTES, 'UTF-8');
             $userFormMode = 'add';
             $availableLanguages = Util::getAvailableLanguages();
             $availableUserTypes = Util::getAvailableUserTypes();
             $displayOldValues = true;
             $widgetManagement = true;
             $partial = 'users_form';
             require_once DefaultFC::getView('admin.tpl');
         }
     }
 }
 public function createAccount()
 {
     // Note : again, because the number of parameters may vary in the future,
     // I will use $_POST to retrieve request params.
     $username = $_POST['username'];
     $password = $_POST['password'];
     $confirmPassword = $_POST['password_confirm'];
     $openId = isset($_POST['openid']) ? $_POST['openid'] : '';
     $userType = 0;
     try {
         UsersManagement::addUser(array('username' => $username, 'password' => $password, 'confirm_password' => $confirmPassword, 'openid' => $openId, 'rights' => $userType, 'copname' => 'cop1'), true);
         $_SESSION['isError'] = false;
         $_SESSION['message'] = __("Your account has been successfuly created.");
         DefaultFC::redirection('wall/index');
     } catch (UsersManagementException $e) {
         $isError = true;
         $message = Util::buildAddEditUserErrorMessage($e);
         // Escaping to reinsert in form ...
         $username = htmlspecialchars($username, ENT_QUOTES, 'UTF-8');
         $openId = htmlspecialchars($openId, ENT_QUOTES, 'UTF-8');
         $displayOldValues = true;
         require_once DefaultFC::getView('register.tpl');
     }
 }
 public static function addAnonymousUser()
 {
     do {
         # Create a new random user
         $suffix = '';
         for ($i = 0; $i < 8; $i++) {
             $suffix .= chr(ord('a') + rand(0, 25));
         }
         $password = $suffix;
         $login = ANONYMOUS_PREFIX . $suffix;
     } while (self::getUserIdByLogin($login) === false);
     #Check if this user exist
     # Add user as an anonymous user
     UsersManagement::addUser(array('username' => $login, 'password' => $suffix, 'confirm_password' => $suffix, 'openid' => '', 'rights' => 0, 'copname' => 'cop1'), true, 1);
     # Add ui for the new anonymous account
     $userId = self::getUserIdByLogin($login);
     WidgetSpace::loadWidgetSpace($userId, DEFAULT_WIDGET_SPACE_ON_SIGNIN);
     return array('login' => $login, 'password' => $password);
 }