PATH:
home
/
letacommog
/
letaweb
/
admin
/
classes
/
components
<?php class authorizationComponent { public $user_id; public $user; public $guest_id; public $logged = false; protected $enabled; protected $loginPage_filename = 'login'; protected $profile_page_filename = 'my_account'; protected $signup_page_filename = 'signup'; protected $loginPage; protected $profile_page; protected $signup_page; public $logout_param = 'logout'; public $lost_password_param = 'getpassword'; public $recover_password_param = 'recover'; public $active_email_param = 'active'; public $send_active_email_param = 'sendActiveEmail'; public function init() { //fAuthorization::setLoginPage(URL::get_css_path().'/module.php?name=login'); $this->initPage(); //$this->cookie_login(); } public function isEnabled() { if (isset($this->enabled)) { return $this->enabled; } $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->loginPage_filename)); if (!isset($b)) { $this->$enabled = false; return false; } $this->enabled = true; return $this->enabled; } public function initPage() { $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->loginPage_filename)); if (isset($b)) { $this->loginPage = $b['name']; } $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->profile_page_filename)); if (isset($b)) { $this->profile_page = $b['name']; } $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->signup_page_filename)); if (isset($b)) { $this->signup_page = $b['name']; } } public function getLoginPage() { if (isset($this->$loginPage)) { return $this->$loginPage; } $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->loginPage_filename)); if (isset($b)) { $this->loginPage = $b['name']; } else { $this->loginPage = $this->loginPage_filename; } return $this->loginPage; } public function getLostPasswordParam() { return $this->lost_password_param; } public function getLogoutParam() { return $this->logout_param; } public function getSignupPage() { if (isset($this->signup_page)) { return $this->signup_page; } global $db; $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->signup_page_filename)); if (isset($b)) { $this->signup_page = $b['name']; } else { $this->signup_page = $this->signup_page_filename; } return $this->$signup_page; } public function getProfilePage() { if (isset($this->profile_page)) { return $this->profile_page; } $b = BPages::model()->find('file_name=:file_name', array(':file_name' => $this->profile_page_filename)); if (isset($b)) { $this->profile_page = $b['name']; } else { $this->profile_page = $this->profile_page_filename; } return $this->profile_page; } public function getRecoverPasswordParam() { return $this->recover_password_param; } public function getActiveEmailParam() { return $this->active_email_param; } public function getSendActiveEmailParam() { return $this->send_active_email_param; } public function getReturnUrl($clear = true, $default_url = null) { $returnUrl = Yii::app()->returnUrl; return $returnUrl; } public function isLogged() { return !Yii::app()->user->isGuest; } protected function setUser($user) { $this->user = $user; } public function getUser() { $user_id = Yii::app()->user->id; return BUsers::model()->findByPk($user_id); } protected function setUser_id($user_id) { //fSession::set(__CLASS__ . '::user_id', $user_id); $this->user_id = $user_id; } public function getUser_id() { return Yii::app()->user->id; } public function setReturnUrl($url) { } private function redirect() { Yii::app()->url->redirectPage($this->getLoginPage()); } public function logout() { } public function login($email, $passwd, $remember = false) { global $db; $cookie = Yii::app()->request->cookie; $user = new BUsers(array('email' => $email)); if ($user->exists() && $user->getIs_active() == 1) { if (!fCryptography::checkPasswordHash($passwd, $user->getPassword_hash())) { throw new fValidationException(Language::get('TEXT_EMAIL_OR_PASSWORD_INCORRECT')); } if ($remember) { $cookie->user_id = $user->getId(); $cookie->passwd = $passwd; } $this->setUser_id($user->getId()); $this->setUser($user); $this->setLogged(true); return $user->getId(); } elseif ($user->exists() && $user->getIs_active() == 0) { $Users_Email = new Users_Email($user->getId()); if ($Users_Email->exists()) { throw new fValidationException(Language::get('TEXT_EMAIL_OR_PASSWORD_INCORRECT')); } else { throw new fValidationException(Language::get('TEXT_EMAIL_OR_PASSWORD_INCORRECT')); } } else { throw new fValidationException(Language::get('TEXT_EMAIL_OR_PASSWORD_INCORRECT')); } return false; } public function active($id, $code) { $user = new User($id); if (!$user->exists()) { throw new fValidationException(Language::get('TEXT_ACTIVE_USER_USER_NOT_EXISTS_ERROR')); } elseif ($user->getIs_active() == 1) { throw new fValidationException(Language::get('TEXT_ACTIVE_USER_USER_ALREADY_ACTIVE_ERROR')); } $c = trim($code); $user_email = new Users_Email($id); if (!$user_email->exists()) { throw new fValidationException(Language::get('TEXT_ACTIVE_USER_HAS_BEEN_BAN_VALID_ERROR')); } elseif (strcmp($user_email->getCode(), $c) != 0) { throw new fValidationException(Language::get('TEXT_ACTIVE_USER_CODE_ACTIVE_NOT_VALID_ERROR')); } $user->setIs_active(1); $user_email->delete(); return true; } public function recover($id, $code) { $user = new User($id); if (!$user->exists()) { throw new fValidationException(Language::get('TEXT_RECOVER_USER_USER_NOT_EXISTS_ERROR')); } elseif ($user->getIs_active() == 1) { throw new fValidationException(Language::get('TEXT_RECOVER_USER_USER_ALREADY_ACTIVE_ERROR')); } $c = trim($code); $Users_Password_Recover = new Users_Password_Recover($id); if (!$Users_Password_Recover->exists()) { throw new fValidationException(Language::get('TEXT_RECOVER_USER_HAS_BEEN_BAN_VALID_ERROR')); } else { $e = $Users_Password_Recover->getDate_expired(); $n = date('Y-m-d h:i:s'); if ($e->gt($n)) { throw new fValidationException(Language::get('TEXT_RECOVER_USER_LINK_EXPIRE_ERROR')); } elseif (strcmp($Users_Password_Recover->getCode(), $c) != 0) { throw new fValidationException(Language::get('TEXT_RECOVER_USER_CODE_ACTIVE_NOT_VALID_ERROR')); } } $send_recover_email = Configuration::get('USER_RECOVER_PASSWORD_SEND_RECOVER_EMAIL'); $new_pass = $this->createEmailCode(23); $user->setPassword_hash(fCryptography::hashPassword($new_pass)); if ($send_recover_email) { $this->sendRecoverPasswordEmail($id, $new_pass); } $Users_Password_Recover->delete(); return $new_pass; } public function register($email, $passwd, $first_name, $last_name = '') { global $db; $cookie = Context::getContext()->cookie; $check_email = $db->query('select * from '.$db->getTablename('users').' where email=\''.$email.'\'')->fetchAllRows(); if (sizeof($check_email) != 0) { throw new fValidationException(Language::get('TEXT_SIGNUP_EMAIL_EXISTS_ERROR')); } if ($last_name == '') { $name = str_replace(' ', ' ', $first_name); $parts = explode(' ', $name); $name_first = array_shift($parts); $name_last = array_pop($parts); $name_middle = trim(implode(' ', $parts)); } else { $name_first = $first_name; $name_last = $last_name; $name_middle = ''; } $user = new User(); $user->setFirst_name($name_first); $user->setLast_name($name_last); $user->setMiddle_name($name_middle); $user->setEmail($email); $USER_REGISTER_ACTIVE_BY_EMAIL = Configuration::get('USER_REGISTER_ACTIVE_BY_EMAIL'); if ($USER_REGISTER_ACTIVE_BY_EMAIL) { $user->setIs_active(0); } else { $user->setIs_active(1); } $user->setPassword_hash(fCryptography::hashPassword($passwd)); $user->store(); $id = $user->getId(); $USER_REGISTER_LOGIN_AFTER_REGISTER = Configuration::get('USER_REGISTER_LOGIN_AFTER_REGISTER'); if ($USER_REGISTER_ACTIVE_BY_EMAIL) { $Users_Email = new Users_Email(); $Users_Email->setUser_id($id); $Users_Email->setCode($this->createEmailCode(16)); $Users_Email->store(); Mail::sendSystemCustomerEmail('signup_active_email', $email, array('full_name' => $full_name, 'email' => $email, 'password' => $passwd, 'url' => $this->createActiveEmailUrl($id))); } else { if ($USER_REGISTER_LOGIN_AFTER_REGISTER) { $this->setUser_id($id); $this->setUser($user); $this->setLogged(true); } Mail::sendCustomerEmail('signup_completed', $email, array('full_name' => $user->getName(), 'email' => $email, 'password' => $passwd)); } return $id; } public function login_required() { if (!$this->isLogged()) { $this->redirect(); } } public function cookie_login() { if ($this->isLogged()) { return false; } $cookie = Context::getContext()->cookie; if (isset($cookie->user_id)) { $password = $cookie->passwd; $user = new User($cookie->user_id); if ($user->exists()) { if (!fCryptography::checkPasswordHash($password, $user->getPassword_hash())) { return false; } $this->setUser_id($user->getId()); $this->setUser($user); $this->setLogged(true); return true; } return false; } } public function checkPassword($id, $password) { global $db; $user = new User($id); if ($user->exists() && $user->getIs_active() == 1) { if (!fCryptography::checkPasswordHash($password, $user->getPassword_hash())) { return true; } } return false; } public function validatePasswordField($pf, $validator) { $password_upperCase = Configuration::get('USER_REGISTER_PASSWORD_MUST_CONTAIN_UPPER_CHARACTER'); $password_lowerCase = Configuration::get('USER_REGISTER_PASSWORD_MUST_CONTAIN_LOWER_CHARACTER'); $password_special = Configuration::get('USER_REGISTER_PASSWORD_MUST_CONTAIN_NONE_ALPHABET'); $password_digit = Configuration::get('USER_REGISTER_PASSWORD_MUST_CONTAIN_BASE_10_DIGITS'); $password_minLength = Configuration::get('USER_REGISTER_PASSWORD_MIN_LENGTH'); if ($password_minLength === false) { $password_minLength = 0; } $password_complexity = array('passwordUpperCase' => $password_upperCase,'passwordLowerCase' => $password_lowerCase,'passwordSpecial' => $password_special, 'passwordDigit' => $password_digit); $password_complexity_ext = array('passwordUpperCase' => array('exp' => '/[A-Z]/','lang' => 'TEXT_PASSWORD_MUST_CONTAIN_UPPERCASE_IN_VALIDATION'),'passwordLowerCase' => array('exp' => '/[a-z]/','lang' => 'TEXT_PASSWORD_MUST_CONTAIN_LOWERCASE_IN_VALIDATION'),'passwordSpecial' => array('exp' => '/[^a-zA-Z0-9]/','lang' => 'TEXT_PASSWORD_MUST_CONTAIN_SPECIAL_IN_VALIDATION'), 'passwordDigit' => array('exp' => '/[0-9]/','lang' => 'TEXT_PASSWORD_MUST_CONTAIN_DIGIT_IN_VALIDATION')); $validator->addCallbackRule($pf, 'check_password_length', sprintf(Language::get('TEXT_PASSWORD_MUST_HAVE_MINLENGTH_IN_VALIDATION'), $password_minLength)); foreach ($password_complexity as $k => $v) { if ($password_complexity[$k]) { $validator->addRegexRule($pf, $password_complexity_ext[$k]['exp'], Language::get($password_complexity_ext[$k]['lang'])); } } } protected function createEmailCode($l) { $chars = 'abcdefghijkmnopqrstuvwxyz023456789'; srand((double) microtime() * 1000000); $i = 0; $pass = ''; while ($i <= $l) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass.$tmp; ++$i; } return $pass; } protected function createActiveEmailUrl($id) { $user = new User($id); $user_email = new Users_Email($id); return URL::createPageURL(Authorization::getLoginPage(), array('action' => Authorization::getActiveEmailParam(), 'id' => $id, 'code' => $user_email->getCode())); } protected function sendRecoverPasswordEmail($id, $passwd) { $user = new User($id); Mail::sendSystemCustomerEmail('signup_recover_email', $email, array('full_name' => $user->getName(), 'email' => $$user->getEmail(), 'password' => $passwd)); } protected function createRecoverEmailUrl($id) { $user = new User($id); $Users_Password_Recover = new Users_Password_Recover(); $Users_Password_Recover->setUser_id($id); $Users_Password_Recover->setCode($this->createEmailCode(16)); $date = date(); $recover_link_timeout = Configuration::get('USER_RECOVER_PASSWORD_LINK_TIMEOUT'); if ($recover_link_timeout === false) { $recover_link_timeout = 24; } $recover_link_timeout_t = ' +'.$recover_link_timeout.' hours'; if ($recover_link_timeout <= 1) { $recover_link_timeout_t = ' +'.$recover_link_timeout.' hour'; } $date = date('Y-m-d h:i:s', strtotime($date.$recover_link_timeout_t)); $Users_Password_Recover->setDate_expired($date); $Users_Password_Recover->store(); return URL::createPageURL('login', array('action' => Authorization::getRecoverPasswordParam(), 'id' => $id, 'code' => $Users_Password_Recover->getCode())); } public function sendActiveEmail($id) { $user = new User($id); $user_email = new Users_Email($id); Mail::sendSystemCustomerEmail('signup_active_email', $email, array('full_name' => $user->getName(), 'email' => $$user->getEmail(), 'password' => $passwd, 'url' => $this->createActiveEmailUrl($id))); } public function sendRecoverEmail($email) { $user = new User(array('email' => $email)); if (!$user->exists()) { throw new fValidationException(Language::get('TEXT_ACTIVE_USER_USER_NOT_EXISTS_ERROR')); } elseif ($user->getIs_active() == 0) { throw new fValidationException(Language::get('TEXT_ACTIVE_USER_USER_ALREADY_ACTIVE_ERROR')); } Mail::sendSystemCustomerEmail('signup_recover_email', $email, array('full_name' => $user->getName(), 'email' => $$user->getEmail(), 'url' => $this->createRecoverEmailUrl($id))); } }
[+]
..
[-] colorComponent.php
[edit]
[-] authorizationComponent.php
[edit]
[-] hostingComponent.php
[edit]
[-] configComponent.php
[edit]
[-] siteComponent.php
[edit]
[-] urlComponent.php
[edit]
[-] paymentComponent.php
[edit]
[-] authManager.php
[edit]
[-] guestComponent.php
[edit]
[-] cmsComponent.php
[edit]
[-] languageComponent.php
[edit]
[-] contextComponent.php
[edit]
[-] cartComponent.php
[edit]
[-] customerComponent.php
[edit]