Example #1
0
 /**
  * Populate global variables with information about the currently logged in user.
  *
  * Will set the current user, if the current user is not set. The current user
  * will be set to the logged in person. If no user is logged in, then it will
  * set the current user to 0, which is invalid and won't have any permissions.
  *
  * @since 0.71
  * @uses $current_user Checks if the current user is set
  * @uses nxt_validate_auth_cookie() Retrieves current logged in user.
  *
  * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set
  */
 function get_currentuserinfo()
 {
     global $current_user;
     if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
         return false;
     }
     if (!empty($current_user)) {
         return;
     }
     if (!($user = nxt_validate_auth_cookie())) {
         if (is_blog_admin() || is_network_admin() || empty($_COOKIE[LOGGED_IN_COOKIE]) || !($user = nxt_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in'))) {
             nxt_set_current_user(0);
             return false;
         }
     }
     nxt_set_current_user($user);
 }
 /**
  * Log user in.
  *
  * @since 2.8
  *
  * @param string $username User's username.
  * @param string $password User's password.
  * @return mixed nxt_User object if authentication passed, false otherwise
  */
 function login($username, $password)
 {
     if (!get_option('enable_xmlrpc')) {
         $this->error = new IXR_Error(405, sprintf(__('XML-RPC services are disabled on this site.  An admin user can enable them at %s'), admin_url('options-writing.php')));
         return false;
     }
     $user = nxt_authenticate($username, $password);
     if (is_nxt_error($user)) {
         $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
         return false;
     }
     nxt_set_current_user($user->ID);
     return $user;
 }
 /**
  * Changes the current user by ID or name.
  *
  * Set $id to null and specify a name if you do not know a user's ID.
  *
  * @since 2.0.1
  * @see nxt_set_current_user() An alias of nxt_set_current_user()
  * @deprecated 3.0.0
  * @deprecated Use nxt_set_current_user()
  *
  * @param int|null $id User ID.
  * @param string $name Optional. The user's username
  * @return object returns nxt_set_current_user()
  */
 function set_current_user($id, $name = '')
 {
     _deprecated_function(__FUNCTION__, '3.0', 'nxt_set_current_user()');
     return nxt_set_current_user($id, $name);
 }
Example #4
0
 function set_user($user_id)
 {
     if (is_numeric($user_id)) {
         $user_id = (int) $user_id;
     } else {
         $user_id = (int) username_exists($user_id);
     }
     if (!$user_id || !nxt_set_current_user($user_id)) {
         fwrite(STDERR, "Error: can not find user\n");
         exit;
     }
     return $user_id;
 }