public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $this->pluginTemplate = '/users/online.plug.html'; $data = $data->fork(); $users = new Model_User(); $users->where('DATE_ADD(lastrequest, INTERVAL 30 MINUTE) > NOW()'); $data->set('usersonline', $users->getTotal()); parent::output($data, $stream); }
/** * Create an Auth object based on a user's auth setting or the default authentication method. * @param string $usernameOrEmail The user name or email address of the user. * @param string $field Which field to use (username, email, or either) * @param string $method Default authentication method for nonexistent users (e.g., so users can authenticate through LDAP even if they don't have a user record yet) * @return Auth */ public static function ForUser($usernameOrEmail, $field = 'either', $method = TYPEF_AUTH_DEFAULT) { switch ($field) { case 'username': $field = 'username'; break; case 'email': $field = 'email'; break; default: $field = 'username'; if (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $usernameOrEmail)) { $field = 'email'; } break; } $users = new Model_User(); $users->where("{$field} = ?", $usernameOrEmail); $obj = null; if ($users->getTotal() == 0) { $user = Model_User::Create(); $user[$field] = $usernameOrEmail; $cls = 'Auth_' . $method; } else { if ($users->getTotal() > 1) { Typeframe::Log("WARNING: {$usernameOrEmail} matches more than one {$field} in the user table."); } $user = $users->getFirst(); $userAuth = $user['auth']; if (!$userAuth) { $userAuth = 'Hash'; } // Older users might have a blank auth field. Assume Hash $cls = 'Auth_' . $userAuth; } if (!is_subclass_of($cls, 'Auth')) { throw new Exception("{$cls} is not a subclass of Auth"); } $obj = new $cls($user); return $obj; }
public function index() { if ($this->registry["ui"]["admin"]) { $this->view->setTitle("Статистика"); $this->view->setLeftContent($this->view->render("left_users", array())); $users = new Model_User(); $data = $users->getTotal(); if ($data["all"] / 1024 / 1024 > 1) { $data["all_val"] = round($data["all"] / 1024 / 1024, 2); $data["all_unit"] = "mb"; } if ($data["all"] / 1024 / 1024 / 1024 > 1) { $data["all_val"] = round($data["all"] / 1024 / 1024 / 1024, 2); $data["all_unit"] = "gb"; } foreach ($data["users"] as $part) { if ($part["quota"] == 0) { $user[$part["login"]]["quota_val"] = "<span style='font-size: 18px; position: relative; top: 3px'>∞</span> (квота не задана)"; } if ($part["quota"] / 1024 / 1024 > 1) { $user[$part["login"]]["quota_val"] = round($part["quota"] / 1024 / 1024, 2); $user[$part["login"]]["quota_unit"] = "mb"; } if ($part["quota"] / 1024 / 1024 / 1024 > 1) { $user[$part["login"]]["quota_val"] = round($part["quota"] / 1024 / 1024 / 1024, 2); $user[$part["login"]]["quota_unit"] = "gb"; } if ($part["sum"] / 1024 / 1024 > 1) { $user[$part["login"]]["val"] = round($part["sum"] / 1024 / 1024, 2); $user[$part["login"]]["unit"] = "mb"; } if ($part["sum"] / 1024 / 1024 / 1024 > 1) { $user[$part["login"]]["val"] = round($part["sum"] / 1024 / 1024 / 1024, 2); $user[$part["login"]]["unit"] = "gb"; } if ($part["quota"] != 0) { $user[$part["login"]]["percent"] = round($part["sum"] / $part["quota"] * 100, 0); } else { $user[$part["login"]]["percent"] = "0"; } } $this->view->users_statistic(array("total" => $data, "users" => $user)); } }
function index() { $this->view->setTitle("Statistics"); if ($this->registry["ui"]["admin"]) { $users = new Model_User(); $data = $users->getTotal(); if ($data["all"] / 1024 / 1024 > 1) { $data["all_val"] = round($data["all"] / 1024 / 1024, 2); $data["all_unit"] = "mb"; } if ($data["all"] / 1024 / 1024 / 1024 > 1) { $data["all_val"] = round($data["all"] / 1024 / 1024 / 1024, 2); $data["all_unit"] = "gb"; } foreach ($data["users"] as $part) { $user[$part["login"]]["quota"] = $part["quota"]; if ($part["quota"] / 1024 / 1024 > 1) { $user[$part["login"]]["quota_val"] = round($part["quota"] / 1024 / 1024, 2); $user[$part["login"]]["quota_unit"] = "mb"; } if ($part["quota"] / 1024 / 1024 / 1024 > 1) { $user[$part["login"]]["quota_val"] = round($part["quota"] / 1024 / 1024 / 1024, 2); $user[$part["login"]]["quota_unit"] = "gb"; } if ($part["sum"] / 1024 / 1024 > 1) { $user[$part["login"]]["val"] = round($part["sum"] / 1024 / 1024, 2); $user[$part["login"]]["unit"] = "mb"; } if ($part["sum"] / 1024 / 1024 / 1024 > 1) { $user[$part["login"]]["val"] = round($part["sum"] / 1024 / 1024 / 1024, 2); $user[$part["login"]]["unit"] = "gb"; } $user[$part["login"]]["percent"] = round($part["sum"] / $part["quota"] * 100, 0); } $this->view->users_statistic(array("total" => $data, "users" => $user)); } }
<?php /** * User password reset controller. * * Allows users to begin the password reset process. * * @package User */ // process the form if ('POST' == $_SERVER['REQUEST_METHOD']) { $users = new Model_User(); $users->where('email = ?', $_REQUEST['email']); if (1 == $users->getTotal()) { // get userid, resetkey, and set to expire in 1 day $user = $users->getFirst(); $userid = $user->get('userid'); $resetkey = randomID(); $expire = date('Y-m-d H:i:s', time() + 86400); // create an entry in the password reset table $reset = Model_UserReset::Create(); $reset->set('userid', $userid); $reset->set('resetkey', $resetkey); $reset->set('expire', $expire); $reset->save(); // construct e-mail body $mm = new Pagemill($pm->root()->fork()); $mm->setVariable('username', $user->get('username')); $mm->setVariable('reseturl', sprintf('http://%s%s/password?userid=%d&resetkey=%s', $_SERVER['HTTP_HOST'], TYPEF_WEB_DIR, $userid, $resetkey)); $body = str_replace('&', '&', $mm->writeString('<pm:include template="/users/reset.eml" />', true)); // e-mail the user so they can reset their password
$searchfield = trim(@$_REQUEST['searchfield']); $searchrange = trim(@$_REQUEST['searchrange']); $searchquery = trim(@$_REQUEST['searchquery']); $pm->setVariable('searchfield', $searchfield); $pm->setVariable('searchrange', $searchrange); $pm->setVariable('searchquery', $searchquery); if (!empty($searchquery)) { $pm->setVariable('searched', true); // filter users using given criteria $field = 'email' == $searchfield ? $searchfield : 'username'; $what = 'starts' == $searchrange ? "{$searchquery}%" : "%{$searchquery}%"; $users->where("{$field} LIKE ?", $what); } // set up pagination $page = trim(@$_REQUEST['page']); if (!ctype_digit($page)) { $page = 1; } $perpage = 20; $totalresults = $users->getTotal(); $totalpages = max(ceil($totalresults / $perpage), 1); $limit = ($page - 1) * $perpage; $pagedurl = sprintf(TYPEF_WEB_DIR . '/admin/users?searchfield=%s&searchrange=%s&searchquery=%s', urlencode($searchfield), urlencode($searchrange), urlencode($searchquery)); $pm->setVariable('page', $page); $pm->setVariable('totalpages', $totalpages); $pm->setVariable('pagedurl', $pagedurl); // set up limits $users->limit("{$limit}, {$perpage}"); // add users and their count to the template $pm->setVariable('users', $users); $pm->setVariable('totalresults', $totalresults);