/** * add login session * * @param array $data */ public function addLoginSession($data = array()) { if (!isset($data['site_id'])) { $site_id = \Model_Sites::getSiteId(false); } else { $site_id = $data['site_id']; } unset($data['site_id']); // find exists last login on target site id. $result = \DB::select()->as_object()->from(static::$_table_name)->where('account_id', $data['account_id'])->where('site_id', $site_id)->execute(); if (count($result) <= 0) { // use insert $insert['account_id'] = $data['account_id']; $insert['site_id'] = $site_id; $insert['account_last_login'] = time(); $insert['account_last_login_gmt'] = \Extension\Date::localToGmt(); if (isset($data['session_id'])) { $insert['account_online_code'] = $data['session_id']; } \DB::insert(static::$_table_name)->set($insert)->execute(); unset($insert); } else { // use update $update['account_last_login'] = time(); $update['account_last_login_gmt'] = \Extension\Date::localToGmt(); if (isset($data['session_id'])) { $update['account_online_code'] = $data['session_id']; } \DB::update(static::$_table_name)->where('account_id', $data['account_id'])->where('site_id', $site_id)->set($update)->execute(); unset($update); } unset($result, $site_id); }
public static function run() { // get site name $result = \DB::select('config_name', 'config_value')->from('config')->where('config_name', 'site_name')->as_object()->execute(); $row = $result->current(); $site_name = $row->config_value; unset($result, $row); // get domain if (isset($_SERVER['HTTP_HOST'])) { $site_domain = $_SERVER['HTTP_HOST']; } elseif (isset($_SERVER['SERVER_NAME'])) { $site_domain = $_SERVER['SERVER_NAME']; } else { $site_domain = 'localhost'; } $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('sites') . "` (\n `site_id` int(11) NOT NULL AUTO_INCREMENT,\n `site_name` varchar(255) DEFAULT NULL,\n `site_domain` varchar(255) DEFAULT NULL COMMENT 'ex. domain.com, sub.domain.com with out http://',\n `site_status` int(1) NOT NULL DEFAULT '0' COMMENT '0=disable, 1=enable',\n `site_create` bigint(20) DEFAULT NULL,\n `site_create_gmt` bigint(20) DEFAULT NULL,\n `site_update` bigint(20) DEFAULT NULL,\n `site_update_gmt` bigint(20) DEFAULT NULL,\n PRIMARY KEY (`site_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;"; \DB::query($sql)->execute(); // check if table already created before insert. $result = \DB::count_records('sites'); if ($result <= 0) { $sql = "INSERT INTO `" . \DB::table_prefix('sites') . "` (`site_id`, `site_name`, `site_domain`, `site_status`, `site_create`, `site_create_gmt`, `site_update`, `site_update_gmt`) VALUES\n (1, '" . $site_name . "', '" . $site_domain . "', 1, " . time() . ", " . \Extension\Date::localToGmt() . ", " . time() . ", " . \Extension\Date::localToGmt() . ");"; \DB::query($sql)->execute(); } unset($sql); return true; }
/** * check cron to run in time * * @param array $option options avaliable: [name, second_expired, run_timestamp] * @param array $callback_function * @param array $callback_function_param * @return boolean */ public function checkCron(array $option = array(), array $callback_function = array(), $callback_function_param = array()) { // not set option name if (!isset($option['name'])) { return false; } // verify second expired. if (!isset($option['second_expired'])) { $option['second_expired'] = 86400; } else { $option['second_expired'] = (int) $option['second_expired']; } // verify run on date/time timestamp is valid and set (if not set, set to null) if (!isset($option['run_timestamp']) || isset($option['run_timestamp']) && !\Extension\Date::isValidTimeStamp((string) $option['run_timestamp'])) { $option['run_timestamp'] = null; } // check that both expired and run timestamp has value. if ($option['second_expired'] == 0 && $option['run_timestamp'] == null) { return false; } // set callback function param to be array if it is not. if (!is_array($callback_function_param)) { $callback_function_param = array($callback_function_param); } // start checking ------------------------------------------------------------------------------------------------ $run_task = false; // run from specific date/time timestamp. if ($option['run_timestamp'] != null && $option['run_timestamp'] <= time()) { $run_task = true; } elseif ($option['second_expired'] > 0) { // get cache of this task name try { // get site id $site_id = \Model_Sites::getSiteId(false); $cache = \Cache::get('library.webcron-siteid' . $site_id . '-' . $option['name']); } catch (\CacheNotFoundException $e) { $cache = false; } // if never cached or cache expired if ($cache === false) { $run_task = true; // get site id $site_id = \Model_Sites::getSiteId(false); \Cache::set('library.webcron-siteid' . $site_id . '-' . $option['name'], 'done', $option['second_expired']); } } // checked pass, run the task by call to callback function. if ($run_task === true) { call_user_func_array($callback_function, $callback_function_param); return true; } return false; }
public function actionAccountLoginSuccess($account_id = '', $args = '') { $testmod_path = \Module::exists('testmod'); $log_file_name = 'login-success.txt'; $log_file_path = $testmod_path . $log_file_name; // delete if exists. if (\File::exists($log_file_path) && !is_writable($log_file_path)) { return false; } elseif (\File::exists($log_file_path) && is_writable($log_file_path)) { \File::delete($log_file_path); } \File::create($testmod_path, $log_file_name, 'Account id ' . $account_id . ' log in success on ' . \Extension\Date::gmtDate()); return true; }
/** * 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; }
<?php foreach ($list_items['items'] as $row) { ?> <tr> <td class="check-column"><?php echo \Extension\Form::checkbox('id[]', $row->post_id); ?> </td> <td><?php echo $row->post_name; ?> </td> <td></td> <td><?php echo \Extension\Date::gmtDate('', $row->post_date); ?> </td> <td> <?php if (\Model_AccountLevelPermission::checkAdminPermission('blog_perm', 'blog_write_perm')) { echo \Extension\Html::anchor('blog/admin/index/edit/' . $row->post_id, '<span class="glyphicon glyphicon-pencil"></span> ' . \Lang::get('admin_edit'), array('class' => 'btn btn-default btn-xs')); } ?> </td> </tr> <?php } // endforeach; ?>
/** * record login * @param integer $account_id * @param integer $attempt 0 for failed, 1 for success * @param string $attempt_text attempt text * @return boolean */ public function recordLogin($account_id = '', $attempt = '0', $attempt_text = '') { if (!is_numeric($account_id) || !is_numeric($attempt)) { return false; } if ($attempt_text == null) { $attempt_text = null; } $site_id = \Model_Sites::getSiteId(false); // get browser class for use instead of fuelphp agent which is does not work. include_once APPPATH . 'vendor' . DS . 'browser' . DS . 'lib' . DS . 'Browser.php'; $browser = new Browser(); // set data for insertion $data['account_id'] = $account_id; $data['site_id'] = $site_id; $data['login_ua'] = \Input::user_agent(); $data['login_os'] = $browser->getPlatform(); $data['login_browser'] = $browser->getBrowser() . ' ' . $browser->getVersion(); $data['login_ip'] = \Input::real_ip(); $data['login_time'] = time(); $data['login_time_gmt'] = \Extension\Date::localToGmt(); $data['login_attempt'] = $attempt; $data['login_attempt_text'] = $attempt_text; \DB::insert(static::$_table_name)->set($data)->execute(); unset($browser, $data, $site_id); return true; }
/** * edit site. update site name to config table too. * * @param array $data * @return boolean */ public static function editSite(array $data = array()) { // check site_domain not exists in other site_id $match_sites = \DB::select()->from(static::$_table_name)->where('site_id', '!=', $data['site_id'])->where('site_domain', $data['site_domain'])->execute(); if (count($match_sites) > 0) { unset($match_sites); return \Lang::get('siteman_domain_currently_exists'); } unset($match_sites); // additional data for updating $data['site_update'] = time(); $data['site_update_gmt'] = \Extension\Date::localToGmt(); // filter data before update if ($data['site_id'] == '1') { // site 1 always enabled. $data['site_status'] = '1'; } $site_id = $data['site_id']; unset($data['site_id']); // update to db \DB::update(static::$_table_name)->where('site_id', $site_id)->set($data)->execute(); // set config for new site. $cfg_data['site_name'] = $data['site_name']; if ($site_id == '1') { $config_table = 'config'; } else { $config_table = $site_id . '_config'; } foreach ($cfg_data as $cfg_name => $cfg_value) { \DB::update($config_table)->where('config_name', $cfg_name)->value('config_value', $cfg_value)->execute(); } unset($cfg_data, $cfg_name, $cfg_value); // clear cache \Extension\Cache::deleteCache('model.sites-getSiteId'); \Extension\Cache::deleteCache('model.sites-isSiteEnabled'); \Extension\Cache::deleteCache('controller.AdminController-generatePage-fs_list_sites'); // done return true; }
if ($i > 5) { echo '...'; break; } $i++; } unset($lvg, $lvl); ?> </td> <td><?php echo \Extension\Date::gmtDate('', $row->account_create); ?> </td> <td><?php if ($row->account_last_login != null) { echo \Extension\Date::gmtDate('', $row->account_last_login); } ?> </td> <td><span class="glyphicon glyphicon-<?php echo $row->account_status == '1' ? 'ok' : 'remove'; ?> "></span> <?php echo $row->account_status_text; ?> </td> <td> <?php if ($row->account_id != '0') { ?>
$tmp_account_timezone = \Extension\Date::getRealTimezoneValue($default_timezone); $account_timezone = $default_timezone; } foreach ($timezone_list as $tznum => $tzval) { echo '<option value="' . $tznum . '"' . (isset($account_timezone) && $account_timezone == $tznum ? ' selected="selected"' : '') . '>' . $tznum . '</option>' . "\n"; // selected, no more another selected because this list have many duplicate key. if (isset($account_timezone) && $account_timezone == $tznum) { unset($account_timezone); } } unset($timezone_list, $tznum, $tzval); ?> </select> <div class="help-block"><?php echo __('account_current_date_time_example', array('time' => \Extension\Date::gmtDate('%Y-%m-%d %H:%M:%S', (string) time(), $tmp_account_timezone))); ?> </div> </div> </div> </fieldset> <fieldset> <legend><?php echo __('account_personal_info'); ?> </legend> <div class="form-group"> <label for="account_firstname" class="col-sm-2 control-label"><?php echo __('account_firstname'); ?>
?> </a></td> <td><?php echo $row->login_ua; ?> </td> <td><?php echo $row->login_browser; ?> </td> <td><?php echo $row->login_ip; ?> </td> <td><?php echo \Extension\Date::gmtDate('', $row->login_time, $account->account_timezone); ?> </td> <td><span class="glyphicon glyphicon-<?php echo $row->login_attempt == '1' ? 'ok' : 'remove'; ?> "></span> <?php echo __('account.' . $row->login_attempt_text); ?> </td> </tr> <?php } // endofreach; ?>
?> </td> <td><?php echo $row->site_domain; ?> </td> <td><span class="glyphicon glyphicon-<?php echo $row->site_status == '1' ? 'ok' : 'remove'; ?> "></span></td> <td><?php echo \Extension\Date::gmtDate('', $row->site_create); ?> </td> <td><?php echo \Extension\Date::gmtDate('', $row->site_update); ?> </td> <td> <ul class="actions-inline"> <?php if (\Model_AccountLevelPermission::checkAdminPermission('siteman_perm', 'siteman_edit_perm')) { ?> <li><?php echo \Extension\Html::anchor('admin/siteman/edit/' . $row->site_id, '<span class="glyphicon glyphicon-pencil"></span> ' . __('admin_edit'), array('class' => 'btn btn-default btn-xs')); ?> </li><?php } ?> </ul>