laravel 7 аутентификация не работает с jenssegers-mongodb - PullRequest
1 голос
/ 29 мая 2020
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Model\Company;
use App\Model\User;
use Crypt;
use Hash;
use Illuminate\Support\Facades\Auth;


class LoginController extends Controller
{
    public function login(Request $request) {
        $email = $request->input('email');
        $password = $request->input('password');

        $user = User::where('email', $email)->first();
        if ($user) {
            if (! $user->is_verified) {
                return response()->json(['success' => false,'message' => 'User not verified.']);
            }
            if (Auth::attempt(['email' => $email, 'password' => $password])) {
                return response()->json(['success' => true,'message' => 'Logged in successfully.']);
            }
            return response()->json(['success' => false,'message' => 'User not found.']);

        } else {
            return response()->json(['success' => false,'message' => 'User not found.']);
        }
    }
}
<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Auth\User as Authenticatable;

class User extends Authenticatable 
{
    use Notifiable;

    protected $primaryKey = '_id';

    protected $connection = 'mongodb';
    protected $collection = 'users';
    
    protected $fillable = [
        'name', 'email','password','user_type', 'company_id' , 'is_verified', 'is_active','created_at'
    ];

    public function getAuthIdentifierName(){

    }
    public function getAuthIdentifier(){

    }
    public function getAuthPassword(){

    }
    public function getRememberToken(){

    }
    public function setRememberToken($value){

    }
    public function getRememberTokenName(){
        
    }
}
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Model\Company;
use App\Model\User;
use Illuminate\Support\Facades\Hash;
use Auth;
use Mail;
use Crypt;

class RegisterController extends Controller
{
    public function userSignup(Request $request) {

        $name = $request->input('name');
        $email = $request->input('email');
        $password = Hash::make($request->input('password'));

        $user = User::where('email', $email)->first();
        if ($user) {
            return response()->json(['success' => false,'message' => 'User already exists.']);
        } else {
            $this->userSignUpProcess($name, $email, $password);
            return response()->json(['success' => true,'message' => 'User signed up successfully.Verify email to login']);
        }
    }

    private function userSignUpProcess($name, $email, $password, $company_id=0){
        $user = User::create([
            'name' =>$name,
            'email' => $email,
            'password' => $password,
            'company_id' => $company_id,
            'is_verified' => false,
            'is_active' => true
        ]);
        $hash_user_id = Crypt::encryptString($user->_id);
        Mail::send('mails.verify-account', ['hash_user_id' => $user->_id], function ($mail) use ($user) {
            $mail->from('no-reply@sbfd.com', config('app.name'));
            $mail->to($user->email)->subject('Verify Your account');
        });
    }
}

Auth::attempt(['email' => $email, 'password' => $password]) returning false. Hash::check($password, $user->password); Это возвращается истина. Использование laravel 7 auth не работает с MongoDB. Для MongoDB я использую jenssegers / mongodb 4.0.0-alpha.1 . Но теперь я столкнулся с ошибкой при создании аутентификации входа в систему на контроллере Laravel.

Любой, пожалуйста, помогите.

...