public function activity() { $this->assertLoggedIn(); try { $this->setTitle('Activity Log'); //how do we find them? if ($this->args('id')) { $user = new User($this->args('id')); } else { if ($this->args('username')) { $user = User::byUsername($this->args('username')); } else { $user = new User(); } } //did we really get someone? if (!$user->isHydrated()) { throw new Exception("Could not find that user."); } $this->set('user', $user); $this->setTitle('Activity Log - ' . $user->getName()); //figure out our info. $collection = $user->getActivityStream(); $this->set('activities', $collection->getPage($this->args('page'), 20)); } catch (Exception $e) { $this->setTitle('View User - Error'); $this->set('megaerror', $e->getMessage()); } }
public static function loginWithToken($token, $createSession = true) { $data = unserialize(base64_decode($token)); if (is_array($data) && $data['id'] && $data['token']) { $user = new User($data['id']); if ($user->isHydrated()) { if ($user->checkToken($data['token'])) { self::createLogin($user, $createSession); } } } }
public function delete() { $this->assertLoggedIn(); try { $this->setTitle("Delete User"); //how do we find them? if ($this->args('id')) { $user = new User($this->args('id')); } else { throw new Exception("Could not find that user."); } //are we cool? if (!$user->isHydrated()) { throw new Exception("Could not find that user."); } //are we cool to edit if ($user->get('is_admin')) { throw new Exception("You cannot delete admins."); } if (!User::isAdmin()) { throw new Exception("You are not an admin and cannot delete users."); } if ($this->args('submit')) { $user->delete(); $this->set('status', "The user has been deleted!"); } $this->set('user', $user); } catch (Exception $e) { $this->setTitle('Delete User - Error'); $this->set('megaerror', $e->getMessage()); } }
public function revoke_app() { $this->assertLoggedIn(); $this->set('area', 'app'); try { $token = new OAuthToken($this->args('id')); if (!$token->isHydrated()) { throw new Exception("This app does not exist."); } /** @var User $user */ $user = new User($token->get('user_id')); if ($user->isHydrated() && $user->id != User::$me->id) { throw new Exception("You are not authorized to delete this app."); } $form = new Form(); $field = WarningField::name('warning'); if ($token->isVerified()) { $this->setTitle('Revoke App Permissions - ' . $token->getName()); $form->submitText = "Revoke App Permissions"; $field->value("Are you sure you want to revoke access to this app? Any apps currently using these credentials to print will be broken"); } else { $this->setTitle('Deny App - ' . $token->getName()); $form->submitText = "Deny App"; $field->value("Are you sure you want to deny access to this app?"); } $form->add($field); $this->set('form', $form); if ($form->checkSubmitAndValidate($this->args())) { if ($token->isVerified()) { Activity::log("removed the app named " . $token->getLink() . "."); } else { Activity::log("denied the app named " . $token->getLink() . "."); } $token->delete(); $this->forwardToUrl("/apps"); } } catch (Exception $e) { $this->setTitle('Error'); $this->set('megaerror', $e->getMessage()); } }