Example #1
0
 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);
 }
Example #2
0
 function show(Pilot $pilot)
 {
     $active = Flight::with('departure', 'departure.country', 'arrival', 'arrival.country')->whereVatsimId($pilot->vatsim_id)->whereIn('state', array(0, 1, 3, 4))->first();
     $flights = Flight::with('departure', 'departure.country', 'arrival', 'arrival.country')->whereVatsimId($pilot->vatsim_id)->whereState(2)->orderBy('arrival_time', 'desc')->take(15)->get();
     $flightCount = Flight::whereVatsimId($pilot->vatsim_id)->whereState(2)->count();
     $stats = new FlightStat(Flight::whereVatsimId($pilot->vatsim_id));
     if ($pilot->processing == 0) {
         Queue::push('LegacyUpdate', $pilot->vatsim_id, 'legacy');
         $pilot->processing = 2;
         $pilot->save();
     }
     if ($pilot->processing == 2) {
         Messages::success('The data for this pilot is currently being processed. In a couple of minutes, all statistics will be available.')->one();
     }
     $distances = $stats->distances($pilot->distance);
     $citypair = $stats->citypair();
     if ($flights->count() > 0) {
         $durations = $stats->durations($pilot->duration);
         extract($durations);
     }
     // Charts: popular airlines, airports and aircraft
     $airlines = $stats->topAirlines();
     $airports = $stats->topAirports();
     $aircraft = $stats->topAircraft();
     $this->javascript('assets/javascript/jquery.flot.min.js');
     $this->javascript('assets/javascript/jquery.flot.pie.min.js');
     $this->autoRender(compact('pilot', 'flights', 'active', 'distances', 'airlines', 'aircraft', 'airports', 'longest', 'shortest', 'citypair', 'hours', 'minutes'), $pilot->name);
 }
Example #3
0
 /**
  * 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);
         }
     }
 }
Example #4
0
 /**
  * 
  * @param Datasource_Section $ds
  * @param Datasource_Document $doc
  */
 public function action_post()
 {
     $id = (int) $this->request->post('id');
     $doc = $this->_get_document($id);
     Session::instance()->set('post_data', $this->request->post());
     try {
         $doc->read_values($this->request->post())->read_files($_FILES)->validate();
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (DataSource_Exception_Document $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     if ($doc->loaded()) {
         $this->section()->update_document($doc);
     } else {
         $doc = $this->section()->create_document($doc);
     }
     Messages::success(__('Document saved'));
     Session::instance()->delete('post_data');
     // save and quit or save and continue editing?
     if ($this->request->post('commit') !== NULL) {
         $this->go(Route::get('datasources')->uri(array('directory' => 'datasources', 'controller' => 'data')) . URL::query(array('ds_id' => $this->section()->id()), FALSE));
     } else {
         $this->go(Route::get('datasources')->uri(array('directory' => $this->section()->type(), 'controller' => 'document', 'action' => 'view')) . URL::query(array('ds_id' => $this->section()->id(), 'id' => $doc->id), FALSE));
     }
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 function validate()
 {
     if (!Session::has('vatsimauth')) {
         throw new AuthException('Session does not exist');
     }
     $SSO = new SSO(Config::get('vatsim.base'), Config::get('vatsim.key'), Config::get('vatsim.secret'), Config::get('vatsim.method'), Config::get('vatsim.cert'));
     $session = Session::get('vatsimauth');
     if (Input::get('oauth_token') !== $session['key']) {
         throw new AuthException('Returned token does not match');
         return;
     }
     if (!Input::has('oauth_verifier')) {
         throw new AuthException('No verification code provided');
     }
     $user = $SSO->checkLogin($session['key'], $session['secret'], Input::get('oauth_verifier'));
     if ($user) {
         Session::forget('vatsimauth');
         $authUser = User::find($user->user->id);
         if (is_null($authUser)) {
             $authUser = new User();
             $authUser->vatsim_id = $user->user->id;
             $authUser->name = trim($user->user->name_first . ' ' . $user->user->name_last);
         }
         $authUser->last_login = Carbon::now();
         $authUser->save();
         Auth::login($authUser);
         Messages::success('Welcome on board, <strong>' . $authUser->name . '</strong>!');
         return Redirect::intended('/');
     } else {
         $error = $SSO->error();
         throw new AuthException($error['message']);
     }
 }
Example #7
0
 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.');
     }
 }
Example #8
0
 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'));
 }
Example #9
0
 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'));
 }
Example #10
0
 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();
 }
Example #11
0
 public function confirm()
 {
     $new_password = Text::random();
     $this->_model->user->change_email($new_password);
     try {
         Email_Type::get('user_new_password')->send(array('username' => $this->_model->user->username, 'email' => $this->_model->user->email, 'password' => $new_password));
         Messages::success(__('An email has been send with your new password!'));
         $this->_model->delete();
         return TRUE;
     } catch (Kohana_Exception $e) {
         throw new Reflink_Exception('Email :email not send', array(':email' => $this->_model->user->email));
     }
 }
Example #12
0
 function update(Airport $airport)
 {
     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();
     });
     Messages::success('Thank you for your submission. We will be evaluating your feedback soon.');
     return Redirect::route('airport.show', $airport->icao);
 }
Example #13
0
 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');
     }
 }
Example #14
0
 public function confirm()
 {
     try {
         $role = ORM::factory('role', array('name' => 'login'));
         $this->_model->user->add('roles', $role);
         Email_Type::get('user_registered')->send(array('username' => $this->_model->user->username, 'email' => $this->_model->user->email));
         Messages::success(__('Thank you for registration!'));
         $this->_model->delete();
         return TRUE;
     } catch (Kohana_Exception $e) {
         throw new Reflink_Exception('Something went wrong');
     }
 }
Example #15
0
 /**
  * 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);
 }
Example #16
0
     $plugin = Plugins::get_registered($plugin_id);
     if ($this->request->method() == Request::POST) {
         return $this->_settings_save($plugin);
     }
     $this->template->content = View::factory('plugins/settings', array('content' => View::factory($plugin->id() . '/settings', array('plugin' => $plugin))));
     $this->set_title(__('Plugin :title settings', array(':title' => $plugin->title())));
 }
 protected function _settings_save($plugin)
 {
     $data = Arr::get($this->request->post(), 'setting', array());
     try {
         $plugin->set_settings($data)->validate()->save_settings();
         Kohana::$log->add(Log::INFO, ':user change settings for plugin :name ', array(':name' => $plugin->title()))->write();
         Messages::success(__('Plugin settings saved!'));
     } catch (Validation_Exception $e) {
         Messages::errors($e->errors('validation'));
         $this->go_back();
     }
 function show(Pilot $pilot)
 {
     $actives = ATC::with('airport', 'airport.country')->whereVatsimId($pilot->vatsim_id)->whereNull('end')->where('facility_id', '!=', 99)->get();
     $duties = ATC::with('airport', 'airport.country')->whereVatsimId($pilot->vatsim_id)->whereNotNull('end')->where('facility_id', '!=', 99)->orderBy('end', 'desc')->take(15)->get();
     if ($pilot->processing == 0) {
         Queue::push('LegacyUpdate', $pilot->vatsim_id, 'legacy');
         $pilot->processing = 2;
         $pilot->save();
     }
     if ($pilot->processing == 2) {
         Messages::success('The data for this controller is currently being processed. In a couple of minutes, all statistics will be available.')->one();
     }
     $stat = new ControllerStat(ATC::whereVatsimId($pilot->vatsim_id)->where('facility_id', '!=', 99));
     extract($stat->durations($pilot->duration_atc));
     $airports = $stat->topAirports();
     $facilities = $stat->topFacilities();
     $this->javascript('assets/javascript/jquery.flot.min.js');
     $this->javascript('assets/javascript/jquery.flot.pie.min.js');
     $this->autoRender(compact('pilot', 'duties', 'actives', 'airport', 'airports', 'longest', 'hours', 'minutes', 'facilities'), $pilot->name);
 }
Example #18
0
 /**
  * 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);
 }
Example #19
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $id = $this->request->param('id');
     // find the user to delete
     $user = ORM::factory('user', $id);
     if (!$user->loaded()) {
         Messages::errors(__('User not found!'));
         $this->go();
     }
     if ($user->delete()) {
         Messages::success(__('User has been deleted!'));
     } else {
         Messages::errors(__('Something went wrong!'));
     }
     $this->go();
 }
Example #20
0
 /**
  * The module index
  *
  * @return  Response
  */
 public function action_index()
 {
     \Sentry::logout();
     \Messages::success('You have successfully logged out');
     \Response::redirect('admin/login');
 }
Example #21
0
 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');
     }
 }
Example #22
0
 /**
  * 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.');
     }
 }
Example #23
0
 /**
  * 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());
 }
Example #24
0
 public function action_sort_attr_in_group($type = false)
 {
     //if(!$type) return false;
     var_dump($items);
     $items = \Input::post('sort');
     var_dump($items);
     exit;
     if (is_array($items)) {
         foreach ($items as $item) {
             list($item, $old_item) = explode('_', $item);
             if (is_numeric($item)) {
                 $sort[] = $item;
             }
             if (is_numeric($old_item)) {
                 $old_sort[] = $old_item;
             }
         }
         if (is_array($sort)) {
             // Get starting point for sort
             $start = min($old_sort);
             $start = $start > 0 ? --$start : $start;
             $model = Model_Attribute::factory(ucfirst($type));
             foreach ($sort as $key => $id) {
                 $item = $model::find_one_by_id($id);
                 $item->set(array('sort' => ++$start));
                 $item->save();
             }
             \Messages::success('Items successfully reordered.');
             echo \Messages::display('left', false);
         }
     }
 }
Example #25
0
 /**
  * Delete content image
  * 
  * @param $image_id		= Image ID
  * @param $content_id	= Content ID
  */
 public function action_delete_image($image_id = false, $content_id = false)
 {
     // Accordion from home page?
     if ($content_id == 1) {
         \Config::load('page::accordion_banner', 'details', true, true);
     }
     if ($image_id && $content_id) {
         $images = Model_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];
                 // 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_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_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());
 }
Example #26
0
 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;
 }
Example #27
0
 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());
 }
Example #28
0
 public function action_create()
 {
     \View::set_global('title', 'Add New User');
     if (\Input::post()) {
         // Validate input parameters
         $val = \Validation::forge('admin_details_validation');
         $val->add('first_name', 'First Name')->add_rule('required')->add_rule('min_length', 2)->add_rule('max_length', 255);
         $val->add('last_name', 'Last Name')->add_rule('required')->add_rule('min_length', 2)->add_rule('max_length', 255);
         $val->add('email', 'Email')->add_rule('required')->add_rule('valid_email');
         $val->add('password', 'Password')->add_rule('min_length', 8);
         $val->add('confirm_password', 'Confirm Password')->add_rule('required_with', 'password')->add_rule('match_field', 'password');
         $val->add('username', 'Username')->add_rule('required')->add_rule('unique', array('users', 'username', $id));
         if ($val->run()) {
             // Get Input parameters
             $post_data = \Input::post();
             try {
                 $fields = array('username' => $post_data['username'], 'email' => $post_data['email'], 'password' => $post_data['password'], 'metadata' => array('first_name' => $post_data['first_name'], 'last_name' => $post_data['last_name']));
                 $user_group = $post_data['user_group'];
                 if (empty($post_data['password'])) {
                     unset($fields['password']);
                 }
                 $item = new \Sentry_User((int) $id);
                 $create = $item->create($fields);
                 $user = \Sentry::user($create);
                 // $item->remove_from_group((int)$fields['user_group']);
                 // $item->add_to_group((int)$fields['user_group']);
                 if ($create and $user->add_to_group($user_group)) {
                     // $user_groups = $item->groups();
                     // if(!empty($user_groups))
                     // {
                     //     // Remove user from all other groups...
                     //     foreach($user_groups as $value)
                     //     {
                     //         $item->remove_from_group((int)$value['id']);
                     //     }
                     // }
                     // $item = new \Sentry_User((int)$id);
                     // // ...and add it to selected one
                     // $item->add_to_group((int)$user_group);
                     \Messages::success('User Details Successfully Created.');
                     \Response::redirect(\Uri::admin('current'));
                 } else {
                     \Messages::error('There was an error while trying to update User details.');
                 }
             } catch (Sentry\SentryException $e) {
                 \Messages::error($e->get_message());
             }
         } else {
             if ($val->error() != array()) {
                 // Show validation errors
                 \Messages::error('<strong>There was an error while trying to update User details</strong>');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
     \Theme::instance()->set_partial('content', $this->view_dir . 'create');
 }
Example #29
0
 /**
  * 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);
         }
     }
 }
Example #30
0
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $snippet_name = $this->request->param('id');
     $snippet = new Model_File_Snippet($snippet_name);
     // find the user to delete
     if ($snippet->is_exists()) {
         if ($snippet->delete()) {
             Kohana::$log->add(Log::INFO, 'Snippet :name has been deleted by :user', array(':name' => $snippet_name))->write();
             Messages::success(__('Snippet has been deleted!'));
             Observer::notify('snippet_after_delete', $snippet_name);
         } else {
             Messages::errors(__('Something went wrong!'));
         }
     } else {
         Messages::errors(__('Snippet not found!'));
     }
     $this->go();
 }