2021-03-04 08:18:32 +00:00
|
|
|
<?php
|
2021-03-04 12:13:07 +00:00
|
|
|
|
2021-03-17 08:43:09 +00:00
|
|
|
require "../../../bootstrap.php";
|
2021-03-04 12:13:07 +00:00
|
|
|
|
|
|
|
use Backend\Models\Group;
|
|
|
|
use Backend\Models\Password;
|
2021-03-09 12:16:34 +00:00
|
|
|
use Illuminate\Support\Str;
|
2021-03-04 12:13:07 +00:00
|
|
|
|
|
|
|
//Start the php session
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
if(isset($_POST['login'])){
|
|
|
|
|
|
|
|
$groupName = $_POST["groupName"];
|
|
|
|
$password = $_POST["password"];
|
|
|
|
|
2021-03-08 12:09:50 +00:00
|
|
|
$group = Group::firstWhere('group_name', $groupName );
|
2021-03-04 12:13:07 +00:00
|
|
|
if($group){
|
2021-03-04 13:12:14 +00:00
|
|
|
$hashedPassword = $group->password->password;
|
2021-03-04 12:13:07 +00:00
|
|
|
if(password_verify($password, $hashedPassword )){
|
2021-03-09 12:16:34 +00:00
|
|
|
$token = Str::random(100);
|
2021-03-11 08:28:30 +00:00
|
|
|
$groupPassword = Password::firstWhere('group_id', $group->id);
|
|
|
|
$groupPassword->remember_token = $token;
|
|
|
|
if($groupPassword->save()){
|
2021-03-09 12:16:34 +00:00
|
|
|
$_SESSION['token'] = $token;
|
|
|
|
$_SESSION['success'] = "You are now logged in";
|
2021-03-25 08:24:55 +00:00
|
|
|
makeLogin($groupName,$group->id);
|
2021-03-19 12:25:27 +00:00
|
|
|
//header('location: ../../../Frontend/index.php?login=success');
|
|
|
|
//exit();
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(200);
|
2021-03-09 12:16:34 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
session_destroy();
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(500);
|
2021-03-09 12:16:34 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 09:05:31 +00:00
|
|
|
}else{
|
|
|
|
session_destroy();
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(401);
|
|
|
|
echo json_encode(["message" => "Wrong password"]);
|
2021-03-04 12:13:07 +00:00
|
|
|
}
|
2021-03-08 09:05:31 +00:00
|
|
|
|
2021-03-19 12:25:27 +00:00
|
|
|
}else{
|
2021-03-08 09:05:31 +00:00
|
|
|
session_destroy();
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(401);
|
|
|
|
echo json_encode(["message" => "group was not found"]);
|
2021-03-04 12:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 09:50:29 +00:00
|
|
|
}else{
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(400);
|
2021-03-12 10:10:14 +00:00
|
|
|
}
|