Score:0

user_login_finalize only works when the user has admin roles

cn flag

i create custom login form in drupal 9 using user_login_finalize function. But this function only work when user has admin roles... i dont know why. This is my code :..

{
    if (isset($_POST['email']) && isset($_POST['password'])) {
        date_default_timezone_set("Asia/Jakarta");
        session_start();
        $session = new Session();

        $count_error = 0;
        $user = user_load_by_mail($_POST['email']);

        if (!$user) {
            $session->set('error_email', 'E-mail tidak sesuai');
            $count_error++;
        }

        if ($user) {
            if (!$user->isActive()) {
                $session->set('error_email', 'Akun kamu belum aktif');
                $count_error++;
            }

            $password_hasher = \Drupal::service('password');

            if (!$password_hasher->check($_POST['password'], $user->getPassword())) {
                $session->set('error_password', 'Password tidak sesuai');
                $count_error++;
            }
        }

        if ($count_error > 0) {
            $variables['error_email']       = $session->get('error_email');
            $variables['error_password']    = $session->get('error_password');
        }

        if ($count_error == 0 && $user) {
            user_login_finalize($user);
        }
    }
}```
Jaypan avatar
de flag
What isn't working?
Aldi Alhafidzi avatar
cn flag
the function ```user_login_finalize``` only works when user has admin roles
Jaypan avatar
de flag
And what is not happening?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.