Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

logued out do not why #811

Open
Open
@nahuelmellusso

Description

@nahuelmellusso
  • Laravel Version: 6.0
  • Adldap2-Laravel Version: 6.0
  • PHP Version: 7.3
  • LDAP Type: OpenLDAP

I am making a login like this :

protected function attemptLogin(Request $request)
    {

        $credentials = $request->only($this->username(), 'password');

        $username = $credentials[$this->username()];
        $password = $credentials['password'];
        $user_format = env('LDAP_USER_FORMAT', 'cn=%s,'.env('LDAP_BASE_DN', ''));
        $userdn = sprintf($user_format, $username);

        if(Adldap::auth()->attempt($userdn, $password, $bindAsUser = true)) {
            // the user exists in the LDAP server, with the provided password

            $user = \App\User::where($this->username(), $username)->first();

            if (!$user) {
                // the user doesn't exist in the local database, so we have to create one

                $user = new \App\User();
                $user->username = $username;
                $user->password = '';

                // you can skip this if there are no extra attributes to read from the LDAP server
                // or you can move it below this if(!$user) block if you want to keep the user always
                // in sync with the LDAP server
                $sync_attrs = $this->retrieveSyncAttributes($username);
                foreach ($sync_attrs as $field => $value) {
                    $user->$field = $value !== null ? $value : '';
                }
            }

            // by logging the user we create the session, so there is no need to login again (in the configured time).
            // pass false as second parameter if you want to force the session to expire when the user closes the browser.
            // have a look at the section 'session lifetime' in `config/session.php` for more options.
            $this->guard()->login($user, false);

            return true;
           dd(auth()->check()) ----> return true
        }

        // the user doesn't exist in the LDAP server or the password is wrong
        // log error
        return false;
    }

but imediatly redirecting to login page and auth()->check() return false.

why ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions