41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Services\Dav;
 | 
						|
 | 
						|
use App\Models\User;
 | 
						|
use Illuminate\Support\Facades\Hash;
 | 
						|
use Illuminate\Support\Facades\Log;
 | 
						|
use Sabre\DAV\Auth\Backend\AbstractBasic;
 | 
						|
use Sabre\DAV\Auth\Backend\BasicCallBack;
 | 
						|
 | 
						|
class LaravelSabreAuthBackend extends AbstractBasic
 | 
						|
{
 | 
						|
    public function __construct()
 | 
						|
    {
 | 
						|
        \Log::info('LaravelSabreAuthBackend instantiated');
 | 
						|
    }
 | 
						|
 | 
						|
    protected function validateUserPass($username, $password)
 | 
						|
    {
 | 
						|
        $user = User::where('email', $username)->first();
 | 
						|
 | 
						|
        if ($user && Hash::check($password, $user->password)) {
 | 
						|
            // THIS is the new required step
 | 
						|
            $this->currentPrincipal = 'principals/' . $user->email;
 | 
						|
 | 
						|
            \Log::info('SabreDAV auth success', ['principal' => $this->currentPrincipal]);
 | 
						|
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
 | 
						|
        \Log::warning('SabreDAV auth failed', ['username' => $username]);
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getCurrentPrincipal()
 | 
						|
    {
 | 
						|
        \Log::debug('SabreDAV getCurrentPrincipal', ['current' => $$this->currentPrincipal]);
 | 
						|
        return $this->currentPrincipal;
 | 
						|
    }
 | 
						|
}
 |