本文整理匯總了PHP中wp_set_auth_cookie函數的典型用法代碼示例。如果您正苦於以下問題:PHP wp_set_auth_cookie函數的具體用法?PHP wp_set_auth_cookie怎麽用?PHP wp_set_auth_cookie使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了wp_set_auth_cookie函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: force_ssl_cookie
function force_ssl_cookie($errors, $user_id)
{
if (empty($errors)) {
wp_set_auth_cookie($user_id, true, true);
wp_set_current_user($user_id);
}
}
示例2: facebook_login
/**
* Maps our FB response fields to the correct user fields as found in wp_update_user. Then
* calls setUpNewFacebookUser, and passes the correct response via JSON to JS.
*
* @since 2.0.0
*
* @return JSON A JSON object
*/
public function facebook_login()
{
check_ajax_referer('facebook-nonce', 'security');
$user = array('username' => $_POST['fb_response']['id'], 'user_login' => $_POST['fb_response']['id'], 'first_name' => $_POST['fb_response']['first_name'], 'last_name' => $_POST['fb_response']['last_name'], 'email' => $_POST['fb_response']['email'], 'user_url' => $_POST['fb_response']['link'], 'fb_id' => $_POST['fb_response']['id']);
if (empty($user['username'])) {
$status = $this->_zm_alr_helpers->status('invalid_username');
$user_id = false;
} else {
$user_obj = get_user_by('login', $user['user_login']);
if ($user_obj == false) {
$user_obj = $this->setupNewFacebookUser($user);
}
// A WP user account already exists that is NOT associated with a FB account
if ($user_obj == 'existing_user_email') {
$status = $this->_zm_alr_helpers->status('username_exists');
} elseif ($user_obj) {
$user_id = $user_obj->ID;
wp_set_auth_cookie($user_id, true);
$status = $this->_zm_alr_helpers->status('success_login');
} else {
$status = $this->_zm_alr_helpers->status('invalid_username');
}
}
$status = array_merge($status, $this->registerRedirect($user['user_login']));
wp_send_json($status);
}
示例3: login
/**
* 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;
}
示例4: ajax_return_to_admin_panel
function ajax_return_to_admin_panel()
{
global $wpdb;
if (!empty($_POST['secure_key'])) {
$verify = $_POST['secure_key'];
} else {
exit(json_encode(array('status' => false, 'message' => __("Wrong data", WPC_CLIENT_TEXT_DOMAIN))));
}
if (!empty($_COOKIE['wpc_key']) && is_user_logged_in()) {
$key = $_COOKIE['wpc_key'];
$user_data = $wpdb->get_row($wpdb->prepare("SELECT umeta_id, user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = 'wpc_client_admin_secure_data' AND meta_value LIKE '%s'", '%"' . md5($key) . '"%'), ARRAY_A);
if (isset($user_data['user_id']) && user_can($user_data['user_id'], 'wpc_admin_user_login') && wp_verify_nonce($verify, get_current_user_id() . $user_data['user_id'])) {
if (!empty($user_data['meta_value'])) {
$secure_array = unserialize($user_data['meta_value']);
if (isset($secure_array['end_date']) && $secure_array['end_date'] > time()) {
wp_set_auth_cookie($user_data['user_id'], true);
$wpdb->delete($wpdb->usermeta, array('umeta_id' => $user_data['umeta_id']));
$secure_logged_in_cookie = 'https' === parse_url(get_option('home'), PHP_URL_SCHEME);
setcookie("wpc_key", '', time() - 1, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);
exit(json_encode(array('status' => true, 'message' => admin_url('admin.php?page=wpclient_clients'))));
}
}
}
}
exit(json_encode(array('status' => false, 'message' => __("Wrong data", WPC_CLIENT_TEXT_DOMAIN))));
}
開發者ID:EfncoPlugins,項目名稱:web-portal-lite-client-portal-secure-file-sharing-private-messaging,代碼行數:26,代碼來源:class.ajax.php
示例5: mm_facebook_connection_process_facebook_actions
function mm_facebook_connection_process_facebook_actions()
{
global $user_ID;
$current_url = mm_facebook_connection_get_current_url();
if (mm_facebook_connection_is_conifgured()) {
if (isset($_GET['mm_unlink_facebook']) && $_GET['mm_unlink_facebook'] == 'true') {
update_user_meta($user_ID, 'mm_facebook_connection_facebook_id', '');
return wp_redirect($current_url);
}
if (isset($_GET['code']) && $_GET['code'] && isset($_GET['mm_facebook_connection']) && $_GET['mm_facebook_connection'] == 'true') {
$data_array = mm_facebook_connection_get_data($_GET['code'], $current_url . '?mm_facebook_connection=true');
if (is_array($data_array) && count($data_array) > 0) {
update_user_meta($user_ID, 'mm_facebook_connection_facebook_id', $data_array['facebook_internal_id']);
return wp_redirect($current_url);
}
}
if (isset($_GET['code']) && $_GET['code'] && isset($_GET['mm_facebook_login']) && $_GET['mm_facebook_login'] == 'true') {
$data_array = mm_facebook_connection_get_data($_GET['code'], $current_url . '?facebook_login=true');
$users_array = get_users(array('meta_key' => 'mm_facebook_connection_facebook_id', 'meta_value' => $data_array['facebook_internal_id']));
if (is_array($users_array) && count($users_array) > 0) {
$user_to_auth_obj = $users_array[0];
if ($user_to_auth_obj) {
wp_set_current_user($user_to_auth_obj->ID, $user_to_auth_obj->user_login);
wp_set_auth_cookie($user_to_auth_obj->ID);
do_action('wp_login', $user_to_auth_obj->user_login);
return wp_redirect(home_url('/'));
}
}
}
}
}
示例6: auto_login_new_user
function auto_login_new_user($user_id)
{
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
echo 'current user: ' . wp_get_current_user()->user_login;
wp_redirect(home_url() . '/logup?newlog=true');
}
示例7: ucenter_oauth
function ucenter_oauth()
{
//根據授權碼獲取access_token
$url = UCENTER_API . '/oauth/accessToken';
$data = array('client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'grant_type' => 'authorization_code', 'redirect_uri' => REDIRECT_URI, 'code' => $_GET['code']);
$response = wp_remote_post($url, array('method' => 'POST', 'body' => $data));
$data = json_decode($response['body'], true);
if (1 !== $data['code']) {
wp_die('授權失敗');
}
$access_token = $data['data']['access_token'];
//根據access_token獲取用戶信息
$url = UCENTER_API . '/user/?access_token=' . $access_token;
$data = wp_remote_get($url);
$data = json_decode($data['body'], true);
if (1 !== $data['code']) {
wp_die('獲取用戶信息失敗');
}
$username = $data['data']['username'];
$user_id = $data['data']['user_id'];
//根據返回的用戶信息登錄,用戶還未存在時則插入
$current_user = get_user_by('login', $username);
if (is_wp_error($current_user) || !$current_user) {
$random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
$user_id = wp_insert_user(array('user_login' => $username, 'display_name' => $username, 'nick_name' => $username, 'user_pass' => $random_password));
wp_set_auth_cookie($user_id);
} else {
wp_set_auth_cookie($current_user->ID);
}
header('Location: ' . home_url() . '/wp-admin');
exit;
}
示例8: authenticateAction
/**
* Handle login submissions. Authenticate using AuthService.
* @return
*/
public function authenticateAction()
{
$form = $this->getForm();
$urlRedirect = false;
$redirect = 'home';
$params = array();
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
/* Handle Authentication */
$username = $request->getPost('Username');
$password = $request->getPost('Password');
$WP_User = wp_authenticate($username, $password);
if (is_wp_error($WP_User)) {
$redirect = 'login';
$this->flashmessenger()->addErrorMessage("Invalid User Credentials");
} else {
wp_set_auth_cookie($WP_User->ID);
$this->flashmessenger()->addSuccessMessage("Login Successful");
}
} else {
/* Form error messages */
foreach ($form->getMessages() as $message) {
$this->flashmessenger()->addErrorMessage(implode(",", $message));
}
}
}
return $this->redirect()->toRoute($redirect);
}
示例9: myfunction
function myfunction()
{
//should do some database query here
// .... ..... ..... .....
//just some dummy result
//$email = $wpdb->get_var("SELECT user_email FROM wp_users WHERE user_login = 'ezyva.jason' ");
//global $wpdb;
//$email = $wpdb->get_var("SELECT user_email FROM wp_users WHERE user_login = 'ezyva.jason' ");
$url = "https://app.thesmsfacademy.com.au/api/auth/validate_auth_cookie/?cookie=ezyva.jason|1398140082|954a2415c23fac56ca7cf23050566c08";
$content = file_get_contents($url);
$json = json_decode($content, true);
if ($json['valid']) {
$url = "https://app.thesmsfacademy.com.au/api/auth/get_currentuserinfo/?cookie=ezyva.jason|1398140082|954a2415c23fac56ca7cf23050566c08";
$content = file_get_contents($url);
$json2 = json_decode($content, true);
$user_login = $json2[user][username];
$user = get_user_by('login', $user_login);
$user_id = $user->ID;
wp_set_current_user($user_id, $user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user_login);
return 'valid';
} else {
return 'Invalid';
}
}
示例10: json_basic_auth_handler
/**
* 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;
}
示例11: bdn_is_user_auth2
function bdn_is_user_auth2()
{
global $driveService;
$current_user_id = get_current_user_id();
$client = new Google_Client();
$client->setRedirectUri(home_url('/'));
$driveService = new Google_DriveService($client);
$oauth2 = new Google_Oauth2Service($client);
if (!isset($_GET['code']) && (!is_user_logged_in() || ($access_token = get_user_meta($current_user_id, '_google_access_token', true)) && $client->setAccessToken($access_token) && !$client->getAccessToken())) {
header('Location: ' . $client->createAuthUrl());
exit;
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$user = $oauth2->userinfo->get();
$new_user = get_user_by('email', $user['email']);
if (!$current_user_id) {
wp_set_current_user($new_user->ID, $new_user->user_login);
wp_set_auth_cookie($new_user->ID);
do_action('wp_login', $new_user->user_login);
} elseif ($new_user->ID == $current_user_id) {
update_user_meta($new_user->ID, '_google_access_token', $client->getAccessToken());
} else {
die('Sorry, please use your BDN account');
}
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
return $driveService;
}
示例12: ins_oauth
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();
}
}
}
示例13: sso_check
/**
Plugin Name: SSO
Author: Garth Mortensen, Mike Hansen
Version: 0.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
function sso_check()
{
if (!isset($_GET['salt']) || !isset($_GET['nonce']) || !isset($_GET['user'])) {
sso_req_login();
}
if (sso_check_blocked()) {
sso_req_login();
}
$nonce = esc_attr($_GET['nonce']);
$salt = esc_attr($_GET['salt']);
$user = esc_attr($_GET['user']);
$hash = base64_encode(hash('sha256', $nonce . $salt, false));
$hash = substr($hash, 0, 64);
if (get_transient('sso_token') == $hash) {
if (is_email($user)) {
$user = get_user_by('email', $user);
} else {
$user = get_user_by('id', (int) $user);
}
if (is_a($user, 'WP_User')) {
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
delete_transient('sso_token');
wp_safe_redirect(admin_url());
} else {
sso_req_login();
}
} else {
sso_add_failed_attempt();
sso_req_login();
}
die;
}
示例14: action
/**
* Generates token.
*
* Uses 'create_token' to create a token.
*
* @since 4.3.0
*
* @param string $request The rest-api request that contains all parameters.
* @return array The token and expiration-timestamp
*/
function action(WP_REST_Request $request)
{
$return = new WP_Error('400', __('Authentication failed.', 'wp_jwt_auth'));
if (isset($request['method'])) {
// if user wants to login by social-media-account
$return = apply_filters('wak_login_method_' . $request['method'], $return, $request);
} else {
// if user wants to login by username/password
$username = $request['username'];
$password = $request['password'];
$jwt_functions = new WAK_Functions();
$user = get_user_by('login', $username);
if ($user && wp_check_password($password, $user->data->user_pass, $user->ID)) {
$return = $jwt_functions->create_token($user->ID);
} else {
$return = new WP_Error('credentials_invalid', __('Username/Password combination is invalid', 'wp_jwt_auth'));
}
}
if (isset($request['set_wp_cookie']) && $request['set_wp_cookie'] == 'true' && !is_wp_error($return)) {
wp_set_auth_cookie($return['userid'], true);
}
if (isset($request['redirect_to']) && !is_wp_error($return)) {
$location = $request['redirect_to'];
if (is_wp_error($return)) {
$location .= '?error=true&msg=' . urlencode($return->get_error_message());
}
wp_redirect($location);
exit;
return;
}
return $return;
}
示例15: qq_oauth
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();
}
}
}