/** * Function for easy update a ORM object * * @param ORM $object ORM object to update * @param array $messages Array of custom messages */ public function update(ORM $object, array $messages = array()) { // Check if is a valid object if (!$object->loaded()) { Messages::warning(isset($messages['warning']) ? $messages['warning'] : 'El elemento que intentas modificar no existe o fue eliminado.'); $this->go(); } // Only if Request is POST if ($this->request->method() == Request::POST) { // Catch ORM_Validation try { // Set object values and update $object->values($this->request->post())->update(); // If object is saved.... if ($object->saved()) { // Success message & redirect Messages::success(isset($messages['success']) ? $messages['success'] : 'El elemento fue modificado correctamente.'); $this->go(); } } catch (ORM_Validation_Exception $e) { // Error message if (isset($messages['error'])) { Messages::error($messages['error']); } // Validation messages Messages::validation($e); } } }
public function on_page_load() { $email_ctx_id = $this->get('email_id_ctx', 'email'); $email = $this->_ctx->get($email_ctx_id); $referrer_page = Request::current()->referrer(); $next_page = $this->get('next_url', Request::current()->referrer()); if (!Valid::email($email)) { Messages::errors(__('Use a valid e-mail address.')); HTTP::redirect($referrer_page); } $user = ORM::factory('user', array('email' => $email)); if (!$user->loaded()) { Messages::errors(__('No user found!')); HTTP::redirect($referrer_page); } $reflink = ORM::factory('user_reflink')->generate($user, 'forgot', array('next_url' => URL::site($this->next_url, TRUE))); if (!$reflink) { Messages::errors(__('Reflink generate error')); HTTP::redirect($referrer_page); } Observer::notify('admin_login_forgot_before', $user); try { Email_Type::get('user_request_password')->send(array('username' => $user->username, 'email' => $user->email, 'reflink' => Route::url('reflink', array('code' => $reflink)), 'code' => $reflink)); Messages::success(__('Email with reflink send to address set in your profile')); } catch (Exception $e) { Messages::error(__('Something went wrong')); } HTTP::redirect($next_page); }
public function action_subscription($id = null) { is_null($id) and Response::redirect(''); if (!($user = Model_User::find($id))) { Messages::error('Could not find user #' . $id); Response::redirect(''); } $val = \Model_User::validate_subscription('edit'); if ($val->run()) { $user->delivery_address = Input::post('delivery_address'); $user->delivery_address_2 = Input::post('delivery_address_2'); $user->delivery_city = Input::post('delivery_city'); $user->delivery_state = Input::post('delivery_state'); $user->delivery_zip_code = Input::post('delivery_zip_code'); if ($user->save()) { Messages::success('Updated user #' . $id); } else { Messages::error('Could not update user #' . $id); } \Response::redirect('backend/account/index/subscription'); } else { if (Input::method() == 'POST') { $user->delivery_address = $val->validated('delivery_address'); $user->delivery_address_2 = $val->validated('delivery_address_2'); $user->delivery_city = $val->validated('delivery_city'); $user->delivery_state = $val->validated('delivery_state'); Session::set_flash('error', $val->error()); } $data['user'] = $this->_user; $this->template->content = View::forge('account/subscription/edit', $data); } $this->template->title = "Delivery Settings"; $data['user'] = $this->_user; $this->template->content = View::forge('account/subscription/edit', $data); }
function store() { $rules = array('icao' => 'alpha|required', 'name' => 'required', 'radio' => '', 'website' => 'url'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { Messages::error($validator->messages()->all()); return Redirect::back()->withInput(); } if (is_null($airline = Airline::whereIcao(Input::get('icao'))->whereNew(true)->first())) { $airline = new Airline(); $airline->icao = Input::get('icao'); $airline->name = Input::get('name'); $airline->new = true; $airline->save(); } Diff::compare($airline, Input::all(), function ($key, $value, $model) { $change = new AirlineChange(); $change->airline_id = $model->id; $change->user_id = Auth::id(); $change->key = $key; $change->value = $value; $change->save(); }, ['name', 'radio', 'website']); Messages::success('Thank you for your submission. We will check whether all information is correct and soon this airline might be available.'); return Redirect::back(); }
/** * Добавление нового пользователя */ public function action_create() { if (\Input::method() == 'POST') { $val = \Model_User::validate('create'); if ($val->run()) { try { $created = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), \Config::get('application.user.default_group', 100)); if ($created) { \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 существует')); } elseif ($e->getCode() == 3) { \Session::set_flash('error', e('Логин существует')); } else { \Messages::error($e->getMessage()); } } } else { \Session::set_flash('error', $val->error()); } } $this->template->title = 'Пользователи'; $this->template->content = \View::forge('users/create'); }
function store() { $rules = array('icao' => 'alpha_num|required', 'iata' => 'alpha_num', 'name' => 'required', 'city' => 'required', 'lat' => 'required|numeric', 'lon' => 'required|numeric', 'elevation' => 'required|numeric', 'country_id' => 'required|exists:countries,id', 'website' => 'url'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { Messages::error($validator->messages()->all()); return Redirect::back()->withInput(); } if (is_null($airport = Airport::whereIcao(Input::get('icao'))->whereNew(true)->first())) { $airport = new Airport(); $airport->icao = Input::get('icao'); $airport->name = Input::get('name'); $airport->new = true; $airport->save(); } Diff::compare($airport, Input::all(), function ($key, $value, $model) { $change = new AirportChange(); $change->airport_id = $model->id; $change->user_id = Auth::id(); $change->key = $key; $change->value = $value; $change->save(); }, ['name', 'iata', 'city', 'country_id', 'lat', 'lon', 'elevation', 'website']); Messages::success('Thank you for your submission. We will check whether all information is correct and soon this airport might be available.'); return Redirect::back(); }
/** * The index action * * @access public * @return void */ public function action_index() { $settings = \Config::load('autoresponder.db'); // $autoResponder = Model_Setting::find(array('where' => array(array('meta_key', '=', 'auto-responders')))); if (\Input::post()) { $input = \Input::post(); if (!\Input::is_ajax()) { $val = Model_Setting::validate('create'); if (!$val->run()) { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } else { try { \Config::save('autoresponder.db', array('logo_url' => $input['logo_url'], 'company_name' => $input['company_name'], 'address' => $input['address'], 'website' => $input['website'], 'phone' => $input['phone'], 'email_address' => $input['email_address'], 'sender_email_address' => $input['sender_email_address'], 'contact_us_email_address' => $input['contact_us_email_address'], 'instagram_account_name' => $input['instagram_account_name'], 'facebook_account_name' => $input['facebook_account_name'])); // $setting->save(); \Messages::success('Settings successfully created.'); \Response::redirect('admin/settings'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings.</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } } } \View::set_global('title', 'Settings'); \Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false); }
/** * @param none * @throws none * @returns void */ public function before() { $result = array(); // users need to be logged in to access this controller if (!\Sentry::check()) { $result = array('message' => 'You need to be logged in to access that page.', 'url' => '/admin/login'); // Don't show this message if url is just 'admin' if (\Uri::string() == 'admin/admin/index') { unset($result['message']); } \Session::set('redirect_to', \Uri::admin('current')); } else { if (!\Sentry::user()->is_admin()) { $result = array('message' => 'Access denied. You need to be a member of staff to access that page.', 'url' => '/admin/login'); \Session::set('redirect_to', \Uri::admin('current')); } } if (!empty($result)) { if (\Input::is_ajax()) { \Messages::error('You need to be logged in to complete this action.'); echo \Messages::display('left', false); exit; } else { if (isset($result['message'])) { \Messages::warning($result['message']); } \Response::redirect($result['url']); } } parent::before(); }
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.'); } }
/** * @param none * @throws none * @returns void */ public function before() { // users need to be logged in to access this controller //if ( ! \Sentry::check()) if ($this->check_logged_type() != 'user') { \Messages::error('Access denied. Please login first'); \Response::redirect('/user/login'); } parent::before(); }
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_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')); }
function processing() { $user = Auth::user(); if ($user->processing == 2) { $user->processing = 0; $user->save(); Messages::success('The processing has been reset. Visit your pilot or controller profile to start processing again'); return Redirect::route('user.edit'); } else { Messages::error('You are not allowed to perform this action.'); return Redirect::route('user.edit'); } }
/** * The index action * * @access public * @return void */ public function action_index() { $settings = \Config::load('backup.db'); if (\Input::post()) { $input = \Input::post(); if (!\Input::is_ajax()) { $val = Model_Backup::validate('create'); if (!$val->run()) { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } else { try { \Config::save('backup.db', array('enable' => $input['enable'], 'email' => $input['email'], 'period' => $input['period'])); //save cronjob $output = shell_exec('crontab -l'); $db_backup_cron_file = "/tmp/db_backup_cron.txt"; if ($input['enable']) { if ($input['period'] == 'daily') { $daily_backup_command = '0 0 * * * wget ' . \Uri::create('backup/execute'); file_put_contents($db_backup_cron_file, $daily_backup_command . PHP_EOL); } else { if ($input['period'] == 'weekly') { $weekly_backup_command = '0 0 * * 0 wget ' . \Uri::create('backup/execute'); file_put_contents($db_backup_cron_file, $weekly_backup_command . PHP_EOL); } } } else { file_put_contents($db_backup_cron_file, "" . PHP_EOL); } exec("crontab {$db_backup_cron_file}"); \Messages::success('Settings successfully created.'); \Response::redirect('admin/backup'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings.</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } } } \View::set_global('title', 'Backup'); \Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false); }
/** * Login user */ public function action_login() { if ($this->request->method() == Request::POST) { $login = $this->request->post(); if (Auth::instance()->login($login['email'], $login['password'], isset($login['remember']))) { if ($next_url = Flash::get('redirect')) { $this->go($next_url); } $this->go_backend(); } Messages::error('Por favor, comprueba tus datos de acceso e inténtalo de nuevo.'); } Document::title('Ingresar'); }
/** * 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)); } }
/** * The module index * * @return Response */ public function action_index() { \View::set_global('full_page', true); $this->data['title'] = 'Login'; // create the form fieldset, do not add an {open}, a closing ul and a {close}, we have a custom form layout! $fieldset = \Fieldset::forge('login'); $fieldset->add('username', 'Username', array('maxlength' => 50), array(array('required')))->add('password', 'Password', array('type' => 'password', 'maxlength' => 255), array(array('required'), array('min_length', 8))); // was the login form posted? if (\Input::post()) { // run the form validation if (!$fieldset->validation()->run()) { // set any error messages we need to display foreach ($fieldset->validation()->error() as $error) { \Messages::error($error); } } else { try { if (\Sentry::user(\Input::param('username'))->is_admin()) { // check the credentials. $valid_login = \Sentry::login(\Input::param('username'), \Input::param('password'), true); if ($valid_login) { \Messages::success('You have logged in successfully'); if (\Session::get('redirect_to')) { $redirect = \Session::get('redirect_to'); \Session::delete('redirect_to'); } \Response::redirect(isset($redirect) ? $redirect : 'admin'); } else { \Messages::error('Username and/or password is incorrect'); } } else { \Messages::error('Username and/or password is incorrect'); } } catch (\SentryAuthException $e) { $errors = $e->getMessage(); \Messages::error($errors); } } } \Theme::instance()->set_partial('content', 'views/login')->set('fieldset', $fieldset, false); }
function show(Flight $flight) { if ($flight->missing) { Messages::error('This flight has been missing for ' . Carbon::now()->diffInMinutes($flight->updated_at) . ' minutes. It will be deleted if it has been missing for 1 hour.')->one(); } if ($flight->pilot->getOriginal('updated_at') == '0000-00-00 00:00:00') { Queue::push('LegacyUpdate', $flight->pilot->vatsim_id, 'legacy'); $flight->pilot->processing = 2; $flight->pilot->save(); } $flightplan = new FlightPlan($flight->route, $flight->departure->lat, $flight->departure->lon, $flight->departure_id, $flight->arrival_id); if (empty($flight->route_parsed)) { $flight->route_parsed = $flightplan->toString(); $flight->save(); } $flight->miles = $flight->distance * 0.54; $this->javascript('assets/javascript/jquery.flot.min.js'); $this->javascript('assets/javascript/jquery.flot.time.min.js'); $this->stylesheet('assets/stylesheets/flightplan.css'); $this->autoRender(compact('flight', 'flightplan'), $flight->callsign); }
public function send() { $email = \Email::forge(); $order = $this->emailData['order']; $email->to($order->shipping_email, ucwords($order->shipping_first_name . ' ' . $order->shipping_last_name)); if ($this->emailData['bcc']) { $email->bcc($this->emailData['bcc']); } $email->subject($this->emailData['site_title'] . ' - Your Order'); $autoresponder_body = \Theme::instance()->view('views/_email/order_confirmation')->set('emailData', $this->emailData, false); $emailHtml = \Theme::instance()->view('views/_email/autoresponder')->set('autoresponder_body', $autoresponder_body); $email->html_body($emailHtml); try { $email->send(); //\Messages::success('A copy of your request has been sent to ' . $this->emailData['order']['billing_email'] . ' for your own reference.'); } catch (\EmailValidationFailedException $e) { \Messages::error('Error while sending email.'); } catch (\EmailSendingFailedException $e) { \Messages::error('Error while sending email.'); } }
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(__('user.login.already-logged-in')); \Response::redirect_back(\Router::get('admin')); } // was the login form posted? if (\Input::method() == 'POST') { // check the credentials. if (\Auth::instance()->login(\Input::param('username'), \Input::param('password'))) { // 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(\Router::get('admin')); } else { // login failed, show an error message \Messages::error(__('user.login.failure')); } } // display the login page $this->theme->set_partial('content', 'user/login'); }
/** * Change user password * * @param unknown_type $email * @param unknown_type $hash */ public function action_reset_password($email = false, $hash = false) { if ($email && $hash) { //Keep existing messages \Messages::instance()->shutdown(); try { if (\Sentry::reset_password_confirm($email, $hash)) { if (\Input::post('new_password') && \Input::post('confirm_new_password')) { if (\Sentry::reset_password_save($email, \Input::post('new_password'))) { \Messages::success('Password successfully changed. Please login and start using your account.'); \Response::redirect(\Uri::front_create('user/login')); } else { \Messages::error('Password was not save.'); \Theme::instance()->set_partial('content', $this->view_dir . 'reset_password'); } } else { \Theme::instance()->set_partial('content', $this->view_dir . 'reset_password'); } } else { \Messages::error('Wrong reset code. Please check your email and try again.'); \Response::redirect(\Uri::front_create('user/login')); } } catch (\Sentry\SentryException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying activate user</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } } }
public function action_delete($id = false) { if (is_numeric($id)) { // Get news item to edit if ($item = Model_Team::find_one_by_id($id)) { // Delete other content data like images, files, etc. if (!empty($item->images)) { foreach ($item->images as $image) { $this->delete_image($image->image); $image->delete(); } } // if(!empty($item->files)) // { // foreach($item->files as $file) // { // $this->delete_file($file->file); // $file->delete(); // } // } // if(!empty($item->videos)) // { // foreach($item->videos as $video) // { // $this->delete_image($video->thumbnail, 'video'); // $video->delete(); // } // } // if(!empty($item->accordions)) // { // foreach($item->accordions as $accordion) // { // \Request::forge('admin/team/accordion/delete/'.$accordion->id)->execute(); // } // } try { $item->seo->delete(); $item->delete(); \Messages::success('Member successfully deleted.'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to delete team</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } } \Response::redirect(\Input::referrer()); }
$master_template = 'master'; $main_template = 'main'; $page_template = 'pages/front'; // path to view AND controller $page_title = null; // set this in controller $messages = new Messages(); $data = []; $images = new Images($config['images_dir'], $config['images_url']); $localization = new Localization($home_dir . 'lang/'); $db = new mysqli($config['db_host'], $config['db_login'], $config['db_password'], $config['db_name']); $db->set_charset('utf8'); if ($db->connect_errno > 0) { $page_template = 'pages/error'; if ($config['debug_mode']) { $messages->error('Database connection error:' . $db->error_message); } } else { $globals = new SiteGlobals($db); $auth = new Authentication($db); $path = ['']; $raw_path = ''; if (isset($_GET['path'])) { $path = explode('/', trimSlashes(strtolower($_GET['path']))); $raw_path = implode('/', $path); } // select page to display switch ($path[0]) { // ADMIN SECTION case 'admin': $main_template = 'admin';
/** * Send email * * @access public * @param object $order = Order object * @param array of objects $products = Products from order * @param string $type = Type of email to send * @return void */ public function send_email($order = false, $products = false, $type = 'job') { // Send email to user \Package::load('email'); // Load email addresses from config (these will be bcc receivers) \Config::load('auto_response_emails', 'autoresponders'); $bcc = \Config::get('autoresponders.order_emails', false); if (!$bcc) { $bcc = \Config::get('autoresponders.default_emails', false); } $email_data = array('order' => $order, 'products' => $products, 'site_title' => \Config::get('site_title')); $email = \Email::forge(); $email->to($order['email'], ucwords($order['first_name'] . ' ' . $order['last_name'])); if ($bcc) { $email->bcc($bcc); } $email->subject($email_data['site_title'] . ' - Your Order'); // Set correct email view $email_view = $type == 'credits' ? 'order_credits' : 'order'; $email_html = \Theme::instance()->view('views/_email/' . $email_view)->set('email_data', $email_data, false); $email->html_body($email_html); try { $email->send(); \Messages::success('A copy of your request has been sent to ' . $order['email'] . ' for your own reference.'); } catch (\EmailValidationFailedException $e) { \Messages::error('Error while sending email.'); } catch (\EmailSendingFailedException $e) { \Messages::error('Error while sending email.'); } }
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'); } }
/** * Delete content image * * @param $content_id = Content ID */ public function action_delete_image($content_id = null) { try { if ($application = Model_Application::find_one_by_id($content_id)) { if (!empty($application->hotspot) && !empty($application->hotspot->images)) { foreach ($application->hotspot->images as $image) { $this->delete_image($image->image); $image->delete(); } } $this->delete_image($application->hotspot_image); $application->hotspot_alt_text = null; $application->hotspot_image = null; if ($application->save()) { \Messages::success('Hotspot image was successfully deleted.'); } else { \Messages::error('There was an error while trying to delete hotspot image.'); } } } catch (\Database_Exception $e) { // show validation errors \Messages::error('There was an error while trying to delete hotspot image.'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } \Response::redirect(\Input::referrer()); }
public function action_delete($id = false) { if (is_numeric($id)) { // Get news item to edit if ($item = Model_Attribute_Group::find_one_by_id($id)) { // Delete item try { // Delete relation to attributes $attributes = Model_Attribute_To_Groups::find_by_group_id($item->id); if (!is_null($attributes)) { foreach ($attributes as $attribute) { $attribute->delete(); } } $item->delete(); \Messages::success('Attribute group successfully deleted.'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to delete attribute group</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } } \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/group/list'))); }
public function action_delete($id = false) { if (is_numeric($id)) { // Get news item to edit if ($item = Model_Attribute::find_one_by_id($id)) { // Delete item try { // Delete attribute options if (!empty($item->options)) { foreach ($item->options as $option) { \Request::forge('admin/attribute/option/delete/' . $option->id)->execute()->response(); } } $item->delete(); \Messages::success('Attribute successfully deleted.'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to delete attribute</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } } \Response::redirect(\Input::referrer()); }
public function add_to_cart($return = 'return') { if (!\Input::post()) { return false; } // check for a valid CSRF token // if (!\Security::check_token()) // { // \Messages::error('CSRF attack or expired CSRF token.'); // return false; // } $post = \Input::post(); $product_id = $post['product_id']; if (!($product = Model_Product::find_one_by_id($product_id))) { return; } $selected_attributes = array(); $selected_attributes_json = null; if (isset($post['select']) && !empty($post['select'])) { ksort($post['select']); $selected_attributes_json = json_encode($post['select']); } $product_data = Model_Product::product_data($product, $selected_attributes_json, \Input::post('select'), \Input::post('attributeid')); if (!empty($product_data)) { $attr_obj = null; if (!empty($product_data['current_attributes'])) { $attr_obj = $product_data['current_attributes'][0]->product_attribute; } $item = array('title' => $product->title, 'id' => $product->id, 'product_attribute_id' => $attr_obj ? $attr_obj->id : null, 'quantity' => $post['quantity'], 'attributes' => $attr_obj ? $attr_obj->attributes : null, 'product_code' => $product_data['code'], 'unique_id' => uniqid()); if ($product_data['sale']) { $item += array('price' => $product_data['sale'], 'price_type' => 'sale_price'); } else { $item += array('price' => $product_data['retail_price'], 'price_type' => 'retail_price'); } $stock_options = \Config::load('stock-option.db'); if ($stock_options['allow_buy_out_of_stock'] != 1 && $product_data['stock_quantity'] < 1) { \Messages::error('Product is Out of Stock.'); echo \Messages::display(); return; } $uid = \Cart::generateUID($item); if (\Cart::exists($uid)) { $cart_item = \Cart::item($uid); $quantity = $cart_item->get('quantity'); if ($product_data['stock_quantity'] > 0 && $product_data['stock_quantity'] <= $quantity) { \Messages::error($product->title . ' has not enough stock to fulfill your request.'); echo \Messages::display(); return; } } if ($return == 'return') { \Cart::add($item); // Always return cart item id $uid = \Cart::generateUID($item); if (\Cart::exists($uid)) { return $uid; } return false; } else { $uid = \Cart::generateUID($item); if (\Cart::exists($uid)) { echo $uid; } echo ''; exit; } \Messages::success('Product successfully added to cart.'); echo \Messages::display(); } return false; }
/** * Delete content image * * @param $image_id = Image ID * @param $content_id = Content ID */ public function action_delete_image($image_id = false, $content_id = false) { if ($image_id && $content_id) { $images = Model_Attribute_Image::find(array('where' => array('content_id' => $content_id), 'order_by' => array('sort' => 'asc')), 'id'); if ($images) { if (isset($images[$image_id])) { $image = $images[$image_id]; // Check if image used for more than one combination $image2 = Model_Attribute_Image::find(array('where' => array('image' => $image->image)), 'id'); if ($image2 && count($image2) > 1) { // Reset sort fields \DB::update(Model_Attribute_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute(); $image->delete(); \Messages::success('Image was successfully deleted.'); \Response::redirect(\Input::referrer()); } // If there is only one image and image is required if (count($images) == 1) { if (\Config::get('details.image.required', false)) { \Messages::error('You can\'t delete all images. Please add new image in order to delete this one.'); } else { // Reset sort fields \DB::update(Model_Attribute_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute(); // Delete image $this->delete_image($image->image); $image->delete(); \Messages::success('Image was successfully deleted.'); } } else { if ($image->cover == 1) { \Messages::error('You can\'t delete cover image. Set different image as cover in order to delete this one.'); } else { // Reset sort fields \DB::update(Model_Attribute_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute(); // Delete image $this->delete_image($image->image); $image->delete(); \Messages::success('Image was successfully deleted.'); } } } else { \Messages::error('Image you are trying to delete don\'t exists. Check your url and try again.'); } } else { \Messages::error('Content Image you are trying to delete don\'t exists. Check your url and try again.'); } } \Response::redirect(\Input::referrer()); }