/** * Insert a block into the block table. Will fail if there is a conflicting * block (same name and options) already in the database. * * @param $dbw DatabaseBase if you have one available * @return mixed: false on failure, assoc array on success: * ('id' => block ID, 'autoIds' => array of autoblock IDs) */ public function insert($dbw = null) { global $wgBlockDisablesLogin; wfDebug("Block::insert; timestamp {$this->mTimestamp}\n"); if ($dbw === null) { $dbw = wfGetDB(DB_MASTER); } # Don't collide with expired blocks Block::purgeExpired(); $row = $this->getDatabaseArray(); $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq"); $dbw->insert('ipblocks', $row, __METHOD__, array('IGNORE')); $affected = $dbw->affectedRows(); $this->mId = $dbw->insertId(); if ($affected) { if ($wgBlockDisablesLogin && $this->target instanceof User) { // Change user login token to force them to be logged out. $this->target->setToken(); $this->target->saveSettings(); } $auto_ipd_ids = $this->doRetroactiveAutoblock(); return array('id' => $this->mId, 'autoIds' => $auto_ipd_ids); } return false; }
/** * Reset API key * * @param void * @return null */ function api_reset_key() { if ($this->active_user->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_user->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->request->isSubmitted()) { $this->active_user->setToken(make_string(40)); $save = $this->active_user->save(); if ($save && !is_error($save)) { flash_success('API key updated'); } else { flash_error('Failed to update API key. Try again in a few minutes'); } // if $this->redirectToUrl($this->active_user->getApiSettingsUrl()); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
static function logIn($email, $password) { DBConnection::connect(); $match = DBConnection::select('SELECT id, pseudo FROM user WHERE email="' . DBConnection::getCleanVar($email) . '" AND password="******"'); if ($match) { $user = new User($match[0]->id, $match[0]->pseudo, false); $user->setToken(); return true; } else { return false; } }
public static function getUser($bdd, $hash, $pseudo = NULL, $email = NULL) { if ($pseudo) { $request = $bdd->prepare('SELECT * FROM driver WHERE pseudo = ?'); $request->execute(array($pseudo)); if ($donnees = $request->fetch()) { $salt = $donnees["salt"]; if ($donnees["hash"] == hash('sha512', $salt + $hash, false)) { $user = new User($pseudo, $donnees["hash"], $donnees["email"]); $user->setId($donnees["driver_id"]); $user->setPseudo($donnees["pseudo"]); $user->setFirstname($donnees["first_name"]); $user->setLastname($donnees["last_name"]); $user->setToken(User::generateRandomString(200)); $request = $bdd->prepare("UPDATE driver SET token=:token WHERE driver_id = :driver"); $request->execute(array('token' => $user->getToken(), 'driver' => $user->getId())); return $user; } } else { return null; } } else { if ($email) { $request = $bdd->prepare('SELECT * FROM driver WHERE email = ?'); $request->execute(array($email)); if ($donnees = $request->fetch()) { $salt = $donnees["salt"]; if ($donnees["hash"] == hash('sha512', $salt + $hash, false)) { $user = new User($donnees["pseudo"], $donnees["hash"], $email); $user->setId($donnees["id"]); $user->setFirstname($donnees["first_name"]); $user->setLastname($donnees["last_name"]); $user->setToken(generateRandomString(200)); $request = $bdd->prepare("UPDATE driver SET token=:token WHERE driver_id = :driver"); $request->execute(array('token' => $user->getToken(), 'driver' => $user->getId())); return $user; } } else { return null; } } else { return null; } } }
/** * Insert a block into the block table. Will fail if there is a conflicting * block (same name and options) already in the database. * * @param IDatabase $dbw If you have one available * @return bool|array False on failure, assoc array on success: * ('id' => block ID, 'autoIds' => array of autoblock IDs) */ public function insert($dbw = null) { global $wgBlockDisablesLogin; wfDebug("Block::insert; timestamp {$this->mTimestamp}\n"); if ($dbw === null) { $dbw = wfGetDB(DB_MASTER); } # Periodic purge via commit hooks if (mt_rand(0, 9) == 0) { Block::purgeExpired(); } $row = $this->getDatabaseArray(); $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq"); $dbw->insert('ipblocks', $row, __METHOD__, ['IGNORE']); $affected = $dbw->affectedRows(); $this->mId = $dbw->insertId(); # Don't collide with expired blocks. # Do this after trying to insert to avoid locking. if (!$affected) { # T96428: The ipb_address index uses a prefix on a field, so # use a standard SELECT + DELETE to avoid annoying gap locks. $ids = $dbw->selectFieldValues('ipblocks', 'ipb_id', ['ipb_address' => $row['ipb_address'], 'ipb_user' => $row['ipb_user'], 'ipb_expiry < ' . $dbw->addQuotes($dbw->timestamp())], __METHOD__); if ($ids) { $dbw->delete('ipblocks', ['ipb_id' => $ids], __METHOD__); $dbw->insert('ipblocks', $row, __METHOD__, ['IGNORE']); $affected = $dbw->affectedRows(); $this->mId = $dbw->insertId(); } } if ($affected) { $auto_ipd_ids = $this->doRetroactiveAutoblock(); if ($wgBlockDisablesLogin && $this->target instanceof User) { // Change user login token to force them to be logged out. $this->target->setToken(); $this->target->saveSettings(); } return ['id' => $this->mId, 'autoIds' => $auto_ipd_ids]; } return false; }
public function run() { // echo "inside model/run"; $uid = $_POST['login']; $password = MD5($_POST['password']); $po = UserDAOImpl::doLogin($uid, $password); // get from DB /** * 1. no record found * 2. user email and password matched and status is activated * 3. user email and password matched and status is non-activated * 4. exception */ if (null == $po) { $msg = NO_RECORD_PROMPT . BACK_TO_LOGIN_LINK; // header('location: ../login'); } elseif ($po->status == STATUS_ACTIVATED) { $user = new User(); // vo : used to convey user info $user->setId($po->id); $user->setUserName($po->username); $user->setPassword($po->password); $user->setEmail($po->email); $user->setStatus($po->status); $user->setToken($po->token); $user->setTokenExptime($po->token_exptime); $user->setRegTime($po->regtime); Session::init(); Session::set('loggedIn', true); Session::set('user', $user); // header('location: ../dashboard'); $msg = STATUS_LOGIN_SUCCESS; } elseif ($po->status == STATUS_NON_ACTIVATED) { $msg = STATUS_NON_ACTIVATED_PROMPT . BACK_TO_LOGIN_LINK; } else { //header('location: ../login?status=exception'); $msg = "Unknown Exception happened when login."; } return $msg; }
public function propareVO() { // Get data from post $username = stripslashes(trim($_POST['userid'])); // user id $pwd = md5(trim($_POST['pwd'])); $email = trim($_POST['email']); $regtime = R::isoDateTime(); $token = md5($username . $pwd . $regtime); //create activation token $token_exptime = time() + 60 * 60 * 24; //expire time 24 hours // create a vo for convey object info $user = new User(); $user->setUserName($username); $user->setPassword($pwd); $user->setEmail($email); $user->setToken($token); $user->setTokenExptime($token_exptime); $user->setRegTime($regtime); return $user; }
/** * 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); }
foreach ($ips as $ip) { if (filter_var($ip, FILTER_VALIDATE_IP)) { $path[] = $ip; } } return array_pop($path); } else { if (filter_var($fwd, FILTER_VALIDATE_IP) && !$trustremote && $checkforwarded) { // single return $fwd; } else { // as usual return $remote; } } } } } // Make our class available automatically $user = new User(); $user->setDebug($debug); $user->setLog($log); $user->setMysql($mysqli); $user->setSalt($config['SALT']); $user->setSmarty($smarty); $user->setConfig($config); $user->setMail($mail); $user->setToken($oToken); $user->setBitcoin($bitcoin); $user->setSetting($setting); $user->setErrorCodes($aErrorCodes);
/** * 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; }
$user->setPassword($_POST['password']); $user->setAuthTokenType($_POST['authTokenType']); $user->setTime(time()); $token = $apl->getTokenByCredentials($user); echo json_encode(array('token' => $token)); } else { if (preg_match('/^(mob-change-password){1}$/', $_POST['method'])) { $user = new User(); $user->setToken($_POST['token']); $user->setPassword($_POST['password']); $user->setNewPassword($_POST['newPassword']); $user->setTime(time()); $feedback = $apl->updatePassword($user); echo json_encode(array('feedback' => $feedback, 'token' => $user->getToken())); } else { if (preg_match('/^(mob-get-user){1}$/', $_POST['method'])) { $user = new User(); $user->setToken($_POST['token']); $user = $apl->getUser($user); echo json_encode(array('id' => $user->getId(), 'name' => utf8_encode($user->getName()), 'email' => $user->getEmail(), 'image' => $user->getImage())); } else { if (preg_match('/^(mob-invalidate-token){1}$/', $_POST['method'])) { $user = new User(); $user->setToken($_POST['token']); $user->setTime(0); $return = $apl->invalidateAuthToken($user); echo json_encode(array('feedback' => $return)); } } } }
/** * When creating a user account, optionally fill in preferences and such. * For instance, you might pull the email address or real name from the * external user database. * * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * * @param User $user * @access public */ function initUser(&$user) { global $G_SESSION; //unless you want the person to be nameless, you should probably populate // info about this user here if (isset($G_SESSION)) { $user->setRealName($G_SESSION->getRealName()); $user->setEmail($G_SESSION->getEmail()); } $user->mEmailAuthenticated = wfTimestampNow(); $user->setToken(); //turn on e-mail notifications by default $user->setOption('enotifwatchlistpages', 1); $user->setOption('enotifusertalkpages', 1); $user->setOption('enotifminoredits', 1); $user->setOption('enotifrevealaddr', 1); }
/** * 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); }
$r->setDelete('1'); $r->setCreate('1'); $r->setUpdate('1'); $r->setRank($rank->getId()); $r->save(); } $personalities = array('John Travolta', 'Jeff Buckley', 'Tom Cruise', 'John Lennon', 'Emmet Brown', 'Geo trouvetou', 'Luke Skywalker', 'Mac Gyver', 'Marty McFly'); $im = $personalities[rand(0, count($personalities) - 1)]; list($fn, $n) = explode(' ', $im); //Creation du premier compte et assignation en admin $user->setMail($_POST['email']); $user->setPassword($_POST['password']); $user->setLogin($_POST['login']); $user->setFirstName($fn); $user->setName($n); $user->setToken(sha1(time() . rand(0, 1000))); $user->setState(1); $user->setRank($rank->getId()); $user->save(); global $myUser; $myUser = $user; Plugin::enabled('relay-relay'); Plugin::enabled('wireRelay-relay'); Plugin::enabled('vocal_infos-vocalinfo'); Plugin::enabled('room-room'); Plugin::enabled('eventManager-eventmanager'); Plugin::enabled('profile-profile'); Plugin::enabled('dashboard-dashboard'); Plugin::enabled('dashboard-monitoring-dashboard-monitoring'); } else { ?>
public function setToken($token) { $this->__load(); return parent::setToken($token); }
/** * Adds the User object to the shared database * * @param User $User * @param String $password * @param String $email * @param String $realname * * @return bool success */ protected function addToDatabase(User &$User, $password, $email, $realname) { wfProfileIn(__METHOD__); global $wgExternalSharedDB; $dbw = wfGetDB(DB_MASTER, [], $wgExternalSharedDB); try { $userId = null; $result = null; if (is_null($result)) { $dbw->insert('`user`', ['user_id' => null, 'user_name' => $User->mName, 'user_real_name' => $realname, 'user_password' => $User->mPassword, 'user_newpassword' => '', 'user_email' => $email, 'user_touched' => '', 'user_token' => '', 'user_options' => '', 'user_registration' => $dbw->timestamp($User->mRegistration), 'user_editcount' => 0, 'user_birthdate' => $User->mBirthDate], __METHOD__); $userId = $dbw->insertId(); } else { if (!$result) { throw new ExternalUserException(); } } $User->mId = $userId; $User->setToken(); $User->saveSettings(); $dbw->commit(__METHOD__); wfRunHooks('ExternalUserAddUserToDatabaseComplete', [&$User]); \Wikia\Logger\WikiaLogger::instance()->info('HELIOS_REGISTRATION_INSERTS', ['exception' => new Exception(), 'userid' => $User->mId, 'username' => $User->mName]); // Clear instance cache other than user table data, which is already accurate $User->clearInstanceCache(); $ret = true; } catch (DBQueryError $e) { \Wikia\Logger\WikiaLogger::instance()->info(__METHOD__, ['exception' => $e, 'username' => $User->mName]); $dbw->rollback(__METHOD__); $ret = false; } catch (ExternalUserException $e) { \Wikia\Logger\WikiaLogger::instance()->info(__METHOD__, ['exception' => $e, 'username' => $User->mName]); $dbw->rollback(__METHOD__); $ret = false; } wfProfileOut(__METHOD__); return $ret; }
/** * Add a user to the database, return the user object * * @param string $name Username to add * @param array $params Array of Strings Non-default parameters to save to * the database as user_* fields: * - email: The user's email address. * - email_authenticated: The email authentication timestamp. * - real_name: The user's real name. * - options: An associative array of non-default options. * - token: Random authentication token. Do not set. * - registration: Registration timestamp. Do not set. * * @return User|null User object, or null if the username already exists. */ public static function createNew($name, $params = []) { foreach (['password', 'newpassword', 'newpass_time', 'password_expires'] as $field) { if (isset($params[$field])) { wfDeprecated(__METHOD__ . " with param '{$field}'", '1.27'); unset($params[$field]); } } $user = new User(); $user->load(); $user->setToken(); // init token if (isset($params['options'])) { $user->mOptions = $params['options'] + (array) $user->mOptions; unset($params['options']); } $dbw = wfGetDB(DB_MASTER); $seqVal = $dbw->nextSequenceValue('user_user_id_seq'); $noPass = PasswordFactory::newInvalidPassword()->toString(); $fields = ['user_id' => $seqVal, 'user_name' => $name, 'user_password' => $noPass, 'user_newpassword' => $noPass, 'user_email' => $user->mEmail, 'user_email_authenticated' => $dbw->timestampOrNull($user->mEmailAuthenticated), 'user_real_name' => $user->mRealName, 'user_token' => strval($user->mToken), 'user_registration' => $dbw->timestamp($user->mRegistration), 'user_editcount' => 0, 'user_touched' => $dbw->timestamp($user->newTouchedTimestamp())]; foreach ($params as $name => $value) { $fields["user_{$name}"] = $value; } $dbw->insert('user', $fields, __METHOD__, ['IGNORE']); if ($dbw->affectedRows()) { $newUser = User::newFromId($dbw->insertId()); } else { $newUser = null; } return $newUser; }
/** * Add a user to the database, return the user object * * @param string $name Username to add * @param array $params Array of Strings Non-default parameters to save to * the database as user_* fields: * - password: The user's password hash. Password logins will be disabled * if this is omitted. * - newpassword: Hash for a temporary password that has been mailed to * the user. * - email: The user's email address. * - email_authenticated: The email authentication timestamp. * - real_name: The user's real name. * - options: An associative array of non-default options. * - token: Random authentication token. Do not set. * - registration: Registration timestamp. Do not set. * * @return User|null User object, or null if the username already exists. */ public static function createNew($name, $params = array()) { $user = new User(); $user->load(); $user->loadPasswords(); $user->setToken(); // init token if (isset($params['options'])) { $user->mOptions = $params['options'] + (array) $user->mOptions; unset($params['options']); } $dbw = wfGetDB(DB_MASTER); $seqVal = $dbw->nextSequenceValue('user_user_id_seq'); $fields = array('user_id' => $seqVal, 'user_name' => $name, 'user_password' => $user->mPassword->toString(), 'user_newpassword' => $user->mNewpassword->toString(), 'user_newpass_time' => $dbw->timestampOrNull($user->mNewpassTime), 'user_email' => $user->mEmail, 'user_email_authenticated' => $dbw->timestampOrNull($user->mEmailAuthenticated), 'user_real_name' => $user->mRealName, 'user_token' => strval($user->mToken), 'user_registration' => $dbw->timestamp($user->mRegistration), 'user_editcount' => 0, 'user_touched' => $dbw->timestamp($user->newTouchedTimestamp())); foreach ($params as $name => $value) { $fields["user_{$name}"] = $value; } $dbw->insert('user', $fields, __METHOD__, array('IGNORE')); if ($dbw->affectedRows()) { $newUser = User::newFromId($dbw->insertId()); } else { $newUser = null; } return $newUser; }
function createadmin() { $user = new User(); $user->setFirstName("digvijay"); $user->setLastName("mohite"); $user->setUsername("digvijay"); $user->setPassword(md5("digvijay")); $user->setEmail("*****@*****.**"); $user->setToken("adfasfasf"); $this->em->persist($user); $this->em->flush(); echo "Administrator Create"; }