/** * @method DELETE * @json */ public function logout() { $user = \Bazalt\Auth::getUser(); if ($user->isGuest()) { return new Response(Response::OK, $user->toArray()); } \Bazalt\Auth::logout(); $user = \Bazalt\Auth::getUser(); return new Response(Response::OK, $user->toArray()); }
/** * Хендлер на евент моделі onSave. Викликається при збереженні об'єкта в БД * * @param \Bazalt\ORM\Record $record Поточний запис * @param bool &$return Флаг, який зупиняє подальше виконання save() * * @return void */ public function onSave(\Bazalt\ORM\Record $record, &$return) { $options = $this->getOptions(); $user = \Bazalt\Auth::getUser(); if (!array_key_exists(get_class($record), $options) || $user->isGuest()) { return; } $options = $options[get_class($record)]; if (array_key_exists('created_by', $options) && $record->isPKEmpty()) { $record->{$options['created_by']} = $user->id; } if (array_key_exists('updated_by', $options)) { $record->{$options['updated_by']} = $user->id; } }
/** * @method DELETE * @json */ public function deleteUser($id) { $user = \Bazalt\Auth::getUser(); $profile = User::getById($id); if (!$profile) { return new Response(400, ['id' => 'User not found']); } if (!$user->hasPermission('auth.can_delete_user')) { return new Response(Response::FORBIDDEN, 'Permission denied'); } if (!$user->isGuest() && $user->id == $profile->id) { return new Response(Response::BADREQUEST, ['id' => 'Can\'t delete yourself']); } $profile->is_deleted = 1; $profile->save(); return new Response(Response::OK, true); }