/** * 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'); }