/** * Transform the \User entity. * * @param \User $model * * @return array */ public function transformData($model) { $data = array_only($model->toArray(), User::$includable); if ($model->getAttribute('avatar')) { $data['avatar'] = $model->avatar(); } return $data; }
/** * Transform the \User entity. * * @param \User $model * * @return array */ public function transformData($model) { $user = array_only($model->toArray(), User::$includable); if ($model->getAttribute('avatar')) { $user['avatar'] = $model->avatar(); } if ($model->getAttribute('links')) { $user['links'] = ['replies_web_view' => route('users.replies.web_view', $model->id)]; } return $user; }
function avatarsave() { if ($_SESSION['iuser']) { $model = new User(); $model->avatar(); View::$layout = 'popup'; View::render('popup/close'); } else { View::render('site/redirect', array('text' => 'Доступ запрещен', 'href' => '/')); } }
/** * Retrieve all posts to display on a specific profile page * * @param Object $target The target to retrieve posts for * * @return array[array[string]]string Returns a 2D array with each internal array holding the relevant post data */ public function get_posts($target) { if ($target->exists()) { $sql = "SELECT id, owner_id, post_data FROM posts WHERE target_id=? AND (target_type=?) ORDER BY created DESC LIMIT 10"; if (empty($this->_db->query($sql, [$target->id(), $target->type()])->errors())) { if (!empty($this->_db->results())) { $posts_info = array(); foreach ($this->_db->results() as $result) { $user = new User(); $user->find($result->owner_id, 'users', ['id']); $posts_info[] = ['id' => $result->id, 'content' => $result->post_data, 'user' => $user->name(), 'avatar' => $user->avatar()]; } return $posts_info; } } } return false; }
?> </p> <div class="markdown"> <?php echo premarkdown($ticket->description); ?> </div> </div> <div class="comments"> <?php foreach ($ticket->histories() as $th) { $thu = new User($th->user_id); ?> <div class="comment"> <img src="<?php echo $thu->avatar(); ?> "> <p class="meta"><?php echo $thu->username; ?> | <?php echo dater($th->dt, 'F j, Y \\a\\t g:ia'); ?> </p> <?php foreach ($th->changes() as $c) { ?> <p class="changes"><?php echo $c; ?>
public static function init() { self::setIP(); self::setLocale(); // session have a dataKey to access the JScripts (yes, also the anons) if (empty($_SESSION['dataKey'])) { $_SESSION['dataKey'] = Util::createHash(); } // just some random numbers for identifictaion purpose self::$dataKey = $_SESSION['dataKey']; if (!self::$ip) { return false; } // check IP bans if ($ipBan = DB::Aowow()->selectRow('SELECT count, unbanDate FROM ?_account_bannedips WHERE ip = ? AND type = 0', self::$ip)) { if ($ipBan['count'] > CFG_FAILED_AUTH_COUNT && $ipBan['unbanDate'] > time()) { return false; } else { if ($ipBan['unbanDate'] <= time()) { DB::Aowow()->query('DELETE FROM ?_account_bannedips WHERE ip = ?', self::$ip); } } } // try to restore session if (empty($_SESSION['user'])) { return false; } // timed out... if (!empty($_SESSION['timeout']) && $_SESSION['timeout'] <= time()) { return false; } $query = DB::Aowow()->SelectRow(' SELECT a.id, a.passHash, a.displayName, a.locale, a.userGroups, a.userPerms, a.allowExpire, BIT_OR(ab.typeMask) AS bans, IFNULL(SUM(r.amount), 0) as reputation, a.avatar, a.dailyVotes FROM ?_account a LEFT JOIN ?_account_banned ab ON a.id = ab.userId AND ab.end > UNIX_TIMESTAMP() LEFT JOIN ?_account_reputation r ON a.id = r.userId WHERE a.id = ?d GROUP BY a.id', $_SESSION['user']); if (!$query) { return false; } // password changed, terminate session if (AUTH_MODE_SELF && $query['passHash'] != $_SESSION['hash']) { self::destroy(); return false; } self::$id = intval($query['id']); self::$displayName = $query['displayName']; self::$passHash = $query['passHash']; self::$expires = (bool) $query['allowExpire']; self::$reputation = $query['reputation']; self::$banStatus = $query['bans']; self::$groups = $query['bans'] & (ACC_BAN_TEMP | ACC_BAN_PERM) ? 0 : intval($query['userGroups']); self::$perms = $query['bans'] & (ACC_BAN_TEMP | ACC_BAN_PERM) ? 0 : intval($query['userPerms']); self::$dailyVotes = $query['dailyVotes']; if ($query['avatar']) { self::$avatar = $query['avatar']; } if (self::$localeId != $query['locale']) { // reset, if changed self::setLocale(intVal($query['locale'])); } // stuff, that updates on a daily basis goes here (if you keep you session alive indefinitly, the signin-handler doesn't do very much) // - conscutive visits // - votes per day // - reputation for daily visit if (self::$id) { $lastLogin = DB::Aowow()->selectCell('SELECT curLogin FROM ?_account WHERE id = ?d', self::$id); // either the day changed or the last visit was >24h ago if (date('j', $lastLogin) != date('j') || time() - $lastLogin > 1 * DAY) { // daily votes (we need to reset this one) self::$dailyVotes = self::getMaxDailyVotes(); DB::Aowow()->query(' UPDATE ?_account SET dailyVotes = ?d, prevLogin = curLogin, curLogin = UNIX_TIMESTAMP(), prevIP = curIP, curIP = ? WHERE id = ?d', self::$dailyVotes, self::$ip, self::$id); // gain rep for daily visit if (!(self::$banStatus & (ACC_BAN_TEMP | ACC_BAN_PERM))) { Util::gainSiteReputation(self::$id, SITEREP_ACTION_DAILYVISIT); } // increment consecutive visits (next day or first of new month and not more than 48h) // i bet my ass i forgott a corner case if ((date('j', $lastLogin) + 1 == date('j') || date('j') == 1 && date('n', $lastLogin) != date('n')) && time() - $lastLogin < 2 * DAY) { DB::Aowow()->query('UPDATE ?_account SET consecutiveVisits = consecutiveVisits + 1 WHERE id = ?d', self::$id); } else { DB::Aowow()->query('UPDATE ?_account SET consecutiveVisits = 0 WHERE id = ?d', self::$id); } } } return true; }
/** * @param User $user * * @return bool|User */ public function makeUser(User $user) { $id = $user->id(); $email = $user->email(); $avatar_link = $user->avatar(); $display_name = $user->displayName(); $refreshToken = $user->refreshToken(); $this->database->query("INSERT INTO `users` (`id`, `email`, `avatar_link`, `display_name`, `refresh_token`) VALUES ({$id},'{$email}','{$avatar_link}','{$display_name}', '{$refreshToken}')"); return $this->getUser($id); }