我在 wordpress 上有网站,我使用 pie-registration 添加用户密码字段。
现在我想做自动登录,但我不知道该怎么做。有人可以帮助我吗?
问问题
1024 次
1 回答
0
注册后是否可以自动登录:
- 在函数 showForm() 搜索中转到 pie-registration/pie-register.php
if(isset($_POST['success']) && $_POST['success'] != "")
和做
if(isset($_POST['success']) && $_POST['success'] != ""){
$output .= '<p class="piereg_message">'.apply_filters('piereg_messages',__($_POST['success'],"piereg")).'</p>';
$this->afterRegisterPage();
}
2.after函数afterLoginPage()添加
function afterRegisterPage()
{
$option = get_option("pie_register_2");
$this->checkAutoLogin();
if(isset($_GET['redirect_to']) and $_GET['redirect_to'] != ""){
wp_redirect($_GET['redirect_to']);
}elseif($option['after_login'] > 0)
{
wp_safe_redirect(get_permalink($option['after_login']));
}else{
wp_redirect(site_url());
}
exit;
}
3.函数checkLogin()添加后
函数 checkAutoLogin()
{
global $errors, $wp_session;
$errors = new WP_Error();
$option = get_option('pie_register_2');
if(empty($_POST['username']) || empty($_POST['password']))
{
$errors->add('login-error',apply_filters("piereg_Invalid_username_or_password",__('Invalid username or password.','piereg')));
}
else
{
$error_found = 0;
if($option['capthca_in_login'] == 1){
$settings = get_option("pie_register_2");
$privatekey = $settings['captcha_private'] ;
require_once(PIEREG_DIR_NAME.'/recaptchalib.php');
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$errors->add('login-error',apply_filters("Invalid_Security_Code",__('Invalid Security Code','piereg')));
$error_found++;
}
}
elseif($option['capthca_in_login'] == 2){
if(isset($_POST['piereg_math_captcha_login']))//Login form in Page
{
$piereg_cookie_array = $_COOKIE['piereg_math_captcha_Login_form'];
$piereg_cookie_array = explode(",",$piereg_cookie_array);
$cookie_result1 = (intval(base64_decode($piereg_cookie_array[0])) - 12);
$cookie_result2 = (intval(base64_decode($piereg_cookie_array[1])) - 786);
$cookie_result3 = (intval(base64_decode($piereg_cookie_array[2])) + 5);
if( ($cookie_result1 == $cookie_result2) && ($cookie_result3 == $_POST['piereg_math_captcha_login'])){
}
else{
$errors->add('login-error',apply_filters("Invalid_Security_Code",__('Invalid Security Code','piereg')));
$error_found++;
}
}
elseif(isset($_POST['piereg_math_captcha_login_widget']))//Login form in widget
{
$piereg_cookie_array = $_COOKIE['piereg_math_captcha_Login_form_widget'];
$piereg_cookie_array = explode(",",$piereg_cookie_array);
$cookie_result1 = (intval(base64_decode($piereg_cookie_array[0])) - 12);
$cookie_result2 = (intval(base64_decode($piereg_cookie_array[1])) - 786);
$cookie_result3 = (intval(base64_decode($piereg_cookie_array[2])) + 5);
if( ($cookie_result1 == $cookie_result2) && ($cookie_result3 == $_POST['piereg_math_captcha_login_widget'])){
}
else{
$errors->add('login-error',apply_filters("Invalid_Security_Code",__('Invalid Security Code','piereg')));
$error_found++;
}
}else{
$errors->add('login-error',apply_filters("Invalid_Security_Code",__('Invalid Security Code','piereg')));
$error_found++;
}
}
if($error_found == 0){
$creds = array();
$creds['user_login'] = $_POST['username'];
$creds['user_password'] = $_POST['password'];
$creds['remember'] = (isset($_POST['rememberme']))?$_POST['rememberme']:"";
if(isset($_POST['social_site']) and $_POST['social_site'] == "true" )
{
require_once( ABSPATH . WPINC . '/user.php' );
require_once( ABSPATH . WPINC . '/pluggable.php' );
wp_set_auth_cookie($_POST['user_id_social_site']);
$user = get_userdata($_POST['user_id_social_site']);
}
else
{
$user = wp_signon( $creds, false );
}
//$this->check_user_activation();
if ( is_wp_error($user))
{
$user_login_error = $user->get_error_message();
if(strpos(strip_tags($user_login_error),'Invalid username',5) > 6)
{
$user_login_error = apply_filters('pie_invalid_username_password_msg_txt','<strong>'.ucwords(__("error","piereg")).'</strong>: '.__("Invalid username","piereg").'. <a href="'.$this->pie_lostpassword_url().'" title="'.__("Password Lost and Found","piereg").'">'.__("Lost your password?","piereg").'</a>');
}else if(strpos(strip_tags($user_login_error),'password you entered',9) > 10)
{
$user_login_error = apply_filters('pie_invalid_user_password_msg_txt','<strong>'.ucwords(__("error","piereg")).'</strong>: '.__("The password you entered for the username","piereg").' <strong>'.$_POST['username'].'</strong> '.__("is incorrect","piereg").'. <a href="'.$this->pie_lostpassword_url().'" title="'.__("Password Lost and Found","piereg").'">'.__("Lost your password?","piereg").'</a>');
}
$errors->add('login-error',apply_filters("piereg_login_error",$user_login_error));
}
else
{
if(in_array("administrator",(array)$user->roles)){
do_action("piereg_admin_login_before_redirect_hook",$user);
if(isset($_GET['redirect_to']) and $_GET['redirect_to'] != ""){
wp_redirect($_GET['redirect_to']);
exit;
}
wp_safe_redirect(admin_url());
exit;
}
else
{
$active = get_user_meta($user->ID,"active",true);
//Delete User after grace Period
if($active == "0")//If not active
{
$delete_user = true;
if($this->deleteUsers($user->ID,$user->user_email,$user->user_registered)){
$errors->add("login-error",apply_filters("piereg_your_account_has_no_longer_exist",__("Your account has no longer exist.")));
$delete_user = false;
}
if($delete_user){
wp_logout();
$errors->add('login-error',apply_filters("piereg_your_account_is_not_activated",__('Your account is not activated!.','piereg')));
}
}elseif(empty($active))
{
//apply_filters('get_avatar',array($this,'custom_avatars'),$user->ID,"29");
do_action("piereg_user_login_before_redirect_hook",$user);
$this->afterLoginPage();
exit;
}
else{
//apply_filters('get_avatar',array($this,'custom_avatars'),$user->ID,"29");
do_action("piereg_user_login_before_redirect_hook",$user);
$this->afterLoginPage();
exit;
}
}
}
}
}
}
我希望能成为你的帮助,你理解我。
于 2014-08-14T09:49:31.650 回答