public function SaveLoginOnClient(\model\User $user) { // Prepare values $cookieValues = implode(':', array($user->GetUserName(), $user->GetToken(), $user->GetSignature())); // Save values in cookie (expires in 30 days) return setcookie(self::$COOKIE_ID, $cookieValues, time() + 60 * 60 * 24 * self::$COOKIE_VALID_DAYS); }
public function Add(\model\User $user) { if ($this->GetRegistrationsForHour() > self::$MAX_REGISTRATIONS_PER_HOUR) { throw new \Exception("Max number of registrations per hour reached. Please try again in 30-60 minutes."); } // Throw exception if username is taken if ($this->GetUserByUsername($user->GetUserName())) { throw new \Exception(self::$DB_USERNAME_EXISTS); } try { // Prepare db statement $statement = self::$db->prepare('INSERT INTO ' . self::$DB_TABLE_NAME . ' (user_id, user_name, user_firstname, user_surname, user_password, created)' . ' VALUES ' . '(NULL, :userName, :firstName, :surName, :password, NOW())'); // Prepare input array $inputArray = ['userName' => $user->GetUserName(), 'firstName' => $user->GetFirstName(), 'surName' => $user->GetSurName(), 'password' => $user->GetPassword()]; // Execute db statement $statement->execute($inputArray); // Check if db insertion was successful return $statement->rowCount() == 1; } catch (\Exception $exception) { throw new \Exception(self::$DB_INSERT_ERROR); } }
public function GetUserLoginsForHour(\model\User $user) { try { $returnArray = []; // Prepare db statement $statement = self::$db->prepare('SELECT * FROM ' . self::$DB_TABLE_NAME . ' WHERE `user_name` = :userName AND ' . ' `created` LIKE \'' . date("Y-m-d H") . '%\''); // Prepare input array $inputArray = ['userName' => $user->GetUserName()]; // Execute db statement $statement->execute($inputArray); // Fetch rows $userRowsArray = $statement->fetchAll(); return sizeOf($userRowsArray); } catch (\Exception $exception) { throw new \Exception(self::$DB_QUERY_ERROR); } }
public function SetLoginUsername(\model\User $user) { $_SESSION['last_login_uname'] = $user->GetUserName(); }