generated from Templates_CodeFirst/templateHtmlCss
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
<?php
|
|
|
|
|
|
class MdlUser{
|
|
|
|
private $con;
|
|
|
|
public function __construct(Connection $con){
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function getUserForConnection(string $username, string $password): ?User{
|
|
if (!empty($username) && !empty($password)){
|
|
$results=[];
|
|
$gate=new UserGateway($this->con);
|
|
$results=$gate->findByNamePassword($username, $password);
|
|
if (!empty($results)){
|
|
$user=new User($results[0]['id'], $results[0]['username'], $results[0]['password']);
|
|
return $user;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function insert(string $username, string $password): ?User{
|
|
$gate=new UserGateway($this->con);
|
|
$results=$gate->findByName($username);
|
|
if ($results==null){
|
|
$u=new User(0, $username, $password);
|
|
$gate->insert($u);
|
|
$id=$gate->getLastId();
|
|
$u->setId($id[0]['oldId']);
|
|
return $u;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function delete(User $user){
|
|
$gate=new UserGateway($this->con);
|
|
$gate->delete($user);
|
|
}
|
|
|
|
public function update(User $user, string $username, string $password){
|
|
$user->setUsername($username);
|
|
$user->setPassword($password);
|
|
$gate=new UserGateway($this->con);
|
|
$gate->update($user);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|