public function action_login() { // Already logged in Auth::check() and Response::redirect('admin'); $val = Validation::forge(); if (Input::method() == 'POST') { $val->add('email', 'Email or Username')->add_rule('required'); $val->add('password', 'Password')->add_rule('required'); if ($val->run()) { if (!Auth::check()) { if (Auth::login(Input::post('email'), Input::post('password'))) { // assign the user id that lasted updated this record foreach (\Auth::verified() as $driver) { if (($id = $driver->get_user_id()) !== false) { // credentials ok, go right in $current_user = Model\Auth_User::find($id[1]); Session::set_flash('success', e('Welcome, ' . $current_user->username)); Response::redirect_back('admin'); } } } else { $this->template->set_global('login_error', 'Login failed!'); } } else { $this->template->set_global('login_error', 'Already logged in!'); } } } $this->template->title = 'ITNT Timesheets Login'; $this->template->content = View::forge('admin/login', array('val' => $val), false); }
public function action_edit($id = null) { if ($customer = Model_Customer::find($id)) { $val = Model_Customer::validate('edit'); if ($val->run()) { $customer->description = Input::post('description'); $customer->contact_person = Input::post('contact_person'); $customer->phone = Input::post('phone'); $customer->email = Input::post('email'); if ($customer->save()) { Session::set_flash('success', e('Updated customer #' . $id)); Response::redirect('admin/customers/view/' . $customer->id); } else { Session::set_flash('error', e('Could not update customer #' . $id)); } } else { if (Input::method() == 'POST') { $customer->description = $val->validated('description'); $customer->contact_person = $val->validated('contact_person'); $customer->phone = $val->validated('phone'); $customer->email = $val->validated('email'); Session::set_flash('error', $val->error()); } $this->template->set_global('customer', $customer, false); } $this->template->title = "Customers » " . $customer->description . " » Edit"; $this->template->content = View::forge('admin/customers/edit'); } else { Session::set_flash('error', 'Cannot find the selected customer.'); Response::redirect_back('admin/customers'); } }
public function action_login() { // already logged in? if (Auth::check()) { // yes, so go back to the page the user came from, or the // application dashboard if no previous page can be detected //Messages::info(__('login.already-logged-in')); Response::redirect_back(''); } // was the login form posted? if (Input::method() == 'POST') { // check the credentials. print_r(Input::all()); if (Auth::login(Input::param('email'), Input::param('password'))) { // did the user want to be remembered? if (Input::param('remember', false)) { // create the remember-me cookie Auth::remember_me(); } else { // delete the remember-me cookie if present Auth::dont_remember_me(); } // logged in, go back to the page the user came from, or the // application dashboard if no previous page can be detected Response::redirect_back('/home'); } else { // login failed, show an error message $this->error = 'test'; } } // display the login page return \View::forge('auth/login'); }
public function action_index() { $data = array(); if (\Input::post()) { $username = \Input::post('username'); $password = \Input::post('password'); if (\Auth::login($username, $password)) { // does the user want to be remembered? if (\Input::post('remember_me')) { // create the remember-me cookie \Auth::remember_me(); } else { // delete the remember-me cookie if present \Auth::dont_remember_me(); } \Response::redirect_back('/'); } else { // Oops, no soup for you. Try to login again. Set some values to // repopulate the username field and give some error text back to the view. $data['username'] = $username; \Session::set_flash('error', 'Wrong username/password combo. Try again'); } } // Show the login form. $this->template->title = "Login"; $this->template->content = \View::forge('auth/login.twig', $data); }
public function before() { parent::before(); // check for admin if (!Auth::member(5)) { \Response::redirect_back('home'); } }
public function action_callback() { // Opauth can throw all kinds of nasty bits, so be prepared try { // get the Opauth object $opauth = \Auth_Opauth::forge(false); // and process the callback $status = $opauth->login_or_register(); // fetch the provider name from the opauth response so we can display a message $provider = $opauth->get('auth.provider', '?'); // deal with the result of the callback process switch ($status) { // a local user was logged-in, the provider has been linked to this user case 'linked': // inform the user the link was succesfully made \Messages::success(sprintf(__('login.provider-linked'), ucfirst($provider))); // and set the redirect url for this status $url = 'dashboard'; break; // the provider was known and linked, the linked account as logged-in // the provider was known and linked, the linked account as logged-in case 'logged_in': // inform the user the login using the provider was succesful \Messages::success(sprintf(__('login.logged_in_using_provider'), ucfirst($provider))); // and set the redirect url for this status $url = 'dashboard'; break; // we don't know this provider login, ask the user to create a local account first // we don't know this provider login, ask the user to create a local account first case 'register': // inform the user the login using the provider was succesful, but we need a local account to continue \Messages::info(sprintf(__('login.register-first'), ucfirst($provider))); // and set the redirect url for this status $url = 'user/register'; break; // we didn't know this provider login, but enough info was returned to auto-register the user // we didn't know this provider login, but enough info was returned to auto-register the user case 'registered': // inform the user the login using the provider was succesful, and we created a local account \Messages::success(__('login.auto-registered')); // and set the redirect url for this status $url = 'dashboard'; break; default: throw new \FuelException('Auth_Opauth::login_or_register() has come up with a result that we dont know how to handle.'); } $url = str_replace('#_=_', '', $url); // redirect to the url set \Response::redirect($url); } catch (\OpauthException $e) { \Messages::error($e->getMessage()); \Response::redirect_back(); } catch (\OpauthCancelException $e) { // you should probably do something a bit more clean here... exit('It looks like you canceled your authorisation.' . \Html::anchor('users/oath/' . $provider, 'Click here') . ' to try again.'); } }
public function action_remove($user_id) { // check for admin if (!Auth::member(5)) { \Response::redirect_back('home'); } $user = Model_User::query()->where('id', $user_id)->get_one(); $user->delete(); Response::Redirect('users'); }
/** * Удаление записи * * @param int $id */ public function action_delete($id = null) { is_null($id) and \Response::redirect_back('admin/videos'); if ($video = \Model_Video::find($id)) { $video->delete(); \Session::set_flash('success', 'Видео удалено.'); } else { \Session::set_flash('error', 'Could not delete video #' . $id); } \Response::redirect_back('admin/videos'); }
public function action_delete($id = null) { $category = Model_Category::find($id); if ($category->delete()) { // Delete cache \Cache::delete('sidebar'); \Messages::success(__('backend.category.deleted')); } else { \Messages::error(__('error')); } \Response::redirect_back(\Router::get('admin_category')); }
public function action_delete($id = null) { $post = \Model_Post::find($id); if ($post->delete()) { // Delete cache \Cache::delete('sidebar'); \Messages::success(__('backend.post.deleted')); } else { \Messages::error(__('error')); } \Response::redirect_back(\Router::get('admin_post')); }
public function action_logout() { // remove the remember-me cookie, we logged-out on purpose \Auth::dont_remember_me(); // logout \Auth::logout(); // inform the user the logout was successful \Messages::success(__('user.login.logged-out')); // and go back to where you came from (or the application // homepage if no previous page can be determined) \Response::redirect_back(); }
/** * Редактирование пользователя * * @param integer $id id пользователя */ public function action_edit($id = null) { is_null($id) and \Response::redirect('admin/users'); $user = \Model_User::find($id); if (!empty($user)) { if (\Input::method() == 'POST') { $val = \Model_User::validate('edit'); // Если ихменили E-Mail if (\Input::post('email') != $user->email) { $val->add_callable(new \MyRules()); $val->add_field('email', 'E-Mail', 'required|max_length[255]|unique[users.email]'); $val->set_message('unique', 'E-Mail существует.'); } if ($val->run()) { try { // Сбрасіваем пароль $new_password = \Auth::reset_password($user->username); $arr = array('email' => \Input::post('email')); if (trim(\Input::post('password') != '')) { $arr['old_password'] = $new_password; $arr['password'] = \Input::post('password'); } $updated = \Auth::update_user($arr, $user->username); if ($updated) { \Session::set_flash('success', e('Пользователь отредактирован')); \Response::redirect_back('admin/users'); } else { // oops, creating a new user failed? \Session::set_flash('error', e('Не удалось отредактировать данные пользователя')); } } catch (\SimpleUserUpdateException $e) { // Повтор е-мэил if ($e->getCode() == 2) { \Session::set_flash('error', e('E-Mail существует')); } else { \Session::set_flash('error', $e->getMessage()); } } } else { \Session::set_flash('error', $val->error()); } } \View::set_global('user', $user, FALSE); $this->template->title = 'Пользователи'; $this->template->content = \View::forge('users/edit'); } else { \Session::set_flash('error', e('Пользователь отсутствует')); \Response::redirect('admin/users'); } }
/** * Get all categorys from author * @param string $author username */ public function action_show_by_author($author = false) { $author = $this->data['author'] = \Model_User::query()->where('username', $author)->get_one(); if (!$author) { \Messages::error(__('frontend.author.not-found')); \Response::redirect_back(\Router::get('homepage')); } else { // Pagination $config = array('pagination_url' => \Uri::current(), 'total_items' => count($author->posts), 'per_page' => \Config::get('application.pagination.per_page'), 'uri_segment' => 'page'); $this->data['pagination'] = $pagination = \Pagination::forge('category_pagination', $config); // Get categorys $this->data['categories'] = Model_Category::query()->where('user_id', $author->id)->order_by('created_at', 'DESC')->offset($pagination->offset)->limit($pagination->per_page)->get(); return \Response::forge(\View::forge('frontend/category/author')->set($this->data, null, false)); } }
/** * Действие для управления настройками */ public function action_index() { $settings = \Model_Striker::find('first'); $seasons = \Model_Season::get_seasons_for_select(); if (\Input::method() == 'POST') { $settings->show = \Input::post('show', 0); $settings->season_id = \Input::post('season_id'); $settings->save(); \Session::set_flash('success', 'Настройки обновлены.'); \Response::redirect_back('admin/competitions/strikers'); } \View::set_global('seasons', $seasons); \View::set_global('settings', $settings); $this->template->content = \View::forge('competitions/strikers/index', array('settings' => $settings)); }
public function action_url($table_name) { // Find class name and metadata etc $class_name = \Admin::getClassForTable($table_name); if ($class_name === false) { return $this->show404(null, "type"); } // Import the data $this->import_result = \CMF\Utils\Importer::importUrl($class_name, \Input::post('import_url')); // If success, redirect back with message if (isset($this->import_result['success']) && $this->import_result['success']) { \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.messages.import_success'))); \Response::redirect("/admin/{$table_name}", 'location'); } // No success, damn! \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.errors.actions.import'))); \Response::redirect_back("/admin/{$table_name}"); }
/** * Действие для редактирования матча * * @param int $id */ public function action_edit($id = null) { is_null($id) and \Response::redirect_back('admin/competitions/matches'); if (!($match = \Model_Match::find($id, array('related' => array('season', 'team_1', 'team_2', 'matches_events', 'matches_events.event'))))) { \Session::set_flash('error', 'Матч не найден.'); \Response::redirect_back('admin/competitions/matches'); } $val = \Model_Match::validate('edit'); if ($val->run()) { $match->status_id = \Input::post('status_id'); $match->date = strtotime(\Input::post('date')); $match->name = \Input::post('name'); $match->team_1_goals = \Input::post('team_1_goals'); $match->team_2_goals = \Input::post('team_2_goals'); $match->team_1_lineup = \Input::post('team_1_lineup'); $match->team_2_lineup = \Input::post('team_2_lineup'); $match->add_data = \Input::post('add_data'); if ($match->save()) { // Если нужно редактировать турнирную таблицу if (\Input::post('change_table')) { \Model_Table::edit_table($match->season_id, $match->team_1_id, $match->team_2_id, $match->team_1_goals, $match->team_2_goals); } \Session::set_flash('success', 'Данные матча обновлены.'); \Response::redirect_back('admin/competitions/matches/edit/' . $id); } else { Session::set_flash('error', 'Could not update match #' . $id); } } else { if (\Input::method() == 'POST') { $match->status_id = $val->validated('status_id'); $match->date = $val->validated('date'); $match->name = $val->validated('name'); $match->team_1_goals = $val->validated('team_1_goals'); $match->team_2_goals = $val->validated('team_2_goals'); $match->team_1_lineup = $val->validated('team_1_lineup'); $match->team_2_lineup = $val->validated('team_2_lineup'); $match->add_data = $val->validated('add_data'); \Session::set_flash('error', $val->error()); } $this->template->set_global('match', $match, false); $this->template->set_global('events', \Model_Event::get_events_for_select(), false); } $this->template->content = \View::forge('competitions/matches/edit'); }
/** * Действие для отображения голосований */ public function action_votes() { $votes = \Model_Vote::find(1); // Проверяем включён ли виджет if ($votes->enable) { $data['question'] = $votes->question; $data['answers'] = json_decode($votes->answers_json); // Если пользователь нажал "Проголосовать" if (\Input::method() == 'POST') { if (\Input::post('answers')) { // Прибавляем 1 к счётчику ответа foreach ($data['answers'] as $key => $item) { if (\Input::post('answers') == $item->answer) { $data['answers'][$key]->count++; } } $votes->answers_json = json_encode($data['answers']); $votes->save(); // Записываем куку на месяц \Cookie::set('vote_' . $votes->hash, 1, 60 * 60 * 24 * 31); \Response::redirect_back(''); } } // Если пользователь проголосовал if (\Cookie::get('vote_' . $votes->hash)) { // Количество голосов $data['count'] = 0; foreach ($data['answers'] as $item) { $data['count'] += $item->count; } return \View::forge('widgets/votes/results', $data, FALSE)->render(); } else { return \View::forge('widgets/votes/quiz', $data, FALSE)->render(); } } else { return \View::forge('widgets/votes/empty')->render(); } }
/** * Действие уменьшение позиции команды в таблице */ public function action_decrease_team_position($table_id = null, $team_id = null) { (is_null($table_id) or is_null($team_id)) and \Response::redirect_back('admin/competitions/tables'); // Проверяем существует ли такая таблица if (!($table = \Model_Table::find($table_id))) { \Session::set_flash('error', 'Таблица не найдена.'); \Response::redirect_back('admin/competitions/tables'); } // Проверяем существует ли такая команда в ней $results = json_decode($table->results_json); foreach ($results as $key => $item) { // если такая команда найдена, то запоминаем место команды, // место которой увеличиваем и той, место которой нужно уменьшить if ($item->id == $team_id) { $key_dec = $key; foreach ($results as $k => $i) { if ($results[$k]->place == $results[$key_dec]->place - 1) { $key_inc = $k; break; } } break; } } if (!isset($key_dec)) { \Session::set_flash('error', 'Запись в таблице не найдена.'); \Response::redirect_back('admin/competitions/tables/edit/' . $table_id); } // Меняем местами команды и сохраняемся if (isset($key_inc) and isset($key_dec)) { $results[$key_inc]->place += 1; $results[$key_dec]->place -= 1; $table->results_json = json_encode($results); $table->save(); } \Session::set_flash('success', 'Действие успешно совершено.'); \Response::redirect_back('admin/competitions/tables/edit/' . $table_id); }
/** * Удаление игрока * * @param int $id */ public function action_delete($id = null) { is_null($id) and \Response::redirect_back('admin/staff'); if ($staff = \Model_Staff::find($id)) { if ($staff->image_uri) { unlink(DOCROOT . 'assets/img/staff/' . $staff->image_uri); } $staff->delete(); \Session::set_flash('success', 'Персонал удалён.'); } else { \Session::set_flash('error', 'Could not delete Ыефаа #' . $id); } \Response::redirect_back('admin/staff'); }
public function action_recover($hash = null) { /* * https://myturbotax.intuit.com/account-recovery?offering_id=Intuit.cg.myturbotax&username=daniel.rodas1&locale=en-Us&offering_env=prd&confirmation_id=910855&namespace_id=50000003 */ //email use a link // was the lostpassword form posted? if (\Input::method() == 'POST') { // do we have a posted email address? if ($email = \Input::post('email')) { // do we know this user? if ($user = \Model\Auth_User::find_by_email($email)) { // generate a recovery hash $hash = \Auth::instance()->hash_password(\Str::random()) . $user->id; // and store it in the user profile \Auth::update_user(array('lostpassword_hash' => $hash, 'lostpassword_created' => time()), $user->username); \Package::load('email'); $email = \Email::forge(); $data = array(); $hash = Crypt::encode($hash, 'R@nd0mK~Y'); $data['url'] = \Uri::create('user/password/recover/' . $hash); $data['user'] = $user; // use a view file to generate the email message $email->html_body(View::forge('user/password/email', $data)); // give it a subject $email->subject('RN | WJS Password Recovery'); // $email->subject(__('user.login.password-recovery')); // add from- and to address // $from = \Config::get('application.email-addresses.from.website'); // $from = array('email' => '*****@*****.**', 'name' => 'RN | Wall Street Journal'); // $email->from($from['email']); $email->from('*****@*****.**'); $email->to($user->email); // and off it goes (if all goes well)! try { // send the email // $email->send(); \Messages::success('Please check your email for instructions to reset your password'); // \Messages::success(__('user.login.recovery-email-send')); \Response::redirect('user/password/confirm/' . $user->id); } catch (\EmailValidationFailedException $e) { \Messages::error('INVALID EMAIL !'); \Messages::error($e->getMessage()); // \Messages::error(__('user.login.invalid-email-address')); \Response::redirect_back(); } catch (\Exception $e) { // log the error so an administrator can have a look logger(\Fuel::L_ERROR, '*** Error sending email (' . __FILE__ . '#' . __LINE__ . '): ' . $e->getMessage()); // \Messages::error($e->getMessage()); \Messages::error('ERROR SENDING EMAIL !'); // \Messages::error(__('user.login.error-sending-email')); } } } else { // inform the user and fall through to the form \Messages::error(__('user.login.error-missing-email')); } // inform the user an email is on the way (or not ;-)) \Messages::info(__('user.login.recovery-email-send')); \Response::redirect_back(); } elseif ($hash !== null) { $hash = Crypt::decode($hash, 'R@nd0mK~Y'); // get the userid from the hash $user = substr($hash, 44); // and find the user with this id if ($user = \Model\Auth_User::find_by_id($user)) { // do we have this hash for this user, and hasn't it expired yet (we allow for 24 hours response)? if (isset($user->lostpassword_hash) and $user->lostpassword_hash == $hash and time() - $user->lostpassword_created < 86400) { // invalidate the hash \Auth::update_user(array('lostpassword_hash' => null, 'lostpassword_created' => null), $user->username); // log the user in and go to the profile to change the password if (\Auth::instance()->force_login($user->id)) { // \Messages::info('LOGGED IN'); $tempPass = \Auth::instance()->reset_password($user->username); if ($tempPass) { // \Messages::info(__('user.login.password-recovery-accepted')); \Messages::info("Your temporary password is : {$tempPass} "); \Response::redirect('backend/account/index/password'); } else { return 'Something went wrong resetting password'; // something wrong with the hash // \Messages::error(__('user.login.recovery-hash-invalid')); // \Response::redirect_back(); } } } } // something wrong with the hash \Messages::error(__('user.login.recovery-hash-invalid')); \Response::redirect_back(); } else { // display the login page $this->template->content = View::forge('user/password/recover'); } }
public function action_register() { // create the registration fieldset $form = \Fieldset::forge('registerform'); // add a csrf token to prevent CSRF attacks $form->form()->add_csrf(); // and populate the form with the model properties $form->add_model('Model\\Auth_User'); // add the fullname field, it's a profile property, not a user property $form->add_after('fullname', __('login.form.fullname'), array(), array(), 'username')->add_rule('required'); // add a password confirmation field $form->add_after('confirm', __('login.form.confirm'), array('type' => 'password'), array(), 'password')->add_rule('required'); // make sure the password is required $form->field('password')->add_rule('required'); // and new users are not allowed to select the group they're in (duh!) $form->disable('group_id'); // since it's not on the form, make sure validation doesn't trip on its absence $form->field('group_id')->delete_rule('required')->delete_rule('is_numeric'); // fetch the oauth provider from the session (if present) $provider = \Session::get('auth-strategy.authentication.provider', false); // if we have provider information, create the login fieldset too if ($provider) { // disable the username, it was passed to us by the Oauth strategy $form->field('username')->set_attribute('readonly', true); // create an additional login form so we can link providers to existing accounts $login = \Fieldset::forge('loginform'); $login->form()->add_csrf(); $login->add_model('Model\\Auth_User'); // we only need username and password $login->disable('group_id')->disable('email'); // since they're not on the form, make sure validation doesn't trip on their absence $login->field('group_id')->delete_rule('required')->delete_rule('is_numeric'); $login->field('email')->delete_rule('required')->delete_rule('valid_email'); } // was the registration form posted? if (\Input::method() == 'POST') { // was the login form posted? if ($provider and \Input::post('login')) { // check the credentials. if (\Auth::instance()->login(\Input::param('username'), \Input::param('password'))) { // get the current logged-in user's id list(, $userid) = \Auth::instance()->get_user_id(); // so we can link it to the provider manually $this->link_provider($userid); // logged in, go back where we came from, // or the the user dashboard if we don't know \Response::redirect_back('dashboard'); } else { // login failed, show an error message Log::error(__('login.failure')); } } elseif (\Input::post('register')) { // validate the input $form->validation()->run(); // if validated, create the user if (!$form->validation()->error()) { try { // call Auth to create this user $created = \Auth::create_user($form->validated('username'), $form->validated('password'), $form->validated('email'), \Config::get('application.user.default_group', 1), array('fullname' => $form->validated('fullname'))); // if a user was created succesfully if ($created) { // inform the user // link new user $this->link_provider($created); // and go back to the previous page, or show the // application dashboard if we don't have any \Response::redirect_back('/'); } else { // oops, creating a new user failed? Log::error(__('login.account-creation-failed')); } } catch (\SimpleUserUpdateException $e) { // duplicate email address if ($e->getCode() == 2) { Log::error(__('login.email-already-exists')); } elseif ($e->getCode() == 3) { Log::error(__('login.username-already-exists')); } else { Log::error($e->getMessage()); } } } } // validation failed, repopulate the form from the posted data $form->repopulate(); } else { // get the auth-strategy data from the session (created by the callback) $user_hash = \Session::get('auth-strategy.user', array()); // populate the registration form with the data from the provider callback $form->populate(array('username' => \Arr::get($user_hash, 'nickname'), 'fullname' => \Arr::get($user_hash, 'name'), 'email' => \Arr::get($user_hash, 'email'))); } $form->add('register', '', array('type' => 'hidden', 'value' => '1')); $form->add('submit', '', array('type' => 'submit', 'value' => 'submit')); // pass the fieldset to the form, and display the new user registration view return \View::forge('login/registration')->set('form', $form->build(), false)->set('login', isset($login) ? $login : null, false); }
/** * Действие для удаления сезона * * @param int $id */ public function action_delete($id = null) { is_null($id) and \Response::redirect_back('admin/competitions/seasons'); if ($season = \Model_Season::find($id)) { $season->delete(); \Session::set_flash('success', 'Сезон (соревнование) удалён(о).'); } else { \Session::set_flash('error', 'Could not delete Season #' . $id); } \Response::redirect_back('admin/competitions/seasons'); }
/** * Удаление фотографии * * @param int $id */ public function action_delete($id = null) { is_null($id) and \Response::redirect_back('admin/media/photos/categories'); if ($photo = \Model_Media_Photo::find($id, array('related' => 'category'))) { // Удаляем также изображение слайда с диска unlink(DOCROOT . 'assets/img/gallery/' . $photo->image_path); unlink(DOCROOT . 'assets/img/gallery/thumbnails/' . $photo->image_path); $category_id = $photo->category->id; // Удаляем из БД $photo->delete(); \Session::set_flash('success', 'Фотография удалена.'); } else { \Session::set_flash('error', 'Could not delete Media_Photo #' . $id); } if (isset($category_id)) { \Response::redirect_back('admin/media/photos/list/index/' . $category_id); } else { \Response::redirect_back('admin/media/photos/categories'); } }
public function action_social_disconnect($provider) { // we have a UID and logged in? Just attach this authentication to a user if (\Auth::check()) { list(, $user_id) = \Auth::instance()->get_user_id(); $entry = Model_Users_Providers::query()->where('parent_id', $user_id)->and_where_open()->where('provider', $provider)->and_where_close()->get_one(); if ($entry) { $entry->delete(); // attachment went ok so we'll redirect Messages::success('Social Media Account Unlinked'); Response::redirect_back(); } else { Messages::warning('Social Mediea Account not found'); Response::redirect_back(); } } return false; }
/** * ログアウト * * @access public * @return Response */ public function action_signout() { \Auth::logout(); return Response::redirect_back('auth/signin'); }
public function action_signup() { // already logged in? if (\Auth::check()) { // yes, so go back to the page the user came from, or the // application home if no previous page can be detected \Response::redirect_back('home'); } // was the login form posted? if (\Input::method() == 'POST') { // Default Group // 3 Users // Moderators // 5 Admins // call Auth to create this user $created = \Auth::create_user(Input::Post('username'), Input::Post('password'), Input::Post('email'), \Config::get('application.user.default_group', 3), array('fullname' => Input::Post('name'))); // if a user was created succesfully if ($created) { \Auth::instance()->login(\Input::param('email'), \Input::param('password')); // and go back to the previous page, or show the // application home if we don't have any \Response::redirect_back('home'); } else { // oops, creating a new user failed? } } $this->template->content = View::forge('login/signup'); }
/** * Действие для удаления категории * * @param int $id */ public function action_delete($id = null) { is_null($id) and \Response::redirect_back('admin/media/photos/categories'); if ($category = \Model_Media_Photos_Category::find($id, array('related' => 'photos'))) { // Удаляем все фото галереи foreach ($category->photos as $item) { unlink(DOCROOT . 'assets/img/gallery/' . $item->image_path); unlink(DOCROOT . 'assets/img/gallery/thumbnails/' . $item->image_path); } $category->delete(); \Session::set_flash('success', 'Галерея удалена.'); } else { \Session::set_flash('error', 'Could not delete Media_Photos_Category #' . $id); } \Response::redirect_back('admin/media/photos/categories'); }
public function action_show($slug = false, $snippet = false) { $this->data['snippet'] = $snippet; // Get post by slug $post = $this->data['post'] = Model_Post::query()->where('slug', $slug)->get_one(); if (!$post) { \Messages::error(__('frontend.post.not-found')); \Response::redirect_back(\Router::get('homepage')); } else { // Prepare comment form fieldset $form = \Fieldset::forge('post_comment'); $form->add_model('Blog\\Model_Comment'); $form->add('submit', '', array('type' => 'submit', 'value' => __('submit'), 'class' => 'btn btn-primary')); // If submit comment if (\Input::post('submit')) { $form->validation()->run(); if (!$form->validation()->error()) { // Create and populate the comment object $comment = Model_Comment::forge(); $comment->from_array(array('username' => $form->validated('username'), 'mail' => $form->validated('mail'), 'content' => $form->validated('content'), 'post_id' => $post->id)); if ($comment->save()) { \Messages::success(__('frontend.comment.added')); \Response::redirect_back(\Router::get('show_post', array('segment' => $post->slug))); } else { \Messages::error(__('error')); } } else { // Output validation errors foreach ($form->validation()->error() as $error) { \Messages::error($error); } } } $form->repopulate(); $this->data['form'] = $form; return \Response::forge(\View::forge('frontend/post/show')->set($this->data, null, false)); } }
/** * Удаление игрока * * @param int $id */ public function action_delete($id = null) { is_null($id) and \Response::redirect_back('admin/players'); if ($player = \Model_Player::find($id)) { if ($player->image_uri) { unlink(DOCROOT . 'assets/img/players/' . $player->image_uri); } $player->delete(); \Session::set_flash('success', 'Игрок удалён.'); } else { \Session::set_flash('error', 'Could not delete Player #' . $id); } \Response::redirect_back('admin/players'); }
/** * Save everything in the entire DB again */ public function action_save_all() { try { set_time_limit(0); ini_set('memory_limit', '512M'); } catch (\Exception $e) { // Nothing! } // Get driver and get all class names $driver = \D::manager()->getConfiguration()->getMetadataDriverImpl(); $this->classNames = $driver->getAllClassNames(); foreach ($this->classNames as $class) { if (is_subclass_of($class, '\\CMF\\Model\\Base')) { $metadata = $class::metadata(); // Don't process super classes! if ($class::superclass() || $metadata->isMappedSuperclass) { continue; } $class::saveAll(); \D::manager()->clear(); sleep(1); } } \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => \Lang::get('admin.messages.save_all_success'))); \Response::redirect_back(); }