Login Done
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||
|
||||
if (!isset($_SESSION['id'])) {
|
||||
http_response_code(401);
|
||||
exit;
|
||||
http_response_code(401);
|
||||
exit;
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
echo 'ok';
|
||||
echo json_encode([
|
||||
"res" => "res.user.login.true",
|
||||
"displayname" => $_SESSION['displayname']
|
||||
]);
|
||||
+14
-9
@@ -2,8 +2,8 @@
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||
|
||||
if ($_ENV['DEV_EMAIL']) {
|
||||
$email = $_ENV['DEV_EMAIL'];
|
||||
if (isset($_ENV['DEV_LOGIN'])) {
|
||||
$email = $_POST['username'];
|
||||
$find = $conn->prepare("SELECT user_id, username, display_name FROM users WHERE email = :email");
|
||||
$find->execute([':email' => $email]);
|
||||
$obstojeciUporabnik = $find->fetch();
|
||||
@@ -22,30 +22,33 @@ if ($_ENV['DEV_EMAIL']) {
|
||||
|
||||
use LdapRecord\Connection;
|
||||
$nimrodLDAP = new Connection([
|
||||
'hosts' => [getenv('LDAP_HOST')],
|
||||
'hosts' => [$_ENV['LDAP_HOST']],
|
||||
'port' => 389,
|
||||
'base_dn' => getenv('LDAP_BASEDN'),
|
||||
'username' => getenv('LDAP_USER'),
|
||||
'password' => getenv('LDAP_SECRET')
|
||||
'base_dn' => $_ENV['LDAP_BASEDN'],
|
||||
'username' => $_ENV['LDAP_USER'],
|
||||
'password' => $_ENV['LDAP_SECRET']
|
||||
]);
|
||||
|
||||
if (!isset($_POST['uporabnik']) || !isset($_POST['geslo'])) {
|
||||
if (!isset($_POST['username']) || !isset($_POST['pass'])) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "error.user.login.missing"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$username = $_POST['uporabnik'];
|
||||
$geslo = $_POST['geslo'];
|
||||
$username = $_POST['username'];
|
||||
$geslo = $_POST['pass'];
|
||||
|
||||
try {
|
||||
$nimrodLDAP->connect();
|
||||
} catch (Exception $e) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "error.user.login.connect"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$LUser = $nimrodLDAP->query()->findBy('samaccountname', $username);
|
||||
if (empty($LUser)) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "error.user.login.notFound"]);
|
||||
exit;
|
||||
}
|
||||
@@ -53,6 +56,7 @@ if (empty($LUser)) {
|
||||
$emailUserja = $LUser['userprincipalname'][0];
|
||||
$user = $LUser['distinguishedname'][0];
|
||||
if (!$nimrodLDAP->auth()->attempt($user, $geslo, $stayAuthenticated = true)) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "error.user.login.wrongPassword"]);
|
||||
exit;
|
||||
}
|
||||
@@ -67,6 +71,7 @@ $razlikaGrup = array_intersect(
|
||||
array_map('strtolower', $dGrupe)
|
||||
);
|
||||
if (count($razlikaGrup) <= 0) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["error" => "error.user.login.groupRight"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
echo json_encode(["res" => "res.user.loginout.true"]);
|
||||
Reference in New Issue
Block a user