Game-Jaming/Backend/Controllers/Group/Login.php

48 lines
1.3 KiB
PHP

<?php
require "../../../bootstrap.php";
use Backend\Models\Group;
use Backend\Models\Password;
use Illuminate\Support\Str;
//Start the php session
session_start();
if(isset($_POST['login'])){
$groupName = $_POST["groupName"];
$password = $_POST["password"];
$group = Group::firstWhere('group_name', $groupName );
if($group){
$hashedPassword = $group->password->password;
if(password_verify($password, $hashedPassword )){
$token = Str::random(100);
$grouppassword = Password::firstWhere('group_id', $group->id);
$grouppassword->remember_token = $token;
if($grouppassword->save()){
$_SESSION['groupName'] = $groupName;
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
header('location: ../../../Frontend/index.php?login=success');
}
else{
session_destroy();
header('location: ../../../Frontend/index.php?login=failed&?reason=token');
}
}else{
session_destroy();
header('location: ../../../Frontend/index.php?login=failed&?reason=password');
}
}
else{
session_destroy();
header('location: ../../../Frontend/index.php?login=failed&?reason=group');
}
}