. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 94.23.64.18 / Your IP :
216.73.216.185 [
Web Server : Apache System : Linux webm005.cluster107.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : villadal ( 6036) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl Domains : 2 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/villadal/www/old/booked/lib/Application/Authentication/ |
Upload File : |
<?php
/**
Copyright 2011-2014 Nick Korbel
Copyright 2012-2014 Moritz Schepp, IST Austria
This file is part of Booked SchedulerBooked SchedulereIt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later versBooked SchedulerduleIt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
alBooked SchedulercheduleIt. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(ROOT_DIR . 'lib/Application/Authentication/namespace.php');
require_once(ROOT_DIR . 'lib/Common/namespace.php');
require_once(ROOT_DIR . 'lib/Database/namespace.php');
require_once(ROOT_DIR . 'lib/Database/Commands/namespace.php');
require_once(ROOT_DIR . 'Domain/Values/RoleLevel.php');
class Authentication implements IAuthentication
{
/**
* @var PasswordMigration
*/
private $passwordMigration = null;
/**
* @var IRoleService
*/
private $roleService;
/**
* @var IUserRepository
*/
private $userRepository;
public function __construct(IRoleService $roleService, IUserRepository $userRepository)
{
$this->roleService = $roleService;
$this->userRepository = $userRepository;
}
public function SetMigration(PasswordMigration $migration)
{
$this->passwordMigration = $migration;
}
/**
* @return PasswordMigration
*/
private function GetMigration()
{
if (is_null($this->passwordMigration))
{
$this->passwordMigration = new PasswordMigration();
}
return $this->passwordMigration;
}
public function Validate($username, $password)
{
if (($this->ShowUsernamePrompt() && empty($username)) || ($this->ShowPasswordPrompt() && empty($password)))
{
return false;
}
Log::Debug('Trying to log in as: %s', $username);
$command = new AuthorizationCommand($username);
$reader = ServiceLocator::GetDatabase()->Query($command);
$valid = false;
if ($row = $reader->GetRow())
{
Log::Debug('User was found: %s', $username);
$migration = $this->GetMigration();
$password = $migration->Create($password, $row[ColumnNames::OLD_PASSWORD], $row[ColumnNames::PASSWORD]);
$salt = $row[ColumnNames::SALT];
if ($password->Validate($salt))
{
$password->Migrate($row[ColumnNames::USER_ID]);
$valid = true;
}
}
Log::Debug('User: %s, was validated: %d', $username, $valid);
return $valid;
}
public function Login($username, $loginContext)
{
Log::Debug('Logging in with user: %s', $username);
$user = $this->userRepository->LoadByUsername($username);
if ($user->StatusId() == AccountStatus::ACTIVE)
{
$loginData = $loginContext->GetData();
$loginTime = LoginTime::Now();
$language = $user->Language();
if (!empty($loginData->Language))
{
$language = $loginData->Language;
}
$user->Login($loginTime, $language);
$this->userRepository->Update($user);
return $this->GetUserSession($user, $loginTime);
}
return new NullUserSession();
}
public function Logout(UserSession $userSession)
{
// hook for implementing Logout logic
}
public function AreCredentialsKnown()
{
return false;
}
public function HandleLoginFailure(IAuthenticationPage $loginPage)
{
$loginPage->SetShowLoginError();
}
/**
* @param User $user
* @param string $loginTime
* @return UserSession
*/
private function GetUserSession(User $user, $loginTime)
{
$userSession = new UserSession($user->Id());
$userSession->Email = $user->EmailAddress();
$userSession->FirstName = $user->FirstName();
$userSession->LastName = $user->LastName();
$userSession->Timezone = $user->Timezone();
$userSession->HomepageId = $user->Homepage();
$userSession->LanguageCode = $user->Language();
$userSession->LoginTime = $loginTime;
$userSession->PublicId = $user->GetPublicId();
$userSession->ScheduleId = $user->GetDefaultScheduleId();
$userSession->IsAdmin = $this->roleService->IsApplicationAdministrator($user);
$userSession->IsGroupAdmin = $this->roleService->IsGroupAdministrator($user);
$userSession->IsResourceAdmin = $this->roleService->IsResourceAdministrator($user);
$userSession->IsScheduleAdmin = $this->roleService->IsScheduleAdministrator($user);
foreach ($user->Groups() as $group)
{
$userSession->Groups[] = $group->GroupId;
}
return $userSession;
}
public function ShowUsernamePrompt()
{
return true;
}
public function ShowPasswordPrompt()
{
return true;
}
public function ShowPersistLoginPrompt()
{
return true;
}
public function ShowForgotPasswordPrompt()
{
return true;
}
}
?>