コード例 #1
0
ファイル: user.php プロジェクト: kotsios5/openclassifieds2
 /**
  * Deletes a single record while ignoring relationships.
  *
  * @chainable
  * @throws Kohana_Exception
  * @return ORM
  */
 public function delete()
 {
     if (!$this->_loaded) {
         throw new Kohana_Exception('Cannot delete :model model because it is not loaded.', array(':model' => $this->_object_name));
     }
     //remove image
     $this->delete_image();
     //remove ads, will remove reviews, images etc...
     $ads = new Model_Ad();
     $ads = $ads->where('id_user', '=', $this->id_user)->find_all();
     foreach ($ads as $ad) {
         $ad->delete();
     }
     //bye profile pic
     $this->delete_image();
     //delete favorites
     DB::delete('favorites')->where('id_user', '=', $this->id_user)->execute();
     //delete reviews
     DB::delete('reviews')->where('id_user', '=', $this->id_user)->execute();
     //delete orders
     DB::delete('orders')->where('id_user', '=', $this->id_user)->execute();
     //delete subscribtions
     DB::delete('subscribers')->where('id_user', '=', $this->id_user)->execute();
     //delete posts
     DB::delete('posts')->where('id_user', '=', $this->id_user)->execute();
     //delete messages
     DB::delete('messages')->where('id_user_from', '=', $this->id_user)->or_where('id_user_to', '=', $this->id_user)->execute();
     //unsusbcribe from elasticemail
     if (Core::config('email.elastic_listname') != '') {
         ElasticEmail::unsubscribe(Core::config('email.elastic_listname'), $this->email);
     }
     parent::delete();
 }
コード例 #2
0
ファイル: profile.php プロジェクト: kotsios5/openclassifieds2
 public function action_edit()
 {
     $this->template->scripts['footer'] = array('js/oc-panel/edit_profile.js');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit profile')));
     // $this->template->title = $user->name;
     //$this->template->meta_description = $user->name;//@todo phpseo
     $user = Auth::instance()->get_user();
     $this->template->bind('content', $content);
     $this->template->content = View::factory('oc-panel/profile/edit', array('user' => $user, 'custom_fields' => Model_UserField::get_all()));
     if ($this->request->post()) {
         //change elastic email status, he was subscribed but not anymore
         if (Core::config('email.elastic_listname') != '' and $user->subscriber == 1 and core::post('subscriber', 0) == 0) {
             ElasticEmail::unsubscribe(Core::config('email.elastic_listname'), $user->email);
         } elseif (Core::config('email.elastic_listname') != '' and $user->subscriber == 0 and core::post('subscriber', 0) == 1) {
             ElasticEmail::subscribe(Core::config('email.elastic_listname'), $user->email, $user->name);
         }
         $user->name = core::post('name');
         $user->description = core::post('description');
         $user->email = core::post('email');
         $user->subscriber = core::post('subscriber', 0);
         //$user->seoname = $user->gen_seo_title(core::post('name'));
         $user->last_modified = Date::unix2mysql();
         //modify custom fields
         foreach ($this->request->post() as $custom_field => $value) {
             if (strpos($custom_field, 'cf_') !== FALSE) {
                 $user->{$custom_field} = $value;
             }
         }
         if (core::post('cf_vatnumber') and core::post('cf_vatcountry')) {
             if (!euvat::verify_vies(core::post('cf_vatnumber'), core::post('cf_vatcountry'))) {
                 Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match'));
                 $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
             }
         }
         try {
             $user->save();
             Alert::set(Alert::SUCCESS, __('You have successfully changed your data'));
         } catch (Exception $e) {
             //throw 500
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
     }
 }
コード例 #3
0
ファイル: auth.php プロジェクト: kotsios5/openclassifieds2
 public function action_unsubscribe()
 {
     $email_encoded = $this->request->param('id');
     $user = new Model_User();
     //mail encoded
     if ($email_encoded !== NULL) {
         //decode emails
         $email_encoded = Base64::fix_from_url($email_encoded);
         $encrypt = new Encrypt(Core::config('auth.hash_key'), MCRYPT_MODE_NOFB, MCRYPT_RIJNDAEL_128);
         $email = $encrypt->decode($email_encoded);
         if (Valid::email($email)) {
             //check we have this email in the DB
             $user = new Model_User();
             $user = $user->where('email', '=', $email)->limit(1)->find();
         } else {
             Alert::set(Alert::INFO, __('Not valid email.'));
         }
     } elseif (Auth::instance()->logged_in()) {
         $user = Auth::instance()->get_user();
     }
     //lets unsubscribe the user
     if ($user->loaded()) {
         $user->subscriber = 0;
         $user->last_modified = Date::unix2mysql();
         try {
             $user->save();
             Alert::set(Alert::SUCCESS, __('You have successfully unsubscribed'));
         } catch (Exception $e) {
             //throw 500
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         //unsusbcribe from elasticemail
         if (Core::config('email.elastic_listname') != '') {
             ElasticEmail::unsubscribe(Core::config('email.elastic_listname'), $user->email);
         }
     } else {
         Alert::set(Alert::INFO, __('Please login to unsubscribe.'));
     }
     //smart redirect
     if (Auth::instance()->logged_in()) {
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
     } else {
         $this->redirect(Route::url('default'));
     }
 }