コード例 #1
0
ファイル: joomla.php プロジェクト: educakanchay/kanchay
 /**
  * This method should handle any authentication and report back to the subject
  *
  * @param   array   $credentials  Array holding the user credentials
  * @param   array   $options      Array of extra options
  * @param   object  &$response    Authentication response object
  *
  * @return  boolean
  *
  * @since   1.5
  */
 public function onUserAuthenticate($credentials, $options, &$response)
 {
     $response->type = 'Joomla';
     // Joomla does not like blank passwords
     if (empty($credentials['password'])) {
         $response->status = JAuthentication::STATUS_FAILURE;
         $response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
         return false;
     }
     // Get a database object
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select('id, password')->from('#__users')->where('username='******'username']));
     $db->setQuery($query);
     $result = $db->loadObject();
     if ($result) {
         $match = JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id);
         if ($match === true) {
             // Bring this in line with the rest of the system
             $user = JUser::getInstance($result->id);
             $response->email = $user->email;
             $response->fullname = $user->name;
             if (JFactory::getApplication()->isAdmin()) {
                 $response->language = $user->getParam('admin_language');
             } else {
                 $response->language = $user->getParam('language');
             }
             $response->status = JAuthentication::STATUS_SUCCESS;
             $response->error_message = '';
         } else {
             // Invalid password
             $response->status = JAuthentication::STATUS_FAILURE;
             $response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
         }
     } else {
         // Invalid user
         $response->status = JAuthentication::STATUS_FAILURE;
         $response->error_message = JText::_('JGLOBAL_AUTH_NO_USER');
     }
     // Check the two factor authentication
     if ($response->status == JAuthentication::STATUS_SUCCESS) {
         require_once JPATH_ADMINISTRATOR . '/components/com_users/helpers/users.php';
         $methods = UsersHelper::getTwoFactorMethods();
         if (count($methods) <= 1) {
             // No two factor authentication method is enabled
             return;
         }
         require_once JPATH_ADMINISTRATOR . '/components/com_users/models/user.php';
         $model = new UsersModelUser();
         // Load the user's OTP (one time password, a.k.a. two factor auth) configuration
         if (!array_key_exists('otp_config', $options)) {
             $otpConfig = $model->getOtpConfig($result->id);
             $options['otp_config'] = $otpConfig;
         } else {
             $otpConfig = $options['otp_config'];
         }
         // Check if the user has enabled two factor authentication
         if (empty($otpConfig->method) || $otpConfig->method == 'none') {
             // Warn the user if he's using a secret code but he has not
             // enabed two factor auth in his account.
             if (!empty($credentials['secretkey'])) {
                 try {
                     $app = JFactory::getApplication();
                     $this->loadLanguage();
                     $app->enqueueMessage(JText::_('PLG_AUTH_JOOMLA_ERR_SECRET_CODE_WITHOUT_TFA'), 'warning');
                 } catch (Exception $exc) {
                     // This happens when we are in CLI mode. In this case
                     // no warning is issued
                     return;
                 }
             }
             return;
         }
         // Load the Joomla! RAD layer
         if (!defined('FOF_INCLUDED')) {
             include_once JPATH_LIBRARIES . '/fof/include.php';
         }
         // Try to validate the OTP
         FOFPlatform::getInstance()->importPlugin('twofactorauth');
         $otpAuthReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorAuthenticate', array($credentials, $options));
         $check = false;
         /*
          * This looks like noob code but DO NOT TOUCH IT and do not convert
          * to in_array(). During testing in_array() inexplicably returned
          * null when the OTEP begins with a zero! o_O
          */
         if (!empty($otpAuthReplies)) {
             foreach ($otpAuthReplies as $authReply) {
                 $check = $check || $authReply;
             }
         }
         // Fall back to one time emergency passwords
         if (!$check) {
             // Did the user use an OTEP instead?
             if (empty($otpConfig->otep)) {
                 if (empty($otpConfig->method) || $otpConfig->method == 'none') {
                     // Two factor authentication is not enabled on this account.
                     // Any string is assumed to be a valid OTEP.
                     return true;
                 } else {
                     /*
                      * Two factor authentication enabled and no OTEPs defined. The
                      * user has used them all up. Therefore anything he enters is
                      * an invalid OTEP.
                      */
                     return false;
                 }
             }
             // Clean up the OTEP (remove dashes, spaces and other funny stuff
             // our beloved users may have unwittingly stuffed in it)
             $otep = $credentials['secretkey'];
             $otep = filter_var($otep, FILTER_SANITIZE_NUMBER_INT);
             $otep = str_replace('-', '', $otep);
             $check = false;
             // Did we find a valid OTEP?
             if (in_array($otep, $otpConfig->otep)) {
                 // Remove the OTEP from the array
                 $otpConfig->otep = array_diff($otpConfig->otep, array($otep));
                 $model->setOtpConfig($result->id, $otpConfig);
                 // Return true; the OTEP was a valid one
                 $check = true;
             }
         }
         if (!$check) {
             $response->status = JAuthentication::STATUS_FAILURE;
             $response->error_message = JText::_('JGLOBAL_AUTH_INVALID_SECRETKEY');
         }
     }
 }
コード例 #2
0
ファイル: profile.php プロジェクト: naka211/befirstapp
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  mixed  The user id on success, false on failure.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id');
     $user = new JUser($userId);
     // Prepare the data for the user object.
     $data['email'] = JStringPunycode::emailToPunycode($data['email1']);
     $data['password'] = $data['password1'];
     // Unset the username if it should not be overwritten
     $username = $data['username'];
     $isUsernameCompliant = $this->getState('user.username.compliant');
     if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) {
         unset($data['username']);
     }
     // Unset the block so it does not get overwritten
     unset($data['block']);
     // Unset the sendEmail so it does not get overwritten
     unset($data['sendEmail']);
     // Handle the two factor authentication setup
     if (array_key_exists('twofactor', $data)) {
         $model = new UsersModelUser();
         $twoFactorMethod = $data['twofactor']['method'];
         // Get the current One Time Password (two factor auth) configuration
         $otpConfig = $model->getOtpConfig($userId);
         if ($twoFactorMethod != 'none') {
             // Run the plugins
             FOFPlatform::getInstance()->importPlugin('twofactorauth');
             $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod));
             // Look for a valid reply
             foreach ($otpConfigReplies as $reply) {
                 if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) {
                     continue;
                 }
                 $otpConfig->method = $reply->method;
                 $otpConfig->config = $reply->config;
                 break;
             }
             // Save OTP configuration.
             $model->setOtpConfig($userId, $otpConfig);
             // Generate one time emergency passwords if required (depleted or not set)
             if (empty($otpConfig->otep)) {
                 $oteps = $model->generateOteps($userId);
             }
         } else {
             $otpConfig->method = 'none';
             $otpConfig->config = array();
             $model->setOtpConfig($userId, $otpConfig);
         }
         // Unset the raw data
         unset($data['twofactor']);
         // Reload the user record with the updated OTP configuration
         $user->load($userId);
     }
     // Bind the data.
     if (!$user->bind($data)) {
         $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError()));
         return false;
     }
     // Load the users plugin group.
     JPluginHelper::importPlugin('user');
     // Null the user groups so they don't get overwritten
     $user->groups = null;
     // Store the data.
     if (!$user->save()) {
         $this->setError($user->getError());
         return false;
     }
     //T.Trung
     if (JRequest::getVar("picture", "", "string")) {
         $filename = sha1(uniqid()) . ".jpg";
         $decoded_img = base64_decode(JRequest::getVar("picture"));
         file_put_contents(JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'plg_user_profilepicture' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'original' . DIRECTORY_SEPARATOR . $filename, $decoded_img);
         file_put_contents(JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'plg_user_profilepicture' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . '200' . DIRECTORY_SEPARATOR . $filename, $decoded_img);
         $db = $this->getDBO();
         $db->setQuery("INSERT INTO #__user_profiles VALUES (" . $user->id . ", 'profilepicture.file', '" . $filename . "', 1)");
         $db->execute();
     }
     //T.Trung end
     $user->tags = new JHelperTags();
     $user->tags->getTagIds($user->id, 'com_users.user');
     return $user->id;
 }
コード例 #3
0
ファイル: profile.php プロジェクト: WineWorld/joomlatrialcmbg
 /**
  * Method to save the form data.
  *
  * @param   array  The form data.
  * @return  mixed  	The user id on success, false on failure.
  * @since   1.6
  */
 public function save($data)
 {
     $userId = !empty($data['id']) ? $data['id'] : (int) $this->getState('user.id');
     $user = new JUser($userId);
     // Prepare the data for the user object.
     $data['email'] = JStringPunycode::emailToPunycode($data['email1']);
     $data['password'] = $data['password1'];
     // Unset the username if it should not be overwritten
     $username = $data['username'];
     $isUsernameCompliant = $this->getState('user.username.compliant');
     if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) {
         unset($data['username']);
     }
     // Unset the block so it does not get overwritten
     unset($data['block']);
     // Unset the sendEmail so it does not get overwritten
     unset($data['sendEmail']);
     // handle the two factor authentication setup
     if (array_key_exists('twofactor', $data)) {
         $model = new UsersModelUser();
         $twoFactorMethod = $data['twofactor']['method'];
         // Get the current One Time Password (two factor auth) configuration
         $otpConfig = $model->getOtpConfig($userId);
         if ($twoFactorMethod != 'none') {
             // Run the plugins
             FOFPlatform::getInstance()->importPlugin('twofactorauth');
             $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod));
             // Look for a valid reply
             foreach ($otpConfigReplies as $reply) {
                 if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) {
                     continue;
                 }
                 $otpConfig->method = $reply->method;
                 $otpConfig->config = $reply->config;
                 break;
             }
             // Save OTP configuration.
             $model->setOtpConfig($userId, $otpConfig);
             // Generate one time emergency passwords if required (depleted or not set)
             if (empty($otpConfig->otep)) {
                 $oteps = $model->generateOteps($userId);
             }
         } else {
             $otpConfig->method = 'none';
             $otpConfig->config = array();
             $model->setOtpConfig($userId, $otpConfig);
         }
         // Unset the raw data
         unset($data['twofactor']);
         // Reload the user record with the updated OTP configuration
         $user->load($userId);
     }
     // Bind the data.
     if (!$user->bind($data)) {
         $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError()));
         return false;
     }
     // Load the users plugin group.
     JPluginHelper::importPlugin('user');
     // Null the user groups so they don't get overwritten
     $user->groups = null;
     // Store the data.
     if (!$user->save()) {
         $this->setError($user->getError());
         return false;
     }
     $user->tags = new JHelperTags();
     $user->tags->getTagIds($user->id, 'com_users.user');
     return $user->id;
 }
コード例 #4
0
ファイル: profile.php プロジェクト: joshjim27/jobsglobal
 public function save()
 {
     // Check for request forgeries
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
     JFactory::getLanguage()->load(COM_USER_NAME);
     $user = JFactory::getUser();
     $userid = $jinput->post->get('id', 0, 'int');
     // preform security checks
     if ($user->get('id') == 0 || $userid == 0 || $userid != $user->get('id')) {
         echo $this->blockUnregister();
         return;
     }
     $username = $user->get('username');
     //if joomla settings allow change login name
     if (JComponentHelper::getParams('com_users')->get('change_login_name')) {
         $username = $jinput->get('username');
     }
     //clean request
     $post = JRequest::get('post');
     $post['username'] = $username;
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //check email
     $post['email'] = $post['jsemail'];
     $email = $post['email'];
     $emailPass = $post['emailpass'];
     $modelReg = $this->getModel('register');
     //CFactory::load( 'helpers', 'validate' );
     if (!CValidateHelper::email($email)) {
         $msg = JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $email);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     if (!empty($email) && $email != $emailPass && $modelReg->isEmailExists(array('email' => $email))) {
         $msg = JText::sprintf('COM_COMMUNITY_EMAIL_EXIST', $email);
         $msg = stripslashes($msg);
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
         return false;
     }
     // get the redirect
     $return = CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false);
     // do a password safety check
     $changePassword = false;
     if (JString::strlen($post['jspassword']) || JString::strlen($post['jspassword2'])) {
         // so that "0" can be used as password e.g.
         if ($post['jspassword'] != $post['jspassword2']) {
             $msg = JText::_('PASSWORDS_DO_NOT_MATCH');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error');
             return false;
         } else {
             $changePassword = true;
             //Jooomla 3.2.0 fix. TO be remove in future
             if (version_compare(JVERSION, '3.2.0', '>=')) {
                 $salt = JUserHelper::genRandomPassword(32);
                 $crypt = JUserHelper::getCryptedPassword($post['jspassword'], $salt);
                 $password = $crypt . ':' . $salt;
             } else {
                 // Don't re-encrypt the password
                 // JUser bind has encrypted the password
                 if (class_exists(JUserHelper) && method_exists(JUserHelper, 'hashpassword')) {
                     $password = JUserHelper::hashPassword($post['jspassword']);
                 } else {
                     $password = $post['jspassword'];
                 }
             }
         }
     }
     // Handle the two factor authentication setup
     $data = $post['jform'];
     if (array_key_exists('twofactor', $data)) {
         if (!class_exists('UsersModelUser')) {
             require JPATH_ROOT . '/administrator/components/com_users/models/user.php';
         }
         $model = new UsersModelUser();
         $twoFactorMethod = $data['twofactor']['method'];
         $userId = CFactory::getUser()->id;
         // Get the current One Time Password (two factor auth) configuration
         $otpConfig = $model->getOtpConfig($userId);
         if ($twoFactorMethod != 'none') {
             // Run the plugins
             FOFPlatform::getInstance()->importPlugin('twofactorauth');
             $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod));
             // Look for a valid reply
             foreach ($otpConfigReplies as $reply) {
                 if (!is_object($reply) || empty($reply->method) || $reply->method != $twoFactorMethod) {
                     continue;
                 }
                 $otpConfig->method = $reply->method;
                 $otpConfig->config = $reply->config;
                 break;
             }
             // Save OTP configuration.
             $model->setOtpConfig($userId, $otpConfig);
             // Generate one time emergency passwords if required (depleted or not set)
             if (empty($otpConfig->otep)) {
                 $oteps = $model->generateOteps($userId);
             }
         } else {
             $otpConfig->method = 'none';
             $otpConfig->config = array();
             $model->setOtpConfig($userId, $otpConfig);
         }
         // Unset the raw data
         unset($data['twofactor']);
     }
     // we don't want users to edit certain fields so we will unset them
     unset($post['gid']);
     unset($post['block']);
     unset($post['usertype']);
     unset($post['registerDate']);
     unset($post['activation']);
     //update CUser param 1st so that the new value will not be replace wif the old one.
     $my = CFactory::getUser();
     $params = $my->getParams();
     $postvars = $post['daylightsavingoffset'];
     $params->set('daylightsavingoffset', $postvars);
     // Store FB prefernce o ly FB connect data
     $connectModel = CFactory::getModel('Connect');
     if ($connectModel->isAssociated($user->id)) {
         $postvars = !empty($post['postFacebookStatus']) ? 1 : 0;
         $my->_cparams->set('postFacebookStatus', $postvars);
     }
     if ($changePassword) {
         $my->set('password', $password);
     }
     /* Save for CUser */
     $my->save();
     $model = CFactory::getModel('profile');
     $editSuccess = true;
     $msg = JText::_('COM_COMMUNITY_SETTINGS_SAVED');
     $jUser = JFactory::getUser();
     // Bind the form fields to the user table
     if (!$jUser->bind($post)) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     // Store the web link table to the database
     if (!$jUser->save()) {
         $msg = $jUser->getError();
         $editSuccess = false;
     }
     if ($editSuccess) {
         /* Update Joomla! User session */
         $session = JFactory::getSession();
         $session->set('user', $jUser);
         // User with FB Connect, store post preference
         //execute the trigger
         $appsLib = CAppPlugins::getInstance();
         $appsLib->loadApplications();
         $userRow = array();
         $userRow[] = $jUser;
         $appsLib->triggerEvent('onUserDetailsUpdate', $userRow);
     }
     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=edit', false), $msg);
 }