Esempio n. 1
0
 public function action_index($account_username = '', $confirm_code = '')
 {
     // load language
     \Lang::load('account');
     // store username and confirm code from url to form and require the form to submit.
     $output['account_username'] = $account_username;
     $output['confirm_code'] = $confirm_code;
     if (\Input::method() == 'POST') {
         // store data for validate and update account status.
         $data['account_username'] = trim(\Input::post('account_username'));
         $data['account_confirm_code'] = trim(\Input::post('confirm_code'));
         // validate form.
         $validate = \Validation::forge();
         $validate->add('account_username', \Lang::get('account_username'), array(), array('required'));
         $validate->add('confirm_code', \Lang::get('account_confirm_code'), array(), array('required'));
         if (!\Extension\NoCsrf::check()) {
             // validate token failed
             $output['form_status'] = 'error';
             $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token');
         } elseif (!$validate->run()) {
             // validate failed
             $output['form_status'] = 'error';
             $output['form_status_message'] = $validate->show_errors();
         } else {
             // confirm register.
             $result = \Model_Accounts::confirmRegister($data);
             if ($result === true) {
                 $output['hide_register_form'] = true;
                 $output['form_status'] = 'success';
                 $output['form_status_message'] = \Lang::get('account_confirm_register_completed');
                 // @todo [fuelstart][account][plug] confirm register passed plug.
                 $plugin = new \Library\Plugins();
                 if ($plugin->hasAction('AccountControllerAfterConfirmedRegister') !== false) {
                     $plugin->doAction('AccountControllerAfterConfirmedRegister', ['input_username' => $account_username, 'inputs_post' => \Input::post()]);
                 }
                 unset($plugin);
             } else {
                 $output['form_status'] = 'error';
                 $output['form_status_message'] = $result;
             }
         }
         // re-populate form
         $output['account_username'] = trim(\Input::post('account_username'));
         $output['confirm_code'] = trim(\Input::post('confirm_code'));
     }
     // <head> output ----------------------------------------------------------------------------------------------
     $output['page_title'] = $this->generateTitle(\Lang::get('account_confirm_register'));
     // <head> output ----------------------------------------------------------------------------------------------
     return $this->generatePage('front/templates/account/confirmregister_v', $output, false);
 }
Esempio n. 2
0
 /**
  * delete level group.
  *
  * @param integer $level_group_id
  * @return boolean
  */
 public static function deleteLevel($level_group_id = '')
 {
     if (in_array($level_group_id, static::forge()->disallowed_edit_delete)) {
         return false;
     }
     // delete related tables.
     \DB::delete(\Model_AccountLevel::getTableName())->where('level_group_id', $level_group_id)->execute();
     \DB::delete(\Model_AccountLevelPermission::getTableName())->where('level_group_id', $level_group_id)->execute();
     // delete level group
     \DB::delete(static::$_table_name)->where('level_group_id', $level_group_id)->execute();
     // @todo [fuelstart][levelgroup][plug] after deleted level group plug.
     $plugin = new \Library\Plugins();
     if ($plugin->hasAction('LevelGroupAfterDeleted') !== false) {
         $plugin->doAction('LevelGroupAfterDeleted', $level_group_id);
     }
     unset($plugin);
     return true;
 }
Esempio n. 3
0
 /**
  * register new account
  *
  * @param array $data
  * @param array $data_fields additional fields to store in account_fields table.
  * @return boolean|string return true when completed and return error text when error occured.
  */
 public static function registerAccount($data = array(), $data_fields = array())
 {
     // check required data.
     if (empty($data) || !is_array($data)) {
         return false;
     }
     // get configurations db
     $cfg = \Model_Config::getvalues(array('member_verification', 'member_disallow_username'));
     // verify disallow username.
     if (isset($cfg['member_disallow_username']['value'])) {
         $cfg['member_disallow_username']['value'] = str_replace(', ', ',', $cfg['member_disallow_username']['value']);
         $disallow_usernames = explode(',', $cfg['member_disallow_username']['value']);
         foreach ($disallow_usernames as $disallow_username) {
             if ($data['account_username'] == trim($disallow_username)) {
                 unset($cfg, $disallow_username, $disallow_usernames);
                 return \Lang::get('account_username_disallowed');
             }
         }
     }
     // check duplicate username.
     $query = static::query()->select('account_username')->where('account_username', $data['account_username']);
     if ($query->count() > 0) {
         unset($query);
         return \Lang::get('account_username_already_exists');
     }
     unset($query);
     // check duplicate email.
     $query = static::query()->select('account_email')->where('account_email', $data['account_email']);
     if ($query->count() > 0) {
         unset($query);
         return \Lang::get('account_email_already_exists');
     }
     unset($query);
     if ($cfg['member_verification']['value'] != '0') {
         // admin config need to verify.
         // generate confirm code
         $data['account_confirm_code'] = \Str::random('alnum', 6);
     }
     // send register email
     $send_result = static::instance()->sendRegisterEmail($data);
     if ($send_result !== true) {
         return $send_result;
     }
     unset($send_result);
     $data['account_password'] = static::instance()->hashPassword($data['account_password']);
     $data['account_create'] = time();
     $data['account_create_gmt'] = \Extension\Date::localToGmt();
     if ($cfg['member_verification']['value'] == '0') {
         // admin config to no need to verify.
         $data['account_status'] = '1';
     } else {
         $data['account_status'] = '0';
         if ($cfg['member_verification']['value'] == '2') {
             $data['account_status_text'] = \Lang::get('account_waiting_for_admin_verification');
         } else {
             $data['account_status_text'] = \Lang::get('account_please_confirm_registration_from_your_email');
         }
     }
     // add account to db. ----------------------------------------
     //list($account_id) = \DB::insert(static::$_table_name)->set($data); // query builder style.
     $account = static::forge($data);
     // add level to user for current site.
     $account->account_level[0] = new Model_AccountLevel();
     $account->account_level[0]->level_group_id = 3;
     $account->save();
     $account_id = $account->account_id;
     unset($account);
     // end add account to db -------------------------------------
     // add level to user.
     // loop sites to add level of this user to each site.
     $site_id = \Model_Sites::getSiteId(false);
     $list_site_option['list_for'] = 'admin';
     $list_site_option['unlimit'] = true;
     $sites = \Model_Sites::listSites($list_site_option);
     if (isset($sites['items']) && is_array($sites['items']) && !empty($sites['items'])) {
         foreach ($sites['items'] as $site) {
             if ($site->site_id != $site_id) {
                 if ($site->site_id == '1') {
                     $table_name = 'account_level';
                 } else {
                     $table_name = $site->site_id . '_account_level';
                 }
                 \DB::insert($table_name)->set(array('account_id' => $account_id, 'level_group_id' => '3'))->execute();
             }
         }
     }
     unset($list_site_option, $site, $sites, $site_id, $table_name);
     // add account fields if there is any value.
     // to add account fields data structure shoud be like this...
     // array(array('field_name' => 'website', 'field_value' => 'http://domain.tld'), array('field_name' => 'fb', 'field_value' => 'http://fb.com/myprofile'));
     // or
     // $af[0]['field_name'] = 'website';
     // $af[0]['field_value'] = 'http://domain.tld';
     // $sf[1]['field_name'] = 'fb';
     // $sf[1]['field_value'] = 'http://fb.com/myprofile';
     if (!empty($data_fields) && is_array($data_fields)) {
         foreach ($data_fields as $field) {
             $account_fields = static::forge($field);
             $account_fields->account_id = $account_id;
             $account_fields->save();
         }
         unset($account_fields, $field);
     }
     // @todo [fuelstart][account][plug] account after register plug.
     // after saved newly user data but not confirm (if require confirm).
     $plugin = new \Library\Plugins();
     if ($plugin->hasAction('AccountAfterRegister') !== false) {
         $plugin->doAction('AccountAfterRegister', ['input_data' => $data, 'input_data_fields' => $data_fields, 'inputs_post' => \Input::post()]);
     }
     unset($plugin);
     return true;
 }
Esempio n. 4
0
 /**
  * delete site tables and site data in sites table.
  *
  * @param integer $site_id
  * @return boolean
  */
 public static function deleteSite($site_id = '')
 {
     // prevent delete site 1
     if ($site_id == '1') {
         return false;
     }
     $self = new static();
     // get module's multisite tables.
     $self->hookGetMultisiteTables();
     // delete related _sites tables
     // this can be done by ORM relation itself. I have nothing to do here except something to remove more than just in db, example file, folder
     // drop [site_id]_tables
     foreach ($self->multisite_tables as $table) {
         \DBUtil::drop_table($site_id . '_' . $table);
     }
     // delete data in related tables
     \DB::delete(\Model_AccountLogins::getTableName())->where('site_id', $site_id)->execute();
     \DB::delete(\Model_AccountSites::getTableName())->where('site_id', $site_id)->execute();
     // delete this site from sites table
     \DB::delete(static::$_table_name)->where('site_id', $site_id)->execute();
     // @todo [fuelstart][multisite][plug] after delete site plug.
     $plugin = new \Library\Plugins();
     if ($plugin->hasAction('SitesAfterDeleteSite') !== false) {
         $plugin->doAction('SitesAfterDeleteSite', $site_id);
     }
     unset($plugin);
     // clear cache
     \Extension\Cache::deleteCache('model.accounts-checkAccount-' . $site_id);
     \Extension\Cache::deleteCache('model.accountLevelPermission-checkLevelPermission-' . $site_id);
     \Extension\Cache::deleteCache('model.accountPermission-checkAccountPermission-' . $site_id);
     \Extension\Cache::deleteCache('model.config-getval-' . $site_id);
     \Extension\Cache::deleteCache('model.config-getvalues-' . $site_id);
     \Extension\Cache::deleteCache('model.sites-getSiteId');
     \Extension\Cache::deleteCache('model.sites-isSiteEnabled');
     \Extension\Cache::deleteCache('controller.AdminController-generatePage-fs_list_sites');
     // done
     unset($self);
     return true;
 }