PHP User::addToDatabase Examples

PHP User::addToDatabase - 12 examples found. These are the top rated real world PHP examples of User::addToDatabase extracted from open source projects. You can rate examples to help us improve the quality of examples.
 static function createTemporaryUser($real_name, $email)
 {
     $user = new User();
     $maxid = User::getMaxID();
     $anonid = $maxid + 1;
     $username = "Anonymous{$anonid}";
     $user->setName($username);
     $real_name = strip_tags($real_name);
     // make sure this hasn't already been created
     while ($user->idForName() > 0) {
         $anonid = rand(0, 100000);
         $username = "Anonymous{$anonid}";
         $user->setName($username);
     }
     if ($real_name) {
         $user->setRealName($real_name);
     } else {
         $user->setRealName("Anonymous");
     }
     if ($email) {
         $user->setEmail($email);
     }
     $user->setPassword(WH_ANON_USER_PASSWORD);
     $user->setOption("disablemail", 1);
     $user->addToDatabase();
     return $user;
 }
 public function setUp()
 {
     parent::setUp();
     $user = new User();
     $user->setName('Notification-formatter-test');
     $user->addToDatabase();
     $this->setMwGlobals('wgUser', $user);
 }
Example #3
0
 public function createAction()
 {
     $bdd = Connection::ConnectToMySQL();
     if (isset($_GET['pseudo']) && isset($_GET['password']) && isset($_GET['email'])) {
         $new_user = new User($_GET['pseudo'], $_GET['password'], $_GET['email']);
         $new_user->addToDatabase();
     } else {
         Message::sendJSONMessage(false, "Requete invalide");
     }
 }
 /**
  * Get user object.
  *
  * @return User object: User object for autocreate user.
  */
 public static function user()
 {
     if (!self::$user) {
         $userName = wfMessage('babel-autocreate-user')->inContentLanguage()->plain();
         self::$user = User::newFromName($userName);
         if (self::$user && !self::$user->isLoggedIn()) {
             self::$user->addToDatabase();
         }
     }
     return self::$user;
 }
 public static function provideAssert()
 {
     $anon = new User();
     $bot = new User();
     $bot->setName('Bot');
     $bot->addToDatabase();
     $bot->addGroup('bot');
     $user = new User();
     $user->setName('User');
     $user->addToDatabase();
     return array(array($anon, 'user', 'assertuserfailed'), array($user, 'user', false), array($user, 'bot', 'assertbotfailed'), array($bot, 'user', false), array($bot, 'bot', false));
 }
 /**
  * Get a user object for doing edits, from a request-lifetime cache
  * False will be returned if the user name specified in the
  * 'double-redirect-fixer' message is invalid.
  *
  * @return User|bool
  */
 function getUser()
 {
     if (!self::$user) {
         $username = wfMessage('double-redirect-fixer')->inContentLanguage()->text();
         self::$user = User::newFromName($username);
         # User::newFromName() can return false on a badly configured wiki.
         if (self::$user && !self::$user->isLoggedIn()) {
             self::$user->addToDatabase();
         }
     }
     return self::$user;
 }
 /**
  * @param $user
  * @param $result
  * @return bool
  */
 public function AutoAuthenticateOverSymfony($user, &$result)
 {
     $symfonyToken = $this->symfonyConatiner->get('security.token_storage')->getToken();
     if (!$symfonyToken || !is_object($symfonyToken)) {
         return false;
     }
     $symfonyUser = $symfonyToken->getUser();
     if (!$symfonyUser || !is_object($symfonyUser)) {
         return false;
     }
     $dbr =& wfGetDB(DB_SLAVE);
     $s = $dbr->selectRow('user', array('user_id'), array('user_name' => $symfonyUser->getUsername()), "UserAuthSymfony::AutoAuthenticateOverSymfony");
     if ($s === false) {
         $username = $symfonyUser->getUsername();
         $newUser = new \User();
         $newUser->loadDefaults($username);
         // Added as it's done this way in CentralAuth.
         $newUser->setEmail($symfonyUser->getEmail());
         $newUser->setName($username);
         $newUser->confirmEmail();
         $newUser->mTouched = wfTimestamp();
         $newUser->addToDatabase();
         $user =& $newUser;
     } else {
         $user->mId = $s->user_id;
     }
     $sfGroups = array();
     if (method_exists($symfonyUser, 'getGroups')) {
         $sfGroups = $symfonyUser->getGroups();
     }
     $oldGroups = $user->getGroups();
     // previous groups
     foreach ($oldGroups as $group) {
         //ignore wiki groups and remove only non wiki groups
         if (!in_array($group, array('sysop', 'bureaucrat'))) {
             $user->removeGroup($group);
             // remove it
         }
     }
     // readd current groups
     foreach ($sfGroups as $sfGroup) {
         $user->addGroup(GroupBridge::getGroupAlias($sfGroup));
     }
     if ($user->loadFromDatabase()) {
         $user->saveToCache();
     }
     $result = true;
     return true;
 }
 /**
  * Set users' fields from SAML attributes.
  * If the user does not exist in the MediaWiki database,
  * it is created. wgSamlCreateUser is not respected.
  *
  * @param User $user the user
  * @param string[][] $attr SAML attributes
  */
 protected static function updateUser(User $user, $attr)
 {
     global $wgSamlRealnameAttr;
     global $wgSamlUsernameAttr;
     global $wgSamlMailAttr;
     global $wgContLang;
     $changed = false;
     if (isset($wgSamlRealnameAttr) && isset($attr[$wgSamlRealnameAttr]) && $attr[$wgSamlRealnameAttr] && $user->getRealName() !== reset($attr[$wgSamlRealnameAttr])) {
         $changed = true;
         $user->setRealName(reset($attr[$wgSamlRealnameAttr]));
     }
     if ($attr[$wgSamlMailAttr] && $user->getEmail() !== reset($attr[$wgSamlMailAttr])) {
         $changed = true;
         $user->setEmail(reset($attr[$wgSamlMailAttr]));
         $user->ConfirmEmail();
     }
     if (!$user->getId()) {
         $user->setName($wgContLang->ucfirst(reset($attr[$wgSamlUsernameAttr])));
         $user->setPassword(null);
         // prevent manual login until reset
         $user->addToDatabase();
     } elseif ($changed) {
         $user->saveSettings();
     }
 }
 /**
  * Actually add a user to the database.
  * Give it a User object that has been initialised with a name.
  *
  * @param User $u
  * @param bool $autocreate True if this is an autocreation via auth plugin
  * @return Status Status object, with the User object in the value member on success
  * @private
  */
 function initUser($u, $autocreate)
 {
     global $wgAuth;
     $status = $u->addToDatabase();
     if (!$status->isOK()) {
         return $status;
     }
     if ($wgAuth->allowPasswordChange()) {
         $u->setPassword($this->mPassword);
     }
     $u->setEmail($this->mEmail);
     $u->setRealName($this->mRealName);
     $u->setToken();
     $wgAuth->initUser($u, $autocreate);
     $u->saveSettings();
     // Update user count
     DeferredUpdates::addUpdate(new SiteStatsUpdate(0, 0, 0, 0, 1));
     // Watch user's userpage and talk page
     $u->addWatch($u->getUserPage(), WatchedItem::IGNORE_USER_RIGHTS);
     return Status::newGood($u);
 }
Example #10
0
 /**
  * Actually add a user to the database.
  * Give it a User object that has been initialised with a name.
  *
  * @param User $u
  * @param bool $autocreate True if this is an autocreation via auth plugin
  * @return Status Status object, with the User object in the value member on success
  * @private
  */
 function initUser($u, $autocreate)
 {
     global $wgAuth;
     $status = $u->addToDatabase();
     if (!$status->isOK()) {
         return $status;
     }
     if ($wgAuth->allowPasswordChange()) {
         $u->setPassword($this->mPassword);
     }
     $u->setEmail($this->mEmail);
     $u->setRealName($this->mRealName);
     $u->setToken();
     Hooks::run('LocalUserCreated', array($u, $autocreate));
     $oldUser = $u;
     $wgAuth->initUser($u, $autocreate);
     if ($oldUser !== $u) {
         wfWarn(get_class($wgAuth) . '::initUser() replaced the user object');
     }
     $u->saveSettings();
     // Update user count
     DeferredUpdates::addUpdate(new SiteStatsUpdate(0, 0, 0, 0, 1));
     // Watch user's userpage and talk page
     $u->addWatch($u->getUserPage(), WatchedItem::IGNORE_USER_RIGHTS);
     return Status::newGood($u);
 }
 /**
  * Actually add a user to the database.
  * Give it a User object that has been initialised with a name.
  *
  * @param User $u
  * @return User
  * @access private
  */
 function &initUser(&$u)
 {
     $u->addToDatabase();
     $u->setPassword($this->mPassword);
     $u->setEmail($this->mEmail);
     $u->setRealName($this->mRealName);
     $u->setToken();
     global $wgAuth;
     $wgAuth->initUser($u);
     if ($this->mRemember) {
         $r = 1;
     } else {
         $r = 0;
     }
     $u->setOption('rememberpassword', $r);
     return $u;
 }
Example #12
0
include_once "../configRoot.php";
require_once ROOT_NAME . "/classes/Database.php";
require_once ROOT_NAME . "/classes/User.php";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    // check if passwords are the same
    if ($_POST["password"] !== $_POST["repeated_password"]) {
        header("location: ../registration.php?error=different_passwords");
    } else {
        $email = $_POST["email"];
        $email = trim($email);
        $email = htmlspecialchars($email);
        $nick = $_POST["nick"];
        $nick = trim($nick);
        $nick = htmlentities($nick);
        $password = $_POST["password"];
        $db = Database::getInstance();
        $conn = $db->getConnection();
        $user = new User($conn);
        $user->setEmail($email);
        $user->setNick($nick);
        $user->setPassword($password);
        $result = $user->addToDatabase();
        if ($result === true) {
            header("location: ../registration.php?registration=success");
        } else {
            header("location: ../registration.php?error=not_created");
        }
    }
} else {
    header("location: ../registration.php");
}