/** * member login. * * @param array $data * @return mixed return true on success, return error message on failed. */ public static function memberLogin($data = array()) { if (!isset($data['account_password']) || !isset($data['account_username']) && !isset($data['account_email'])) { return false; } else { if (!isset($data['account_username'])) { $data['account_username'] = null; } if (!isset($data['account_email'])) { $data['account_email'] = null; } } $query = static::query()->where('account_username', $data['account_username'])->or_where('account_email', $data['account_email']); if ($query->count() > 0) { // found $row = $query->get_one(); // clear cache \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $row->account_id); // check enabled account. if ($row->account_status == '1') { // enabled // check password if (static::instance()->checkPassword($data['account_password'], $row->account_password, $row) === true) { // check password passed // generate session id for check simultaneous login $session_id = \Session::key('session_id'); // if login set to remember, set expires. if (\Input::post('remember') == 'yes') { $expires = \Model_Config::getval('member_login_remember_length') * 24 * 60 * 60; } else { $expires = 0; } // set cookie $cookie_account['account_id'] = $row->account_id; $cookie_account['account_username'] = $row->account_username; $cookie_account['account_email'] = $row->account_email; $cookie_account['account_display_name'] = $row->account_display_name; $cookie_account['account_online_code'] = $session_id; $cookie_account = \Crypt::encode(serialize($cookie_account)); Extension\Cookie::set('member_account', $cookie_account, $expires); unset($cookie_account, $expires); // update last login in accounts table $accounts = static::find($row->account_id); $accounts->account_last_login = time(); $accounts->account_last_login_gmt = \Extension\Date::localToGmt(); $accounts->save(); unset($accounts); // add/update last login session. $account_session['account_id'] = $row->account_id; $account_session['session_id'] = $session_id; $account_site = new \Model_AccountSites(); $account_site->addLoginSession($account_session); unset($account_session); // record login $account_logins = new Model_AccountLogins(); $account_logins->recordLogin($row->account_id, 1, 'account_login_success'); // @todo [fuelstart][account][plug] login success plug. $plugin = new \Library\Plugins(); if ($plugin->hasAction('AccountLoginSuccess') !== false) { $plugin->doAction('AccountLoginSuccess', $row->account_id, $row); } unset($plugin, $query, $row, $session_id); // login success return true; } else { // check password failed, wrong password $account_logins = new Model_AccountLogins(); $account_logins->recordLogin($row->account_id, 0, 'account_wrong_username_or_password'); unset($query, $row); return \Lang::get('account_wrong_username_or_password'); } } else { // account disabled $account_logins = new Model_AccountLogins(); $account_logins->recordLogin($row->account_id, 0, 'account_was_disabled'); unset($query); return \Lang::get('account_was_disabled') . ' : ' . $row->account_status_text; } } // not found account. login failed unset($query); return \Lang::get('account_wrong_username_or_password'); }
/** * 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; }
public function action_viewlogins($account_id = '') { // set redirect url $redirect = $this->getAndSetSubmitRedirection(); // check permission if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_viewlogin_log_perm') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); \Response::redirect($redirect); } // viewing guest logins? if ($account_id == '0') { \Response::redirect($redirect); } // load language \Lang::load('account'); \Lang::load('accountlogins'); // read flash message for display errors. $form_status = \Session::get_flash('form_status'); if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) { $output['form_status'] = $form_status['form_status']; $output['form_status_message'] = $form_status['form_status_message']; } unset($form_status); // get accounts data for this account. $account = \Model_Accounts::find($account_id); if ($account == null) { // not found account. \Response::redirect($redirect); } $output['account'] = $account; $output['account_id'] = $account_id; unset($account); // set sort variable for sortable in views. $next_sort = \Security::strip_tags(trim(\Input::get('sort'))); if ($next_sort == null || $next_sort == 'DESC') { $next_sort = 'ASC'; } else { $next_sort = 'DESC'; } $output['next_sort'] = $next_sort; unset($next_sort); // list logins ----------------------------------------------------------------------------------------------------- $option['limit'] = \Model_Config::getval('content_admin_items_perpage'); $option['offset'] = trim(\Input::get('page')) != null ? ((int) \Input::get('page') - 1) * $option['limit'] : 0; if (\Security::strip_tags(trim(\Input::get('orders'))) != null) { $option['orders'] = \Security::strip_tags(trim(\Input::get('orders'))); } if (\Security::strip_tags(trim(\Input::get('sort'))) != null) { $option['sort'] = \Security::strip_tags(trim(\Input::get('sort'))); } $list_logins = \Model_AccountLogins::listLogins(array('account_id' => $account_id), $option); // pagination config $config['pagination_url'] = \Uri::main() . \Uri::getCurrentQuerystrings(true, true, false); $config['total_items'] = $list_logins['total']; $config['per_page'] = $option['limit']; $config['uri_segment'] = 'page'; $config['num_links'] = 3; $config['show_first'] = true; $config['show_last'] = true; $config['first-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['first-inactive-link'] = '<a href="#">{page}</a>'; $config['first-marker'] = '«'; $config['last-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['last-inactive-link'] = '<a href="#">{page}</a>'; $config['last-marker'] = '»'; $config['previous-marker'] = '‹'; $config['next-marker'] = '›'; $pagination = \Pagination::forge('viewlogins_pagination', $config); $output['list_logins'] = $list_logins; $output['pagination'] = $pagination; unset($config, $list_logins, $option, $pagination); // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('account_view_login_history')); // <head> output ---------------------------------------------------------------------------------------------- // breadcrumb ------------------------------------------------------------------------------------------------- $page_breadcrumb = []; $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')]; $page_breadcrumb[1] = ['name' => \Lang::get('account_accounts'), 'url' => \Uri::create('admin/account')]; $page_breadcrumb[2] = ['name' => \Lang::get('account_view_login_history'), 'url' => \Uri::main()]; $output['page_breadcrumb'] = $page_breadcrumb; unset($page_breadcrumb); // breadcrumb ------------------------------------------------------------------------------------------------- return $this->generatePage('admin/templates/account/viewlogins_v', $output, false); }
public function action_index() { // is user logged in? if (\Model_Accounts::isMemberLogin() == false) { \Response::redirect(\Uri::create('account/login') . '?rdr=' . urlencode(\Uri::main())); } // load language \Lang::load('account'); \Lang::load('accountlogins'); // get account id $cookie_account = \Model_Accounts::forge()->getAccountCookie(); // get account data $row = \Model_Accounts::find($cookie_account['account_id']); if ($row == null) { // not found user data. unset($row); \Response::redirect(\Uri::main()); } $output['account'] = $row; // set sort variable for sortable in views. $next_sort = \Security::strip_tags(trim(\Input::get('sort'))); if ($next_sort == null || $next_sort == 'DESC') { $next_sort = 'ASC'; } else { $next_sort = 'DESC'; } $output['next_sort'] = $next_sort; unset($next_sort); // list logins ----------------------------------------------------------------------------------------------------- $option['limit'] = \Model_Config::getval('content_items_perpage'); $option['offset'] = trim(\Input::get('page')) != null ? ((int) \Input::get('page') - 1) * $option['limit'] : 0; if (\Security::strip_tags(trim(\Input::get('orders'))) != null) { $option['orders'] = \Security::strip_tags(trim(\Input::get('orders'))); } if (\Security::strip_tags(trim(\Input::get('sort'))) != null) { $option['sort'] = \Security::strip_tags(trim(\Input::get('sort'))); } $data['account_id'] = $cookie_account['account_id']; $data['site_id'] = \Model_Sites::getSiteId(); $list_logins = \Model_AccountLogins::listLogins($data, $option); // pagination config $config['pagination_url'] = \Uri::main() . \Uri::getCurrentQuerystrings(true, true, false); $config['total_items'] = $list_logins['total']; $config['per_page'] = $option['limit']; $config['uri_segment'] = 'page'; $config['num_links'] = 3; $config['show_first'] = true; $config['show_last'] = true; $config['first-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['first-inactive-link'] = '<a href="#">{page}</a>'; $config['first-marker'] = '«'; $config['last-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['last-inactive-link'] = '<a href="#">{page}</a>'; $config['last-marker'] = '»'; $config['previous-marker'] = '‹'; $config['next-marker'] = '›'; $pagination = \Pagination::forge('viewlogins_pagination', $config); $output['list_logins'] = $list_logins; $output['pagination'] = $pagination; unset($config, $data, $list_logins, $option, $pagination); // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('account_login_history')); // <head> output ---------------------------------------------------------------------------------------------- return $this->generatePage('front/templates/account/viewlogins_v', $output, false); }