public function create(User $_user) { $this->_user = $_user; $query = "INSERT INTO remember (user_id, token, date_expires, user_agent) VALUES (:u, :t, :d, :a)"; $this->_pdo->perform($query, ["u" => $this->user_id = $_user->getId(), "t" => $this->token = Utility::getRandomString(30), "d" => $this->date_expires = Utility::getExpiryAsMySQLDateTime(self::EXPIRE_TIME), "a" => $this->user_agent = $_SERVER["HTTP_USER_AGENT"]]); $cookie_val = $_user->getEmailUniversity() . self::$COOKIE_SEPARATOR . $this->token; setcookie(self::$COOKIE_REMEMBER, $cookie_val, time() + Utility::SECONDS_IN_DAY * 30, "/"); $this->id = $this->_pdo->lastInsertId(); }
private function send(\string $template_name, User $to_user, array $data) { $base_path = __DIR__ . self::$FOLDER_PATH . DIRECTORY_SEPARATOR . $template_name . DIRECTORY_SEPARATOR; $body_html = file_get_contents($base_path . self::$HTML_FILE_NAME); $body_text = file_get_contents($base_path . self::$TEXT_FILE_NAME); foreach ($data as $key => $var) { $body_html = str_replace("#!" . $key . "!#", $var, $body_html); $body_text = str_replace("#!" . $key . "!#", $var, $body_text); } $body_html = str_replace("#!BASE_URL!#", Config::getBaseUrl(), $body_html); $body_text = str_replace("#!BASE_URL!#", Config::getBaseUrl(), $body_text); $address = $this->is_dev ? Config::getDevUserEmail() : $to_user->getEmailUniversity(); $this->_phpmailer->addAddress($address, $to_user->getNameFull()); $this->_phpmailer->msgHTML($body_html); $this->_phpmailer->AltBody = $body_text; $this->logEmail($this->_phpmailer->send(), $template_name, $to_user, $data); $this->_phpmailer->clearAllRecipients(); $this->_phpmailer->clearAttachments(); $this->_phpmailer->clearReplyTos(); }
private function login(User $_user) { $this->_user = $_user; $_SESSION[self::$VALID_LOGIN] = $_user->getEmailUniversity(); $_SESSION[self::$LAST_ACTION] = time(); }