/** * Create an avatar picture (and checks all necessary things too) * TODO decouple * TODO total rebuild */ public static function createAvatar() { // check avatar folder writing rights, check if upload fits all rules if (self::isAvatarFolderWritable() and self::validateImageFile()) { // create a jpg file in the avatar folder, write marker to database $user_name = Session::get(Session::SESSION_USER_NAME); $target_file_path = Config::get('avatar.path') . $this->getIdForImage($user_name); self::resizeAvatarImage($_FILES['avatar_file']['tmp_name'], $target_file_path, Config::get('avatar.size'), Config::get('avatar.size')); self::writeAvatarToDatabase(Session::getDecoded(Session::SESSION_USER_NAME)); Session::set(Session::SESSION_USER_AVATAR_FILE, self::getPublicUserAvatarFilePathByUserName(Session::get(Session::SESSION_USER_NAME))); Session::add(Session::SESSION_FEEDBACK_POSITIVE, Text::get('FEEDBACK_AVATAR_UPLOAD_SUCCESSFUL')); } }
/** * renders the feedback messages into the view */ public function getFeedbackNegativeMessages() { // echo out the feedback messages (errors and success messages etc.), // they are in $_SESSION["feedback_positive"] and $_SESSION["feedback_negative"] // get the feedback (they are arrays, to make multiple positive/negative messages possible) $feedback_negative = Session::get(Session::SESSION_FEEDBACK_NEGATIVE); // delete these messages (as they are not needed anymore and we want to avoid to show them twice Session::set(Session::SESSION_FEEDBACK_NEGATIVE, null); return $feedback_negative; }
/** * Checks if the user is logged in or not * * @return bool user's login status */ public static function userIsLoggedIn() { return Session::get(Session::SESSION_USER_LOGGED_IN) ? true : false; }
/** * Log out process: delete cookie, delete session */ public static function logout() { $user_name = Session::getDecoded(Session::SESSION_USER_NAME); $user_provider = Session::get(Session::SESSION_USER_PROVIDER_TYPE); if ($user_provider == UserModel::PROVIDER_TYPE_FB) { // Facebook // Session::set(Session::FACEBOOK_ID, null); // Session::set(Session::FACEBOOK_ACCESS_TOKEN, null); // Session::set(Session::FACEBOOK_DISPLAY_NAME, null); // Session::set(Session::FACEBOOK_PICTURE, null); } else { if ($user_provider == UserModel::PROVIDER_TYPE_GO) { // Session::set(Session::GOOGLE_ID, null); // Session::set(Session::GOOGLE_BEARER_TOKEN, null); // Session::set(Session::GOOGLE_DISPLAY_NAME, null); // Session::set(Session::GOOGLE_PICTURE, null); } else { self::deleteCookie($user_name); // solo per provider 'DEFAULT' } } Session::destroy(); Session::updateSessionId($user_name, null); // if(false){ // Il seguente blocco è inutile (vedi statement successivi) // Session::set(Session::SESSION_FEEDBACK_NEGATIVE, null); // Session::set(Session::SESSION_FEEDBACK_POSITIVE, null); // Session::set(Session::SESSION_USER_NAME, null); // Session::set(Session::SESSION_USER_EMAIL, null); // Session::set(Session::SESSION_USER_ACCOUNT_TYPE, null); // Session::set(Session::SESSION_USER_PROVIDER_TYPE, null); // Session::set(Session::SESSION_USER_AVATAR_FILE, null); // Session::set(Session::SESSION_USER_GRAVATAR_IMAGE_URL, null); // Session::set(Session::SESSION_USER_LOGGED_IN, null); // } return true; }