/** * custom log in functionality, from custom log in page */ static function login() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'login')) { return; } if (is_email($_POST['email'])) { $user = get_user_by('email', $_POST['email']); if (empty($user)) { Kanban_Flash::flash(__('Whoops! We can\'t find an account for that email address.', 'kanban'), 'danger'); wp_redirect($_POST['_wp_http_referer']); exit; } } else { $user = get_user_by('login', $_POST['email']); if (empty($user)) { Kanban_Flash::flash(__('Whoops! We can\'t find an account for that username.', 'kanban'), 'danger'); wp_redirect($_POST['_wp_http_referer']); exit; } } $creds = array(); $creds['user_login'] = $user->user_login; $creds['user_password'] = $_POST['password']; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { Kanban_Flash::flash(__('Whoops! That password is incorrect for this email address.', 'kanban'), 'danger'); wp_redirect($_POST['_wp_http_referer']); exit; } wp_set_current_user($user->ID); wp_set_auth_cookie($user->ID); wp_redirect(sprintf('%s/%s/board', site_url(), Kanban::$slug)); exit; }
function loginUser($email, $password) { if ($email !== null && $password !== null) { /** * @var \WegeTech\LottoYard\Service $lottoService */ global $lottoService; $credentials = array(); $credentials['user_login'] = $email; $credentials['user_password'] = $password; $credentials['remember'] = true; $user = wp_signon($credentials, false); if (is_wp_error($user)) { wp_send_json(array('data' => $user->get_error_message())); } else { $userData = new User(); $lottoPass = get_user_meta($user->id, 'lottoPass', true); $userData->Email = $email; $userData->Password = $lottoPass; $response = $lottoService->loginUser($userData); session_start(); $_SESSION['userData'] = $response->data; if ($response->success) { header('Location: http://wpjl.2hypnotize.com/'); } else { wp_send_json(array('data' => $response->message)); } } } }
function check_login() { $user = $this->share_session(); if ($user) { wp_signon(array('user_login' => $user->username, 'user_password' => 'whatever')); } }
public function process_registration() { do_action('popmake_alm_ajax_override_registration'); $user_login = $_POST['user_login']; $user_email = $_POST['user_email']; $user_pass = isset($_POST['user_pass']) ? $_POST['user_pass'] : wp_generate_password(12, false); $userdata = compact('user_login', 'user_email', 'user_pass'); $user = wp_insert_user($userdata); if (!isset($_POST['user_pass'])) { update_user_option($user, 'default_password_nag', true, true); // Set up the Password change nag. wp_new_user_notification($user, $user_pass); } if (is_wp_error($user)) { $response = array('success' => false, 'message' => $user->get_error_message()); } else { if (popmake_get_popup_ajax_registration($_POST['popup_id'], 'enable_autologin')) { $creds = array('user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true); $user = wp_signon($creds); } $message = __('Registration complete.', 'popup-maker-ajax-login-modals'); if (!isset($_POST['user_pass'])) { $message .= ' ' . __('Please check your e-mail.', 'popup-maker-ajax-login-modals'); } $response = array('success' => true, 'message' => $message); } echo json_encode($response); die; }
function rcl_get_login_user() { global $wp_errors; $pass = sanitize_text_field($_POST['user_pass']); $login = sanitize_user($_POST['user_login']); $member = isset($_POST['rememberme']) ? intval($_POST['rememberme']) : 0; $url = esc_url($_POST['redirect_to']); $wp_errors = new WP_Error(); if (!$pass || !$login) { $wp_errors->add('rcl_login_empty', __('Fill in the required fields!', 'wp-recall')); return $wp_errors; } if ($user = get_user_by('login', $login)) { $user_data = get_userdata($user->ID); $roles = $user_data->roles; $role = array_shift($roles); if ($role == 'need-confirm') { $wp_errors->add('rcl_login_confirm', __('Your email is not confirmed!', 'wp-recall')); return $wp_errors; } } $creds = array(); $creds['user_login'] = $login; $creds['user_password'] = $pass; $creds['remember'] = $member; $user = wp_signon($creds, false); if (is_wp_error($user)) { $wp_errors = $user; return $wp_errors; } else { rcl_update_timeaction_user(); wp_redirect(rcl_get_authorize_url($user->ID)); exit; } }
/** * Logs in the user * * Logs in the the user using wp_signon (since 2.5.2). If login * is successful, it redirects and exits; otherwise "loginfailed" * is returned. * * @since 0.1 * * @uses apply_filters Calls 'wpmem_login_redirect' hook to get $redirect_to * * @uses wp_signon * @uses wp_redirect Redirects to $redirect_to if login is successful * @return string Returns "loginfailed" if the login fails */ function wpmem_login() { if (isset($_POST['redirect_to'])) { $redirect_to = $_POST['redirect_to']; } else { $redirect_to = $_SERVER['PHP_SELF']; } $redirect_to = apply_filters('wpmem_login_redirect', $redirect_to); if (isset($_POST['rememberme']) == 'forever') { $rememberme = true; } else { $rememberme = false; } if ($_POST['log'] && $_POST['pwd']) { $user_login = sanitize_user($_POST['log']); $user_login = wpmem_login_check_for_email($user_login); $creds = array(); $creds['user_login'] = $user_login; $creds['user_password'] = $_POST['pwd']; $creds['remember'] = $rememberme; $user = wp_signon($creds, false); if (!is_wp_error($user)) { if (!$using_cookie) { wp_setcookie($user_login, $user_pass, false, '', '', $rememberme); } wp_redirect($redirect_to); exit; } else { return "loginfailed"; } } else { //login failed return "loginfailed"; } }
function wppb_signon() { global $error; global $wppb_login; global $wpdb; $wppb_generalSettings = get_option('wppb_general_settings'); if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'log-in' && wp_verify_nonce($_POST['login_nonce_field'], 'verify_true_login') && $_POST['formName'] == 'login') { $remember = isset($_POST['remember-me']) && trim($_POST['remember-me'] != '') ? true : false; // if this setting is active, the posted username is, in fact the user's email if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { $username = $wpdb->get_var($wpdb->prepare("SELECT user_login FROM {$wpdb->users} WHERE user_email= %s LIMIT 1", trim($_POST['user-name']))); if ($username == NULL) { $username = trim($_POST['user-name']); } } else { $username = trim($_POST['user-name']); } $wppb_login = wp_signon(array('user_login' => $username, 'user_password' => trim($_POST['password']), 'remember' => $remember), false); } elseif (isset($_GET['userName']) && isset($_GET['passWord'])) { $password = base64_decode(trim($_GET['passWord'])); // if this setting is active, the posted username is, in fact the user's email if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { $username = $wpdb->get_var($wpdb->prepare("SELECT user_login FROM {$wpdb->users} WHERE user_email= %s LIMIT 1", $username)); } $wppb_login = wp_signon(array('user_login' => $username, 'user_password' => base64_decode(trim($_GET['passWord'])), 'remember' => true), false); } }
function jr_process_login_form() { global $posted; if (isset($_REQUEST['redirect_to'])) { $redirect_to = $_REQUEST['redirect_to']; } else { $redirect_to = admin_url(); } if (is_ssl() && force_ssl_login() && !force_ssl_admin() && 0 !== strpos($redirect_to, 'https') && 0 === strpos($redirect_to, 'http')) { $secure_cookie = false; } else { $secure_cookie = ''; } $user = wp_signon('', $secure_cookie); $redirect_to = apply_filters('login_redirect', $redirect_to, isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '', $user); if (!is_wp_error($user)) { if (user_can($user, 'manage_options')) { $redirect_to = admin_url(); } wp_safe_redirect($redirect_to); exit; } $errors = $user; return $errors; }
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; }
function rcl_confirm_user_registration() { global $wpdb, $rcl_options; $reglogin = $_GET['rglogin']; $regpass = $_GET['rgpass']; $regcode = md5($reglogin); if ($regcode == $_GET['rgcode']) { if ($user = get_user_by('login', $reglogin)) { wp_update_user(array('ID' => $user->ID, 'role' => get_option('default_role'))); $time_action = current_time('mysql'); $action = $wpdb->get_var($wpdb->prepare("SELECT time_action FROM " . RCL_PREF . "user_action WHERE user = '******'", $user->ID)); if (!$action) { $wpdb->insert(RCL_PREF . 'user_action', array('user' => $user->ID, 'time_action' => $time_action)); } $creds = array(); $creds['user_login'] = $reglogin; $creds['user_password'] = $regpass; $creds['remember'] = true; $sign = wp_signon($creds, false); if (!is_wp_error($sign)) { rcl_update_timeaction_user(); do_action('rcl_confirm_registration', $user->ID); wp_redirect(rcl_get_authorize_url($user->ID)); exit; } } } if ($rcl_options['login_form_recall'] == 2) { wp_safe_redirect('wp-login.php?checkemail=confirm'); } else { wp_redirect(get_bloginfo('wpurl') . '?action-rcl=login&error=confirm'); } exit; }
/** * Processes credentials to pass into wp_signon to log a user into WordPress. * * @uses check_ajax_referer() * @uses wp_signon() * @uses is_wp_error() * * @param $user_login (string) Defaults to $_POST['user_login'] * @param $password (string) * @param $is_ajax (bool) Process as an AJAX request * @package AJAX * * @return userlogin on success; 0 on false; */ public function login_submit($user_login = null, $password = null, $is_ajax = true) { /** * Verify the AJAX request */ if ($is_ajax) { check_ajax_referer('login_submit', 'security'); } $username = empty($_POST['user_login']) ? $user_login : sanitize_text_field($_POST['user_login']); $password = empty($_POST['password']) ? $password : sanitize_text_field($_POST['password']); $remember = !empty($_POST['rememberme']) ? true : false; // Currently wp_signon returns the same error code 'invalid_username' if // a username does not exists or is invalid if (validate_username($username)) { if (username_exists($username)) { $creds = array('user_login' => $username, 'user_password' => $password, 'remember' => $remember); $user = wp_signon($creds, false); $status = is_wp_error($user) ? $this->status($user->get_error_code()) : $this->status('success_login'); } else { $status = $this->status('username_does_not_exists'); } } else { $status = $this->status('invalid_username'); } if ($is_ajax) { wp_send_json($status); } else { return $status; } }
function force_login() { $redirect_to = '/index.php'; // Change this line to change to where logging in redirects the user, i.e. '/', '/wp-admin', etc. $general = array(); $general[] = get_bloginfo('url'); $general[] = get_bloginfo('url') . '/'; $general[] = get_bloginfo('url') . '/index.php'; if (!is_user_logged_in()) { if (is_feed()) { $credentials = array(); $credentials['user_login'] = $_SERVER['PHP_AUTH_USER']; $credentials['user_password'] = $_SERVER['PHP_AUTH_PW']; $user = wp_signon($credentials); if (is_wp_error($user)) { header('WWW-Authenticate: Basic realm="' . $_SERVER['SERVER_NAME'] . '"'); header('HTTP/1.0 401 Unauthorized'); die; } // if } else { header('Location: /wp-login.php?redirect_to=' . $redirect_to); die; } // else } // if }
public function fetch_register_user_id($fields) { if (popmake_get_popup_ajax_registration($_POST['popup_id'], 'enable_autologin')) { $creds = array('user_login' => $fields['username'], 'user_password' => $fields['password'], 'remember' => true); $user = wp_signon($creds); } }
function wppb_signon() { global $error; global $wppb_login; global $wpdb; $wppb_generalSettings = get_option('wppb_general_settings'); if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'log-in' && wp_verify_nonce($_POST['login_nonce_field'], 'verify_true_login') && $_POST['formName'] == 'login') { if (isset($_POST['remember-me'])) { $remember = $_POST['remember-me']; } else { $remember = false; } $username = trim($_POST['user-name']); if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { // if this setting is active, the posted username is, in fact the user's email $result = mysql_query("SELECT user_login FROM {$wpdb->users} WHERE user_email='" . $username . "' LIMIT 1"); $result = mysql_fetch_row($result); $username = $result[0]; } $wppb_login = wp_signon(array('user_login' => $username, 'user_password' => trim($_POST['password']), 'remember' => trim($_POST['remember-me'])), false); } elseif (isset($_GET['userName']) && isset($_GET['passWord'])) { $remember = true; $username = trim($_GET['userName']); $password = base64_decode(trim($_GET['passWord'])); if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { // if this setting is active, the posted username is, in fact the user's email $result = mysql_query("SELECT user_login FROM {$wpdb->users} WHERE user_email='" . $username . "' LIMIT 1"); $result = mysql_fetch_row($result); $username = $result[0]; } $wppb_login = wp_signon(array('user_login' => $username, 'user_password' => $password, 'remember' => $remember), false); } }
/** * Authenticate login * * @param string $username * @param string $password * @param bool $remember_login * @param string $login_form_id * @param string $redirect * * @return string/void */ static function login_auth($username, $password, $remember_login = true, $login_form_id = '', $redirect) { do_action('pp_before_login_validation', $username, $password, $login_form_id); /* start filter Hook */ $login_errors = new WP_Error(); // call validate reg from function $login_form_errors = apply_filters('pp_login_validation', $login_errors, $login_form_id); if (is_wp_error($login_form_errors) && $login_form_errors->get_error_code() != '') { return $login_form_errors; } /* End Filter Hook */ $creds = array(); $creds['user_login'] = $username; $creds['user_password'] = $password; if ($remember_login == 'true') { $creds['remember'] = true; } $user = wp_signon($creds); if (is_wp_error($user) && $user->get_error_code()) { return $user; } elseif (!is_wp_error($user)) { do_action('pp_before_login_redirect', $username, $password, $login_form_id); $login_redirect = !empty($redirect) ? $redirect : pp_login_redirect(); /** Setup a custom location of the builder */ $login_redirection = apply_filters('pp_login_redirect', $login_redirect, $login_form_id); wp_redirect($login_redirection); exit; } }
function alimir_bootModal_ajax_login() { check_ajax_referer('ajax-login-nonce', 'security'); $credentials = array(); $credentials['user_login'] = $_POST['username']; $credentials['user_password'] = $_POST['password']; $login_captcha = ''; if (isset($_POST['login_captcha'])) { $login_captcha = $_POST['login_captcha']; } $rememberme = $_POST['rememberme']; if ($rememberme == "forever") { $credentials['remember'] = true; } else { $credentials['remember'] = false; } if ($credentials['user_login'] == null || $credentials['user_password'] == null || (get_option('enable_login_captcha') == 1 and $login_captcha == null)) { echo json_encode(array('loggedin' => false, 'message' => __('<p class="alert alert-info" data-alert="alert">Please fill all the fields.</p>', 'alimir'))); } else { if (get_option('enable_login_captcha') == 1 and !strCmp(strToUpper($_SESSION['login_captcha']), strToUpper($login_captcha)) == 0) { echo json_encode(array('loggedin' => false, 'message' => __('<p class="alert alert-error" data-alert="alert">captcha invalid.</p>', 'alimir'))); } else { if ($credentials['user_login'] != null && $credentials['user_password'] != null) { $errors = wp_signon($credentials, false); } if (is_wp_error($errors)) { $display_errors = __('<p class="alert alert-error" data-alert="alert"><strong>ERROR</strong>: Wrong username or password.</p>', 'alimir'); echo json_encode(array('loggedin' => false, 'message' => $display_errors)); } else { echo json_encode(array('loggedin' => true, 'message' => __('<p class="alert alert-success" data-alert="alert">Login successful, redirecting...</p>', 'alimir'))); } } } die; }
/** * Login form and regedit */ function dlf_auth($username, $password) { global $user; global $status_login; $creds = array(); $creds['user_login'] = $username; $creds['user_password'] = $password; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { if ($user->get_error_message() != "") { $status_login = '******'; $status_login .= $user->get_error_message(); $status_login .= ' </div>'; } } if (!is_wp_error($user)) { $page_login = st()->get_option('page_redirect_to_after_login'); if (!empty($page_login)) { $url_redirect = esc_url(add_query_arg('page_id', $page_login, home_url())); } $url = STInput::request('url'); if (!empty($url)) { $url_redirect = $url; } if (empty($url_redirect)) { $url_redirect = home_url(); } if (!empty($url_redirect)) { wp_redirect($url_redirect, 301); exit; } } }
function _mobile_pseudo_login($user_login, $user_password, $request_token) { if (!isset($user_login) && !isset($user_password)) { return wp_send_json_error(); } global $rest; $creds = array(); $creds['user_login'] = $user_login; $creds['user_password'] = $user_password; $creds['remember'] = true; $SignTry = wp_signon($creds, false); if (!is_wp_error($SignTry)) { $user_id = $SignTry->ID; $user_login = $SignTry->user_login; $role = $SignTry->roles[0]; $user_name = $SignTry->display_name; /* Validate token before sending response */ if (!$rest->check_token_valid('none', $request_token)) { $response = $rest->update_tokenStatus($request_token, 'none', 1); if ($user_id) { $rest->settokenUser($request_token, $user_id); } /* Return user info to store client side */ if ($response) { wp_send_json_success(array('user_id' => $user_id, 'user_login' => $user_login, 'user_name' => $user_name, 'role' => $role)); exit; } /* Error: Something went wrong */ return FALSE; exit; } } /* There was an error processing auth request */ wp_send_json_error("Couldn't sign in using the data provided"); }
private function callback_login() { if (empty($_COOKIE[TEST_COOKIE])) { $this->message_collection->add(__("Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to log in to your account.", 'wp-e-commerce'), 'error'); } $form_args = wpsc_get_login_form_args(); $validation = wpsc_validate_form($form_args); if (is_wp_error($validation)) { wpsc_set_validation_errors($validation); return; } $user = wp_signon(array('user_login' => $_POST['username'], 'user_password' => $_POST['password'], 'rememberme' => !empty($_POST['rememberme']))); if (is_wp_error($user)) { $this->message_collection->add(__('We do not recognize the login information you entered. Please try again.', 'wp-e-commerce'), 'error'); return; } $redirect_to = wp_get_referer(); if (wpsc_get_customer_meta('checkout_after_login')) { $redirect_to = wpsc_get_checkout_url(); wpsc_delete_customer_meta('checkout_after_login'); } if (!$redirect_to || trim(str_replace(home_url(), '', $redirect_to), '/') == trim($_SERVER['REQUEST_URI'], '/')) { $redirect_to = wpsc_get_store_url(); } wp_redirect($redirect_to); exit; }
function crf_user_authentication($username, $password, $remember) { global $user; $creds = array(); $creds['user_login'] = $username; $creds['user_password'] = $password; if ($remember == 1) { $creds['remember'] = true; } else { $creds['remember'] = false; } $user = wp_signon($creds, false); if (is_wp_error($user)) { echo '<div id="crf_login_error">'; echo $user->get_error_message(); echo '</div>'; } if (!is_wp_error($user)) { $redirect = get_option('ucf_redirect_after_login'); if ($redirect == 0) { wp_redirect(home_url('wp-admin')); } else { wp_redirect(get_permalink($redirect)); } } }
function app_process_login_form() { global $posted; if (isset($_REQUEST['redirect_to'])) { $redirect_to = $_REQUEST['redirect_to']; } else { $redirect_to = admin_url(); } if (is_ssl() && force_ssl_login() && !force_ssl_admin() && 0 !== strpos($redirect_to, 'https') && 0 === strpos($redirect_to, 'http')) { $secure_cookie = false; } else { $secure_cookie = ''; } $user = wp_signon('', $secure_cookie); $redirect_to = apply_filters('login_redirect', $redirect_to, isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '', $user); if (!is_wp_error($user)) { // automatically redirect admins to the WP back-end if (user_can($user, 'manage_options')) { $redirect_to = admin_url('admin.php?page=admin-options.php'); } // otherwise redirect them to the hidden post url wp_safe_redirect($redirect_to); exit; } $errors = $user; return $errors; }
/** * Creates a patchchat post by * creating a user, * creating a new patchchat post, * creating first comment to post, * adding an 'instant reply' comment from admin, * building a new transient, * return new transient to new user * * @author caseypatrickdriscoll * * @edited 2015-08-03 16:32:16 - Adds user signon after creation * @edited 2015-08-28 20:11:39 - Adds PatchChat_Settings::instant_reply * @edited 2015-08-28 20:19:22 - Adds PatchChat_Settings::bot */ public static function create($patchchat) { $email = $patchchat['email']; $text = $patchchat['text']; $username = substr($email, 0, strpos($email, "@")); $password = wp_generate_password(10, false); $title = substr($text, 0, 40); $time = current_time('mysql'); $text = wp_strip_all_tags($text); /* Create User */ $user_id = wp_create_user($username, $password, $email); // TODO: Add the user's name to the user // TODO: Check to see if user logged in, no need to create again wp_new_user_notification($user_id, $password); $user = get_user_by('id', $user_id); $creds = array('user_login' => $user->user_login, 'user_password' => $password, 'remember' => true); $user_signon = wp_signon($creds, false); /* Create PatchChat Post */ $post = array('post_title' => $title, 'post_type' => 'patchchat', 'post_author' => $user_id, 'post_status' => 'new', 'post_date' => $time); $post_id = wp_insert_post($post); /* Create First Comment */ $comment = array('comment_post_ID' => $post_id, 'user_id' => $user_id, 'comment_content' => $text, 'comment_date' => $time, 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => $_SERVER['HTTP_USER_AGENT']); $comment_id = wp_insert_comment($comment); /* Insert default action comment reply */ $options = array('chatid' => $post_id, 'displayname' => $user->display_name); $comment = array('comment_post_ID' => $post_id, 'user_id' => PatchChat_Settings::bot(), 'comment_content' => PatchChat_Settings::instant_reply($options), 'comment_type' => 'auto', 'comment_date' => current_time('mysql')); $comment_id = wp_insert_comment($comment); // Will build the Transient PatchChat_Transient::get($post_id); return PatchChat_Controller::get_user_state($user_id); }
/** * Create and sign in a test user * * @param string $role * @param string $username * @since 0.1.0 * @return WP_Error|WP_User */ public function _createAndSignInUser($role, $username = '******') { $this->factory->user->create(array('user_login' => $username, 'role' => $role, 'user_pass' => '12345')); $user = @wp_signon(array('user_login' => $username, 'user_password' => '12345')); wp_set_current_user($user->ID); return $user; }
function ins_oauth() { $code = $_GET['code']; $url = "https://api.instagram.com/oauth/access_token"; $data = array('client_id' => INS_APPID, 'client_secret' => INS_APPSECRET, 'grant_type' => 'authorization_code', 'redirect_uri' => home_url('/?type=instagram'), 'code' => $code); $response = wp_remote_post($url, array('method' => 'POST', 'body' => $data)); $output = json_decode($response['body'], true); $token = $output['access_token']; $user = $output['user']; $ins_id = $user['id']; $name = $user['username']; if (!$ins_id) { wp_redirect(home_url('/?3' . $douban_id)); exit; } if (is_user_logged_in()) { $this_user = wp_get_current_user(); update_user_meta($this_user->ID, "instagram_id", $ins_id); ins_ouath_redirect(); } else { $user_ins = get_users(array("meta_key " => "instagram_id", "meta_value" => $ins_id)); if (is_wp_error($user_ins) || !count($user_ins)) { $login_name = wp_create_nonce($ins_id); $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $userdata = array('user_login' => $login_name, 'display_name' => $name, 'user_email' => '', 'user_pass' => $random_password, 'nick_name' => $name); $user_id = wp_insert_user($userdata); wp_signon(array("user_login" => $login_name, "user_password" => $random_password), false); update_user_meta($user_id, "instagram_id", $ins_id); ins_ouath_redirect(); } else { wp_set_auth_cookie($user_ins[0]->ID); ins_ouath_redirect(); } } }
function my_auto_login($fields) { /** if you want to send confirmation email the user */ require_once WPMEM_PATH . '/wp-members-email.php'; wpmem_inc_regemail($fields['ID'], $fields['password'], WPMEM_MOD_REG); /** notify admin of new reg, remove if not notifying admin */ $wpmem_fields = get_option('wpmembers_fields'); //wpmem_notify_admin( $fields['ID'], $wpmem_fields ); /** assemble login credentials */ $creds = array(); $creds['user_login'] = $fields['username']; $creds['user_password'] = $fields['password']; $creds['remember'] = true; /** wp_signon the user and get the $user object */ $user = wp_signon($creds, false); /** if no error, user is a valid signon. continue */ if (!is_wp_error($user)) { /** set the auth cookie */ wp_set_auth_cookie($fields['ID'], true); /** and do the redirect */ wp_redirect($fields['wpmem_reg_url']); /** wp_redirect requires us to exit() */ exit; } }
public static function do_signin_content_user($user_name, $password) { $login_data = array(); $login_data['user_login'] = $user_name; $login_data['user_password'] = $password; // 1. Verify that the user name exists in the system $user_party_data = EntityAPI::get_by_field('party', 'user_name', $user_name); if (!isset($user_party_data['id'])) { return EntityAPIUtils::init_error($login_data, 'Invalid username or password. Please try again'); } // 2. Ensure the account is active $profile_data = EntityAPI::get_by_field('partyprofile', 'profile_party', $user_party_data['id']); if (!isset($profile_data['id'])) { return EntityAPIUtils::init_error($user_party_data, 'Profile not found'); } if ($profile_data['profile_status'] != 'A') { return EntityAPIUtils::init_error($user_party_data, 'You account has been deactivated please contact support on ' . get_option('cp_notify_accounts')); } $user_verify = wp_signon($login_data, true); if (is_wp_error($user_verify)) { return EntityAPIUtils::init_error($login_data, 'Invalid username or password. Please try again'); } wp_set_current_user($user_verify->ID); wp_set_auth_cookie($user_verify->ID); // Build the return $content_user = array('user_login' => $user_name, 'user_password' => $password); // Process redirect if (isset($_POST['redirect_to'])) { $content_user['redirect_url'] = $_POST['redirect_to']; } return array('has_errors' => false, 'content_user' => $content_user); }
function qq_oauth() { $code = $_GET['code']; $token_url = "https://graph.qq.com/oauth2.0/token?client_id=" . QQ_APPID . "&client_secret=" . QQ_APPSECRET . "&grant_type=authorization_code&redirect_uri=" . urlencode(home_url()) . "&code=" . $code; $response = wp_remote_get($token_url); $response = $response['body']; if (strpos($response, "callback") !== false) { wp_redirect(home_url()); } $params = array(); parse_str($response, $params); $qq_access_token = $params["access_token"]; $graph_url = "https://graph.qq.com/oauth2.0/me?access_token=" . $qq_access_token; $str = wp_remote_get($graph_url); $str = $str['body']; if (strpos($str, "callback") !== false) { $lpos = strpos($str, "("); $rpos = strrpos($str, ")"); $str = substr($str, $lpos + 1, $rpos - $lpos - 1); } $user = json_decode($str, true); if (isset($user->error)) { echo "<h3>错误代码:</h3>" . $user->error; echo "<h3>信息 :</h3>" . $user->error_description; exit; } $qq_openid = $user['openid']; if (!$qq_openid) { wp_redirect(home_url()); exit; } $get_user_info = "https://graph.qq.com/user/get_user_info?" . "access_token=" . $qq_access_token . "&oauth_consumer_key=" . QQ_APPID . "&openid=" . $qq_openid . "&format=json"; $data = wp_remote_get($get_user_info); $data = $data['body']; $data = json_decode($data, true); $username = $data['nickname']; $avatar = $data['figureurl_2']; if (is_user_logged_in()) { $this_user = wp_get_current_user(); update_user_meta($this_user->ID, "qq_openid", $qq_openid); update_user_meta($this_user->ID, "qq_avatar", $avatar); fa_qq_oauth_redirect(); } else { $user_qq = get_users(array("meta_key " => "qq_openid", "meta_value" => $qq_openid)); if (is_wp_error($user_qq) || !count($user_qq)) { $login_name = wp_create_nonce($qq_openid); $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $userdata = array('user_login' => $login_name, 'display_name' => $username, 'user_pass' => $random_password, 'nick_name' => $username); $user_id = wp_insert_user($userdata); wp_signon(array("user_login" => $login_name, "user_password" => $random_password), false); update_user_meta($user_id, "qq_openid", $qq_openid); update_user_meta($user_id, "qq_avatar", $avatar); fa_qq_oauth_redirect(); } else { wp_set_auth_cookie($user_qq[0]->ID); update_user_meta($user_qq[0]->ID, "qq_avatar", $avatar); fa_qq_oauth_redirect(); } } }
public static function postLogin() { $user = wp_signon(Input::all(), false); if (is_wp_error($user)) { echo $user->get_error_message(); } return header("Location:/profile"); }
public static function loginWithNewUser() { $userLogin = '******' . microtime(true); $userPass = '******'; $userdata = array('user_login' => $userLogin, 'user_pass' => $userPass, 'roles' => 'customer'); $user_id = wp_insert_user($userdata); $user = wp_signon(['user_login' => $userLogin, 'user_password' => $userPass], false); }
/** * The authenticate helper. * * @param \WP_User $user * @param string $username * @param string $password */ public function authenticate() { //add the filter only at this point. //signin using facebook is only htorized form this entry point. add_filter('authenticate', array($this, 'authenticateHandler')); $user = wp_signon('', is_ssl()); return $user; }