/source/application/controller/Home/LoginController.php
PHP | 411 lines | 299 code | 72 blank | 40 comment | 42 complexity | 8235c735318e623c94839e039f26d5d9 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- // Business class to include
- class Home_LoginController extends TvcController
- {
- const MENU_ITEM = Parameter::MENU_REGISTER;
- /*
- * Log in
- */
- function loginAction()
- {
- $smarty = TVC::load('smarty');
- $return_link = TVC_Request::get('return_link');
- $smarty->assign('register_link', APPLICATION_URL . '/login/register?affCd=AAAAA');
- $login_time = TVC_Request::getIntNumber('login_time');
- if(Parameter::$params['ALLOW_PUBLIC'])
- {
- setcookie("from_public_site", "1", time() + 3600*24*30, "/", DOMAIN);
- }
- // get id of requested user
- $rid = TVC_Request::getIntNumber('rid');
- // get salt value
- $salt_value = TVC_Request::get('sno');
- // get id of user
- $id = TVC_Request::getIntNumber('id');
- $error_code = null;
- $user = new User();
- // if 3 parameters exist, do OneClick Login action
- if ($rid && $salt_value && $id)
- {
- $user->get($id);
- if (User::validateLoginByOneClick($rid, $salt_value, $id))
- {
- //check user login without encoding password
- $error_code = User::performLogin($user->email, $user->password, User::APPLICATION_PUBLIC , false);
- }
- }
- else
- {
- if (TVC_Request::isParamSet("login"))
- {
- if(($login_time-1) >= Parameter::$params['NUMBER_OF_PASSWORD_ATTEMT'])
- {
- $error_captcha = Utils::validateCaptcha(TVC_Request::get('captcha'));
- if($error_captcha)
- {
- $error_code[] = $error_captcha;
- }
- }
- if(!$error_code)
- {
- //check user login.
- $error_code = User::performLogin($_POST["login"], $_POST["pwd"], User::APPLICATION_PUBLIC);
- }
- }
- }
- if (!TVC_Session::exist('user_serialize'))
- {
- $smarty->assign("login_time", $login_time+1);
- $smarty->assign("turn_on_captcha", ($login_time >= Parameter::$params['NUMBER_OF_PASSWORD_ATTEMT'])?1:0);
- //login fail
- $smarty->assign("return_link", $return_link);
- $smarty->assign("message_error", $error_code);
- $smarty->assign("login", (TVC_Request::isParamSet('login') ? TVC_Request::get('login') : ""));
- $smarty->display('home/login.html');
- }
- else
- {
- if (!$return_link)
- {
- TVC::redirect(APPLICATION_URL."/home/home");
- }
- else
- {
- TVC::redirect(APPLICATION_URL . $return_link);
- }
- }
- }
- /*
- * Log in
- */
- function loginDomainAction()
- {
- $available_lang = TVC_Config::get('I18N','AUTHORIZED_LANGUAGES');
- if (TVC_Request::isParamSet("SID"))
- {
- session_destroy();
- $SID = TVC_Request::getString('SID');
- session_id($SID);
- session_start();
- setcookie("from_other_site", "1", time() + 3600*24*30, "/", DOMAIN);
- // set language
- if((TVC_Request::isParamSet("lang"))
- && (in_array(TVC_Request::getString("lang"), $available_lang)))
- {
- $language = TVC_Request::getString("lang");
- }
- else
- {
- $language = TVC_Config::get('I18N','DEFAULT_LANGUAGE');
- }
- TVC::redirect(APPLICATION_URL."?language=".$language);
- }
- $reponse = array();
- if((TVC_Request::isParamSet("lang"))
- && (in_array(TVC_Request::getString("lang"), $available_lang)))
- {
- $language = TVC_Request::getString("lang");
- }
- else
- {
- $language = TVC_Config::get('I18N','DEFAULT_LANGUAGE');
- }
- Utils::setIniLang($language);
- if (TVC_Request::isParamSet("username"))
- {
- $error_code = User::performLogin(TVC_Request::getString('username'), TVC_Request::getString("password"), User::APPLICATION_PUBLIC);
- if (TVC_Session::exist('user_serialize'))
- {
- $reponse['status'] = 1;
- $reponse['result'] = APPLICATION_URL.'/login/loginDomain/SID/'.session_id().'?lang='.$language;
- }
- else
- {
- $reponse['status'] = 0;
- $error_label = array('_LB_USER_IS_NOT_ACTIVE' => _LB_USER_IS_NOT_ACTIVE,
- '_LB_NOT_GRANTED' => _LB_NOT_GRANTED,
- '_LB_INVALID_LOGIN_OR_PASSWORD' => _LB_INVALID_LOGIN_OR_PASSWORD
- );
- $reponse['result'] = $error_label[$error_code[0]];
- }
- }
- else
- {
- $reponse['status'] = 0;
- $reponse['result'] = _LB_NOT_GRANTED;
- }
- echo json_encode ($reponse);
- }
- /*
- * Logout
- */
- function logoutAction()
- {
- TVC_Session::remove();
- Utils::resetAccessAuthentical();
- TVC::redirect(URL_MASTER_BO."/login/logout");
- }
- public function logoutFromEDTAction()
- {
- TVC_Session::remove();
- Utils::resetAccessAuthentical();
- TVC::redirect(URL_MASTER_BO."/login/logoutFromPublic");
- }
- public function logoutFromADVAction()
- {
- TVC_Session::remove();
- Utils::resetAccessAuthentical();
- TVC::redirect(URL_EDITOR_BO."/login/logoutFromPublic");
- }
- /**
- * Register a new member
- */
- public function registerAction()
- {
- $smarty = TVC::load('smarty');
- $user = new User();
-
- $act = TVC_Request::getIntNumber('act');
- if($act)
- {
- if($user->validateInputRegister())
- {
- $user->password=sha1($user->password);
- $user->activation_code = sha1($user->password);
- $user->insert();
-
- //send activate email
- $user->sendActivateEmail($user->id, $user->first_name." ".$user->last_name,$user->email,TVC_Request::get('user_pass'),$user->activation_code,
- 'home/mails/subscribe-mail-'.TVC_MultiLanguage::getLanguage().'.tpl');
- TVC::redirect(APPLICATION_URL . '/login/notify');
- }
- }
-
- $language_code = TVC_Multilanguage::getLanguage();
-
- $sex = array(Parameter::MALE_SEX=>'_LB_MALE_SEX', Parameter::FEMALE_SEX=>'_LB_FEMALE_SEX', Parameter::NONE_SEX=>'_LB_NONE_SEX');
-
- $smarty->assign('backlink', APPLICATION_URL .'/login/login');
- $smarty->assign('sex', $sex);
- $smarty->assign('user', $user);
- $smarty->assign('lang', $language_code);
- $smarty->display('home/user_register.html');
- }
-
- public function activateAction()
- {
- $user = new User();
- $user->activateFromMail(TVC_Request::get('c'));
- TVC::redirect(APPLICATION_URL . '/login/login');
- }
- public function notifyAction()
- {
- $smarty = TVC::load('smarty');
- $smarty->display('home/registration_notice.html');
- }
- public function generateCaptchaAction()
- {
- return Utils::generateCAPTCHA();
- }
- public function forgotPasswordAction()
- {
- $smarty = TVC::load('smarty');
- $return_link = TVC_Request::get('return_link');
- $act = TVC_Request::get('act');
- $email = TVC_Request::get('email');
- $captcha = TVC_Request::get('captcha');
- $error_code = array();
- if($act)
- {
- //validate email
- if($email == "")
- {
- $error_code[] = '_LB_EMAIL_IS_EMPTY';
- }
- elseif(strlen($email) > Parameter::MAX_LENGTH_NAME || !Utils::checkEmailValid($email) || !User::checkUserExist($email, true))
- {
- $error_code[]='_LB_INVALID_EMAIL';
- }
- $error_captcha = Utils::validateCaptcha($captcha);
- if($error_captcha)
- {
- $error_code[] = $error_captcha;
- }
- if(count($error_code)==0)
- {
- $user = new User();
- $user->selectAdd();
- $user->selectAdd("user.id user_id, concat(first_name, ' ', last_name) name, email, password");
- $user->whereAdd("user.email='$email'");
- $user->find(true);
- //- Disable the user & update activation code
- $user->query("UPDATE user SET activation_code='".sha1($user->password)."' WHERE email='$email'");
- //- Send an Email with a private link (key)
- $user->sendActivateEmail($user->id_contact, $user->user_id, $user->name,$user->email,$user->password,$user->account_type,sha1($user->password),
- 'home/mails/forgot-password-mail-'.TVC_MultiLanguage::getLanguage().'.tpl', 1);
- $smarty->assign('sendMailSuccess', 1);
- }
- }
- $smarty->assign('return_link', $return_link);
- $smarty->assign('email', $email);
- $smarty->assign('capstr', $captcha);
- $smarty->assign("message_error", $error_code);
- $smarty->display('home/forgot_password.html');
- }
-
- /**
- * Check the user is exist
- * This function is called by AJAX
- *
- * @param String $email
- * @return boolean true is returned if the user is exist
- */
- public function checkEMailExist($email)
- {
- return User::checkEMailExist($email);
- }
- /**
- * Check the contact is exist
- * This function is called by AJAX
- *
- * @param String $name
- * @return boolean true is returned if the user is exist
- */
- public function checkNameExist($first_name, $last_name)
- {
- return User::checkNameExist($first_name, $last_name);
- }
-
- public function renewPasswordAction()
- {
- $smarty = TVC::load('smarty');
- $act=TVC_Request::get('act');
- $info_str=TVC_Request::get('c');
- $error_code = array();
- $user = new User();
- if($info_str)
- {
- $info = explode(",",base64_decode($info_str));
- $u_id = $info[1];
- $u_email = $info[2];
- $activation_code = $info[3];
- $user->id = $u_id;
- $user->id_contact = $cid;
- $user->email = trim($u_email);
- $user->activation_code = $activation_code;
- }
- if($act == 1)
- {
- $new_pwd = TVC_Request::get('new_pwd');
- $confirm_pwd = TVC_Request::get('confirm_pwd');
- //validate user password
- if($new_pwd == "")
- {
- $error_code[] = '_LB_PASSWORD_IS_EMPTY';
- }
- else if(strlen($new_pwd) > Parameter::MAX_LENGTH_PASSWORD)
- {
- $error_code[] = '_MSG_PASSWORD_IS_TOO_LONG';
- }
- else if(strlen($new_pwd) < Parameter::MIN_LENGTH_PASSWORD)
- {
- $error_code[] = '_MSG_PASSWORD_IS_TOO_SHORT';
- }
- else if($confirm_pwd != $new_pwd)
- {
- $error_code[] = '_LB_PASSWORD_DOESNT_MATCH';
- }
- if(count($error_code) == 0)
- {
- $user->password = sha1($new_pwd);
- $user->is_disabled = 0;
- $user->activation_code = '';
- $user->update();
- $smarty->assign('renewSuccess',1);
- }
- else
- {
- $smarty->assign('renewPassword',1);
- }
- $smarty->assign("message_error", $error_code);
- $smarty->display('home/renew_password.html');
- }
- else
- {
- if($user->find(true))
- {
- $smarty->assign("message_error", $error_code);
- $smarty->assign('renewPassword',1);
- $smarty->display('home/renew_password.html');
- }
- else
- {
- TVC::redirect(APPLICATION_URL . '/login/login');
- }
- }
- }
- }