_docOpts = $docOpts;
parent::Auth($DBObj);
}
function isLogged()
{
$data = $this->getData();
$logged = (!empty($data[$this->cookieAccessCodeName]) && $data[$this->cookieAccessCodeName] == $_COOKIE[$this->cookieAccessCodeName]);
if (!$logged) {
$this->clearSessionData();
}
return $logged;
}
function checkAutoLogin()
{
if ($this->isLogged()) {
$memberData = $this->getData();
if ($memberData['auto_login'] == 'y' && strtotime($memberData['access_code_changed']) < (time() - $this->cookieUpdatePeriod)) {
$this->updateAccessCode($memberData);
}
return false;
}
if (isset($_COOKIE[$this->cookieAccessCodeName])) {
$memberData = $this->DBObj->getMemberByAccessCode($_COOKIE[$this->cookieAccessCodeName]);
if (!is_array($memberData) || empty($memberData) || $memberData['auto_login'] != 'y') {
return false;
}
if (strtotime($memberData['access_code_changed']) < (time() - $this->cookieUpdatePeriod)) {
$this->updateAccessCode($memberData);
}
$this->updateSessionData($memberData);
}
return true;
}
function getData($key = null, $is_support_account = false)
{
$sessionName = $this->ses_arr_name;
$variableName = '_loginData';
if ($is_support_account) {
$sessionName .= '_support';
$variableName = '_loginDataSupoort';
}
require_once ('class/Session.php');
$arr = Session::getData($sessionName, $sessionName);
if ($arr) {
if (null === $this->$variableName) {
$this->$variableName = $this->DBObj->DBLogin(array('login' => $arr[$this->DBObj->login_field], 'password' => $arr[$this->DBObj->pass_field]));
}
$arr = &$this->$variableName;
if ($key != null && array_key_exists($key, $arr)) {
return $arr[$key];
}
}
return $arr;
}
public static function getSessionData($key = null)
{
require_once ('class/Session.php');
$arr = Session::getData(USERAUTH_SESSION_ARR_NAME, USERAUTH_SESSION_ARR_NAME);
if (null !== $key) {
if (isset($arr[$key])) {
return $arr[$key];
}
return null;
}
return $arr;
}
public static function setSessionData($data, $key = null)
{
require_once ('class/Session.php');
if ($key == null) {
Session::setData(USERAUTH_SESSION_ARR_NAME, USERAUTH_SESSION_ARR_NAME, $data);
} else {
$arr = Session::getData(USERAUTH_SESSION_ARR_NAME, USERAUTH_SESSION_ARR_NAME);
$arr[$key] = $data;
Session::setData(USERAUTH_SESSION_ARR_NAME, USERAUTH_SESSION_ARR_NAME, $arr);
}
return $arr;
}
function verifyEmailForm(&$Doc)
{
require_once 'class/Form/Form.class.php';
$form = new Form($Doc, 'checkEmail');
$form->addFormRule(array(&$this, 'checkemail'));
$form->setTitle('
Don\'t have an account?
');
$form->addElement('text', 'email', 'E-Mail', array('style' => 'width:230px;'));
$action = &$form->addElement('hidden', 'action');
$action->setValue('checkemail');
$form->setCancelType('none');
$form->submitTitle = 'Verify Email';
$form->addRuleRequired(array('email'));
$form->setTpl(BASE_PATH . '/tpl/Member/createaccount.tpl');
return $form;
}
function createAccountForm(&$Doc, $defaults)
{
require_once 'class/Form/Form.class.php';
$form = new Form($Doc, 'createAccount');
$form->addFormRule(array(&$this, 'validcode'));
$form->setTitle('The verification code has been sent to
' . $defaults['email'] . ' (please check your inbox)');
$form->addElement('static', 'staticdenote', null, '* denotes required field
');
$form->addElement('hidden', 'email', $defaults['email']);
$form->addElement('static', 'staticemail', 'E-Mail', $defaults['email']);
$form->addElement('text', 'verificationcode', 'Verification Code', array('size' => 35, 'value' => $defaults['verificationcode']));
$form->addElement('password', 'password', 'Password');
$form->addElement('text', 'first_name', 'First Name');
$form->addElement('text', 'middle_initial', 'Middle Name');
$form->addElement('text', 'last_name', 'Last Name');
$form->addElement('text', 'company_name', 'Company Name');
$form->addElement('text', 'address', 'Address');
$form->addElement('text', 'city', 'City');
$form->addElement('select', 'state', 'State ', array(''=>'') + (array)$this->DBObj->getState4Select());
$form->addElement('text', 'zip', 'Zip Code');
$form->addElement('text', 'primary_phone', 'Phone');
$form->addRuleRequired(array('verificationcode', 'password', 'first_name', 'last_name', 'primary_phone', 'company_name'));
$action = &$form->addElement('hidden', 'action');
$action->setValue('create_account');
$form->setCancelType('none');
$form->submitTitle = 'Create Account & Login';
$form->setTpl(BASE_PATH . '/tpl/Member/createaccount.tpl');
return $form;
}
function checkemail($user)
{
if ($this->DBObj->isUnique('email', $user['email'])) return true;
else return array('email' => 'This email is already exists. Please use it to login, using form above, or choose another email)');
}
function validcode($data)
{
// vdie(1);
if (!$this->DBObj->isUnique('email', $data['email'])) return array('verificationcode' => 'This Verification Code and Email are already used');
elseif ($data['verificationcode'] == md5($data['email'] . date('d-m-Y')) || $data['verificationcode'] == md5(
$data['email'] . date('d-m-Y', mktime() - 24 * 60 * 60))) return true;
else return array('verificationcode' => 'Verification Code is invalid');
}
function createAccount($data)
{
$Member = SiteMap::getObj('Member/Member.php');
$data['email_verified'] = 'y';
$data['info_verified'] = 'y';
$data['is_accepted_legal_agreement'] = 'y';
$data['id_misc_type'] = 3;
$data['id_misc_status'] = 1;
$aFields = array('email' => 'Email',
'first_name' => 'First Name',
'middle_initial' => 'Middle Name',
'last_name' => 'Last Name',
'company_name' => 'Company Name',
'address' => 'Address',
'city' => 'City',
'state' => 'State',
'zip' => 'Zip Code',
'primary_phone' => 'Phone');
$data['note']='';
$aP = str_split(preg_replace('/\D/', '', $data['primary_phone']));
$data['primary_phone'] = '(' . $aP[0] . $aP[1] . $aP[2] . ') ' . $aP[3] . $aP[4] . $aP[5] . '-' . $aP[6] . $aP[7] . $aP[8] . $aP[9];
if (count($aP) > 10) $data['primary_phone'] .= ' ext. ';
for($i = 10; $i < count($aP); $i++) $data['primary_phone'] .= $aP[$i];
$Member->initFromArray($data);
$nMemberID=$Member->insert();
foreach ($aFields as $key=>$label) $data['note'].=$label.': '.$data[$key]."\r\n";
require_once ('lib/htmlMimeMail/htmlMimeMail.php');
$mail = new htmlMimeMail();
$mail->setHtml(
'New Member Account has been registered for Open Event at MNCAR.org.
'.nl2br($data['note']).'
Click here to view more info');
require_once ('app/Settings/Settings.php');
$mail->setFrom(Settings::get('admin_email_from'));
$mail->setSubject('New Member Account has been registered for Open Event at MNCAR.org.');
$mail->setHeader('X-Mailer', 'HTML Mime mail class');
$mail->send(array(Settings::get('admin_email')));
$this->login(array('member_login' => $data['email'], 'member_password' => $this->DBObj->_encryptPass($data['password'])));
}
function sendemail4verify($email)
{
require_once ('lib/htmlMimeMail/htmlMimeMail.php');
$mail = new htmlMimeMail();
require_once ('class/Session.php');
$aLogin2 = split('\/', Session::getData($this->ses_arr_name, 'login_to'));
$nEventID = (int) $aLogin2[count($aLogin2) - 1];
$cCode = md5($email . date('d-m-Y'));
$mail->setHtml(
'Thank you for creating a new account on www.mncar.org! Click the link below to
continue the registration process:
Click here to continue registration
Alternately, you can copy the following code and paste it into the field
indicated in the next step of the registration process:
Email Verification Code: ' . $cCode . '
Notice: this code is valid during 24 hours only.
');
require_once ('app/Settings/Settings.php');
$mail->setFrom(Settings::get('admin_email_from'));
$mail->setSubject('Email Verifying from mncar.org');
$mail->setHeader('X-Mailer', 'HTML Mime mail class');
$mail->send(array($email));
}
function getLoginForm(&$Doc)
{
require_once 'class/Form/Form.class.php';
$form = new Form($Doc, 'sssssssssss');
$form->addFormRule(array(&$this, 'login'));
$form->setTitle('');
require_once ('class/Session.php');
$login = Form::createElement('text', 'member_login', 'Your Email', array('class' => 'inp_login'));
$form->addElement($login);
$form->setCancelType(FORM_CBT_RESET);
$password = & Form::createElement('password', 'member_password', 'Password', array('class' => 'inp_login'));
$form->style_pref = 'login_';
$form->addElement($password);
$password->setValue('');
$action = Form::createElement('hidden', 'action', 'login');
$form->addElement($action);
$form->addElement('advcheckbox', 'auto_login', '', 'Remember me for future visits', null, array('n', 'y'));
//$form->addElement('password', 'reg_password', 'Choose a Password', array('class' => 'inp_login'));
//$form->addElement('password', 'reg_confirm_password', 'Confirm Your Password', array('class' => 'inp_login'));
$form->setCancelType('none');
$form->submitTitle = 'Login';
$form->setRendType(FORM_RENDERER_ARRAY_SMARTY);
$form->return_form_arr = true;
$form->setTpl(BASE_PATH . '/tpl/Member/login.tpl');
return $form;
}
function login($user, $files = array(), $redirect = true, $useAutoLogin = true)
{
if (empty($user['member_password'])) {
return array('member_password' => 'Password is required');
}
$member = $this->DBObj->getMemberByEmail($user['member_login']);
if (!is_array($member) || empty($member)) {
return array('member_login' => 'Bad login or password');
}
if (true !== ($err = $this->DBObj->validStatus($member))) {
return array('member_login' => $err);
}
if (true !== ($err = $this->DBObj->validActivated($member))) {
return array('member_login'=>$err);
}
if ($member['is_support_account'] == 'y') {
$DBObj = SiteMap::getObj('SupportAccount/Profile/Profile.php');
$SupportAccountAuth = SiteMap::getObj('SupportAccount/SupportAccountAuth.php', null, $DBObj);
if (true !== ($ret = $SupportAccountAuth->login($user, array(), false))) {
return $ret;
}
$redirectURL = $SupportAccountAuth->getLogin2();
//require_once ('class/HTTP.php');
$supportData = $SupportAccountAuth->getData();
if (intval($member['id_autologin_member'])
&& intval($member['id']) != intval($member['id_autologin_member'])
&& array_key_exists(intval($member['id_autologin_member']), $supportData['ids_member']) && $useAutoLogin
) {
$memberData = $this->DBObj->getMemberById(intval($member['id_autologin_member']));
if (isset($memberData['id']) && $memberData['is_support_account'] == 'n') {
$this->logout(false);
$GLOBALS['Doc']->assign('member', null);
$GLOBALS['Doc']->assign('id_member4select', $id_member);
$this->login(array('member_login'=>$memberData['email'], 'member_password'=>$memberData['password']), $files, empty($redirectURL));
}
//vdie(BASE_URL.'/support-account/profile?action=switch&id_member='.intval($member['id_autologin_member']));
//skHTTP::redirect(BASE_URL.'/support-account/profile?action=switch&id_member='.intval($member['id_autologin_member']));
}
if (empty($redirectURL)) {
$redirectURL = BASE_URL;
}
/*skHTTP::redirect($redirectURL);*/
//vdie($redirectURL);
//return true;
}
if (true !== ($err = $this->DBObj->validAgreement($member))) {
require_once ('class/Session.php');
Session::setData('login_info','login_info',$user);
require_once ('class/HTTP.php');
skHTTP::redirect(BASE_URL.'/account/login?action=agreement-form');
}
$auto_login = $user['auto_login'];
if ($user['force2account']=='force2account') $force2account=true;
else $force2account=false;
$user = $this->DBObj->DBLogin(array('login' => $user['member_login'], 'password' => $this->DBObj->_encryptPass($user['member_password'])));
//vdie($user);
if (!empty($user)) {
$this->updateAccessCode($user);
$this->updateSessionData($user);
if ($auto_login == 'y' && $user['auto_login'] != 'y') {
$this->DBObj->setAutoLogin($user['id']);
}
if ($redirect) {
$url = $this->getLogin2();
if ($url == '' || $force2account) {
$url = BASE_URL . '/' . str_replace('/login', '', CURR_PAGE);
}
require_once ('class/HTTP.php');
//vdie($url, Session::getData('individual_user', 'individual_user'));
skHTTP::redirect($url);
}
return true;
} else {
return array('member_password' => 'Invalid password');
}
}
function updateSessionData($user, $is_support_account = false)
{
require_once ('class/Session.php');
$sessionName = $this->ses_arr_name;
$sessionData = Session::getData($sessionName, $sessionName);
if (is_array($sessionData) && !empty($sessionData)) {
$user = array_merge($sessionData, $user);
}
Session::setData($sessionName, $sessionName, $user);
}
function clearSessionData()
{
require_once ('class/Session.php');
Session::clearData($this->ses_arr_name, $this->ses_arr_name);
}
function logout($redirect = true)
{
require_once ('class/Session.php');
Session::clearData($this->ses_arr_name, $this->ses_arr_name);
setcookie($this->cookieAccessCodeName, '', time() - 3600, '/', $_SERVER['HTTP_HOST'], false);
if ($redirect) {
header("Location: " . BASE_URL);
exit();
}
}
function updateAccessCode(&$user)
{
$user[$this->cookieAccessCodeName] = md5(rand(10, 999) . time() . $user['email'] . rand(100, 300));
$this->DBObj->updateAccessCode($user['id'], $user[$this->cookieAccessCodeName], $this->cookieAccessCodeName);
setcookie($this->cookieAccessCodeName, $user[$this->cookieAccessCodeName], time() + 60 * 60 * 24, '/',
$_SERVER['HTTP_HOST'], false);
}
}
?>