/** * @operationName("Create API key") * @operationDescription("Create API key") */ public function createAction() { $form = new Forms\ApikeyForm(); $apikey = new Models\Apikey(); $form->setModel($apikey); $this->view->setVar('form', $form); if ($uid = $this->request->get('uid')) { if (Models\Apikey::findFirst("userId = {$uid}")) { return $this->response->redirect('/admin/permission/apikey/edit/' . $uid); } $this->view->setVar('user', Users::findFirst($uid)); } if (!$this->request->isPost()) { return false; } $form->bind($this->request->getPost(), $apikey); if (!$form->isValid()) { return $this->showInvalidMessages($form); } $apikey = $form->getEntity(); try { if (!$apikey->save()) { return $this->showModelMessages($apikey); } } catch (\Exception $e) { return $this->showException($e, $apikey->getMessages()); } $this->flashSession->success('SUCCESS_APIKEY_CREATED'); return $this->redirectHandler('/admin/permission/apikey/edit/' . $apikey->id); }
public function updateSpamUser($id, $reason) { if ($id > 0) { /** @var Entities\users $user */ $user = Entities\Users::findFirst($id); $user->status = 'spam'; $user->spamReason = $reason; $user->updatedAt = time(); if ($user->save() === false) { throw new Exception\RuntimeException('Save user failed'); } } }