In code with the comment "THIS IS NOT WORKING", I can't authorize.
I get user object and use Auth::login($user)
but it doesn't work.
User in this moment creates in database.
public function login(Request $request)
{
if(Auth::check()) {
return redirect('/');
}
if($request->isMethod('post')) {
if($request->has('username') && $request->has('password')) {
$inputs = $request->except('_token');
$auth = Auth::attempt(['username' => $inputs['username'], 'password' => $inputs['password']]);
if(!$auth) {
$user_i3 = Client::whereUserUsername($inputs['username'])->whereUserPassword($inputs['password'])->first();
if($user_i3) {
$user = SystemUser::create([
'uid' => $this->generateUid(),
'username' => $user_i3->user_username,
'email' => $user_i3->user_email,
'password' => bcrypt($user_i3->user_password),
'name' => $user_i3->user_name,
'is_employee' => 0,
'object_i3' => serialize($user_i3)
]);
Auth::login($user);
} else {
$user_ad = $this->getActiveDirectoryData($inputs['username'], $inputs['password']);
if($user_ad) {
$name = ucwords(str_replace('.', ' ', str_replace('@latakko.lv', '', $inputs['username'])));
$user = SystemUser::create([
'uid' => $this->generateUid(),
'username' => $inputs['username'],
'email' => $inputs['username'],
'password' => bcrypt($inputs['password']),
'name' => $name,
'is_employee' => 1
]);
// THIS IS NOT WORKING
Auth::login($user);
}
}
return (Auth::check()) ? redirect()->route('home') : redirect()->back()->with('form_error', true);
} else {
return redirect()->route('home');
}
}
}
return view('pages.auth.login');
}
User.php maybe here is something wrong?
namespace App\Models\system;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
protected $primaryKey = 'uid';
protected $table = 'eltk.dbo.system_users';
protected $guarded = [];
protected $hidden = ['password', 'remember_token'];
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire