Giter VIP home page Giter VIP logo

Comments (19)

yajra avatar yajra commented on August 16, 2024 1

USER_PASS? is it hashed? I think you are using an existing users table and the password is not hashed.

from laravel-oci8.

yajra avatar yajra commented on August 16, 2024

Hi,

Are you using blob field on your user table? If not, then just use Model/Eloquent directly. I only use OracleEloquent for blob fields.

from laravel-oci8.

AminMkh avatar AminMkh commented on August 16, 2024

Yeah I was using OracleElequent, then tried Model, did authenticate but still lost after new page request. Here is my model code, then the Auth snippet.

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;


use App\RoleModel;

class UserModel extends Model implements AuthenticatableContract, CanResetPasswordContract {

    use Authenticatable, CanResetPassword;
    use Permission;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'USER';
    public $primaryKey = 'USER_SERNO';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    // protected $fillable = ['username', 'email', 'password'];
    // public $guarded = ['role_id'];
    public $guarded = [];
    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];

    public function setPasswordAttribute( $password ) {
        $this->attributes['password'] = \Hash::make( $password );
    }

}

Auth snippet:

        if (Auth::attempt(['email' => $email, 'password' => $password]))
        {
            $user = Auth::user(); // had to do this to get it to work
            session(['user' => $user ] );  // had to do this to get it to work

from laravel-oci8.

yajra avatar yajra commented on August 16, 2024

You're using class UserModel extends Model which is Laravel's default model. It should work as expected. Have you tried using the default AuthController of Laravel?

FYI: The package have use yajra\Oci8\Eloquent\OracleEloquent as Eloquent; class which was what I thought you were referring to. OracleEloquent.

from laravel-oci8.

AminMkh avatar AminMkh commented on August 16, 2024

I will try using laravel's AuthController sure, although used same code with MySQL db driver and works fine.

Regarding OracleEloquent, I keep it OracleElequent just so I won't be confused, but thanks for mentioning :)

//basically all other models extend this 
use yajra\Oci8\Eloquent\OracleEloquent as OracleElequent;
class BaseModel extends OracleElequent {

from laravel-oci8.

AminMkh avatar AminMkh commented on August 16, 2024

Hello,

I tried Laravel's built in Auth controller, registering fine, and after registering session is stored, so that's working.

Login in, same problem, Auth user is only stored for that page request. New page requests it's lost.

I tried dd (Auth::user) when register and logging in. Identical, just why is the logging in isn't being stored in session. Is driving me crazy.

Also tried the exact function in register method: Auth::login($user); Doesn't working when logging in.

Any hints or where to debug? I would live to print the session values, but not sure how to do that in Laravel, because it's not php $_SESSION.

from laravel-oci8.

AminMkh avatar AminMkh commented on August 16, 2024

After some debugging, and Using Session::all()
the login token is empty in case of user logging in, below:

array:5 [▼ "_token" => "HrSjpH8S8dgu0FGGTzN8GQIjr4G98JFLb9xSJrgk" "_previous" => array:1 [▶] "flash" => array:2 [▶] "login_82e5d2c56bdd0811318f0cf078b78bfc" => null "flash_message" => "welcome in" ]

In case of user registering, it has the user ID
"login_82e5d2c56bdd0811318f0cf078b78bfc" => 132

No clue why this only happens with Oracle, using MySQL is fine, and it's a session file in both cases !

But thanks mate, as I said I had a workaround, so it's not urgent. But would love to hear your thoughts, and if you are as persistent as I am, I can give you FTP access to development server to further look into it.

from laravel-oci8.

AminMkh avatar AminMkh commented on August 16, 2024

Totally figured out what's wrong, although it took hours of debugging!

When creating a user model, it works perfectly, then Auth::login($user) works fine.

When retrieving $user model, using Auth::attempt or fetching user by email then Hash::check passwords, the user primary key (user ID), is stored in Laravel model as small case, user_id, doesn't work. When creating it's stored in Laravel model in capital case, USER_ID.

Anyways so when logging in, laravel is confused and doesn't find the id, so login is only for 1 page request. Then token_***** is stored NULL.

All good now, I finally fixed it, just when logging in, I get user by email, then manually set the id to capital case, then send the model object to Auth::login. I bet I can find a way to do all of that using Model's setters and geters, this way it's in one location, not doing it whenever I need to login.

Damn it Oracles, why the hell are you confusing me!

Feel free to close this issue when you like. But out of curiosity, how is it working with you! Auth::attemp ? we must be on different Oracle server/client/configurations.

Thanks again, see ya.

from laravel-oci8.

yajra avatar yajra commented on August 16, 2024

Hi, good to know you were able to fixed this issue. I haven't encountered this yet but maybe this occurs because you specifically use upper case value on table and primaryKey on your model (will also check if that might cause the issue on my free time)? Oracle is a bit hard on us when it comes to text case like on sorting, searching, etc..

from laravel-oci8.

yajra avatar yajra commented on August 16, 2024

Hi, I was able to replicate this issue just now by setting protected $primaryKey = 'ID'; in my model. You can fix this issue by using small case id protected $primaryKey = 'id';. Thanks for the hints.

Note: the package converts all fields name to small case which may have cause the confusion.

from laravel-oci8.

AminMkh avatar AminMkh commented on August 16, 2024

oh great, what I ended up doing was override Elequent's get primary key function, but will try check out your suggestion.

    public function getKeyName()
    {
        $this->ID = $this->id;
        return $this->primaryKey ;
    }

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

Hi
I faced with a big problem for login to system .
when i register a new user -> this is Ok and after register immediately login to system .

but when i logout and want to login to system by attempt function this returned an error .
how i manage login ?
Thank you

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

User Model is :

class User extends Authenticatable
{
	use Notifiable;

	public $sequence = 'user_id_seq';
	protected $table = 'USERS';
	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'FULLNAME', 'USERNAME', 'EMAIL', 'USER_PASS', 'IS_ADMIN', 'ACTIVE'
		, 'IS_SUPERADMIN'
	];

} 

Login Function is :

	public function getLogin(Request $request)
	{
		$username = $request->get('username');
		$pass = $request->get('password');

		if (Auth::attempt(['USERNAME' => $username, 'USER_PASS' => $pass])) {
			dd('yes');
		} else {
			dd('no');
		}
	}

This return no ,

anyone know answer ?
Thank you

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

@yajra
@AminMkh
You know how i can solve this error?

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

i do all steps for add OracleServiceProvider to Providers/AuthServiceProvider.php class :

class AuthServiceProvider extends ServiceProvider
{
	/**
	 * The policy mappings for the application.
	 *
	 * @var array
	 */
	protected $policies = [
		'App\Model' => 'App\Policies\ModelPolicy',
	];


	/**
	 * Register any authentication / authorization services.
	 *
	 * @return void
	 */
	public function boot()
	{
		Auth::provider('oracle', function ($app, array $config) {
			return new \Yajra\Oci8\Auth\OracleUserProvider($app['hash'], $config['model']);
		});

		$this->registerPolicies();

	}
}

and change login function :

                 $username = $request->get('username');
		$pass     = $request->get('password');
		$creadentials = ['USERNAME'=> $username , 'USER_PASS'=>$pass];
		dd(Auth::retrieveByCredentials($creadentials));

but i see this error after login :

Symfony\Component\Debug\Exception\FatalThrowableError in AuthManager.php line 294:
Call to undefined method Illuminate\Auth\SessionGuard::retrieveByCredentials()

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

@yajra : PLEASE HELP ME

from laravel-oci8.

yajra avatar yajra commented on August 16, 2024

@ali2535 see docs https://github.com/yajra/laravel-oci8#laravel-52-oracle-user-provider

To use, just update auth.php config and set the driver to oracle

'providers' => [
    'users' => [
        'driver' => 'oracle',
        'model' => App\User::class,
    ],
]

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

@yajra :
Thank you for your answer .
i do this . but this no change . i get same error .
yajra can you give me an example from scratch that show login function?
what is the problem for my login code ?

from laravel-oci8.

falahatiali avatar falahatiali commented on August 16, 2024

i change the code :

dd(Auth::attempt('USERNAME'=> $username , 'USER_PASS'=>$pass);

but this always return false . why ?

from laravel-oci8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.