57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
|
<?php
|
||
|
namespace App\Controller;
|
||
|
|
||
|
use App\Definition\Controller;
|
||
|
use App\Contract\Auth as sAuth;
|
||
|
|
||
|
class Auth
|
||
|
{
|
||
|
use Controller;
|
||
|
|
||
|
public static function login()
|
||
|
{
|
||
|
return view('auth.login');
|
||
|
}
|
||
|
public static function do_login()
|
||
|
{
|
||
|
$name = post('name');
|
||
|
$password = post('password');
|
||
|
$bool = sAuth::login($name, $password);
|
||
|
if ($bool) {
|
||
|
header('Location: .');
|
||
|
} else {
|
||
|
header('Location: ' . url('', ['p' => 'auth', 'a' => 'login']));
|
||
|
}
|
||
|
}
|
||
|
public static function logout()
|
||
|
{
|
||
|
sAuth::logout();
|
||
|
header('Location: .');
|
||
|
}
|
||
|
public static function check_pass()
|
||
|
{
|
||
|
if (\password_verify(post('password'), sAuth::User()->password)) {
|
||
|
return 'OK';
|
||
|
}
|
||
|
return 'KO';
|
||
|
}
|
||
|
public static function change_pass()
|
||
|
{
|
||
|
return view('auth.change_pass');
|
||
|
}
|
||
|
public static function do_change_pass()
|
||
|
{
|
||
|
if (\password_verify(post('old'), sAuth::User()->password)) {
|
||
|
if (post('new') == post('new2')) {
|
||
|
$user = sAuth::User();
|
||
|
$user->password(post('new'));
|
||
|
$user->save();
|
||
|
header('Location: .');
|
||
|
die();
|
||
|
}
|
||
|
}
|
||
|
header('Location: ' . url('', ['p' => 'auth', 'a' => 'change_pass']));
|
||
|
}
|
||
|
}
|
||
|
?>
|