How IT

언제든지 물어보세요.

컨텐츠로 건너뛰기
  • 홈
  • Unix
  • Apple
  • Java
  • Android
  • C#
  • C++

사용자 등록 후 자동 로그인 등록한 후입니다.

내 목적에 맞게 수정 된 플러그인을 사용하고 있습니다.

내가 따르는 것은 사용자가 자동으로 로그인하여 현재 페이지로 돌아가도록 등록한 후입니다. 현재 사용자 이름과 비밀번호가 포함 된 이메일을 보냅니다. 그런 다음 해당 세부 정보를 사용하여 로그인해야합니다.



답변

기본적으로 사용자를 로그인하려면 다음을 사용할 수 있습니다.

            //Login the user
    $creds = array();
    $creds['user_login'] = $login;
    $creds['user_password'] = $password;
    if ( !empty( $remember ) ){
        $creds['remember'] = true;
    }
    $user = wp_signon( $creds, true );

그러나 비밀번호와 로그인이있는 경우에만 자신의 등록 양식을 작성하고 처리하여 사용자를 직접 작성할 수 있습니다.

//Only after Everything has been validated, proceed with creating the user
        //Create the user
        $user_pass = wp_generate_password();
        $user = array(
            'user_login' => $username,
            'user_pass' => $user_pass,
            'first_name' => $firstname,
            'last_name' => $lastname,
            'user_email' => $email
        );
        $user_id = wp_insert_user( $user );

        /*Send e-mail to admin and new user -
        You could create your own e-mail instead of using this function*/
        wp_new_user_notification( $user_id, $user_pass );

여기에 로그인과 비밀번호가 있으므로 사용자를 로그인 할 수 있습니다.

도움이 되었기를 바랍니다


답변

등록 과정에 이상적인 장소는 없습니다. 핵심에 사용자 등록 이벤트 작업 후크를 추가하는 강력한 사례가 있다고 생각합니다. 그러나 그 동안 가짜로 만들 수 있다고 생각합니다. 사용자가 성공적으로 등록 할 때 발생하는 마지막 작업 중 하나는 ‘default_password_nag’라는 사용자 옵션을 만드는 것입니다. 이를 감시하는 액션을 생성하고 설정되면 사용자를 설정할 수 있습니다.

add_action('update_user_metadata', 'my_auto_login', 10, 4);

function my_auto_login( $metaid, $userid, $key, $value ) {
    // We only care about the password nag event. Ignore anything else.
    if ( 'default_password_nag' !== $key  && true !== $value) {
        return;
    }

    // Set the current user variables, and give him a cookie. 
    wp_set_current_user( $userid );
    wp_set_auth_cookie( $userid );
}

이론적으로는 테스트되지 않았지만 작동해야합니다.

이제해야 할 일에 대한 아이디어를 얻었으므로 이것이 보안 상 나쁜 생각이라고 생각합니다. 정크 메일 보관함을 설정하는 데 어려움을 겪지 않아도 정크 계정을 만들 수 있습니다. 🙂


답변

난 그냥 사용하여 작업하는 기능 얻을 관리했습니다 user_register 후크를 내에서 다음 코드 functions.php를 :

// auto log in a user who has just signed up       
function auto_login_new_user( $user_id ) {
  wp_set_auth_cookie( $user_id, false, is_ssl() );
}
add_action( 'user_register', 'auto_login_new_user' );


답변

function login_after_register($userlogin,$userpass){
    $credentials = array( 'user_login' =>  $userlogin, 'user_password' => $userpass, 'remember' => true );

    $secure_cookie = is_ssl();

    $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials);
    add_filter('authenticate', 'wp_authenticate_cookie', 30, 3);

    $user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
    wp_set_auth_cookie($user->ID, $credentials["remember"], $secure_cookie);
    do_action('wp_login', $user->user_login, $user);
}


답변


이 글은 wordpress 카테고리에 분류되었고 login, php, registered 태그가 있으며 소장 마님에 의해 2023-08-04에 작성되었습니다.

글 네비게이션

← 바다 소금과 일반 식탁 소금의 차이점은 무엇입니까? 식탁 소금을 사용하면 어떤 가능하면 Google 크롬에서 내 삭제 된 기록을 복구 할 수 있습니까? 있지만 내 Chrome 브라우저에 항목을 다시 저장하는 →

태그

  • android
  • apt
  • bash
  • boot
  • c#
  • c++
  • code-golf
  • command-line
  • debian
  • firefox
  • git
  • google-chrome
  • hard-drive
  • html
  • java
  • keyboard
  • linux
  • mac
  • macos
  • math
  • memory
  • microsoft-excel
  • mysql
  • networking
  • performance
  • permissions
  • python
  • r
  • regression
  • security
  • shell
  • sql-server
  • ssh
  • string
  • terminal
  • ubuntu
  • unity
  • usb
  • vim
  • virtualbox
  • windows
  • windows-7
  • windows-8
  • windows-10
  • windows-xp

최신 글

  • Windows에서 파티션 크기를 조정 한 후 APFS 파티션이 손실 됨 00 80
  • App Store에서 El Capitan을 강제로 다시 다운로드 하시겠습니까? 업데이트 된 플래시 드라이브 설치 프로그램을 빌드하기
  • 기존 시스템에 부팅 드라이브로 SSD 추가 백업에 큰 관심이 없습니다. 내가 걱정하는 것은이
  • geoJSON featureCollection에 properties 요소를 갖는 것이 유효합니까?
  • 추세를 식별하기 위해 신호 처리 원리를 신중하게 사용 매우 시끄러운 장기 데이터에서 추세를

카테고리

  • Android
  • Apple
  • C#
  • C++
  • cooking
  • cs
  • cstheory
  • diy
  • drupal
  • electronics
  • emacs
  • Gis
  • Git
  • Html
  • Java
  • Javascript
  • magento
  • photo
  • Python
  • raspberrypi
  • scicomp
  • Server
  • Software
  • Sql
  • stats
  • Superuser
  • ubuntu
  • Unix
  • vi
  • webapps
  • webmasters
  • wordpress
  • 게임개발
  • 코딩
Proudly powered by WordPress
Go to mobile version
Close