Token for groups

This commit is contained in:
RundelhausCode 2021-03-09 13:16:34 +01:00
parent fbdf9e675c
commit 46afda4622
5 changed files with 37 additions and 17 deletions

View File

@ -4,6 +4,7 @@ require "../../../bootstrap.php";
use Backend\Models\Group;
use Backend\Models\Password;
use Illuminate\Support\Str;
//Start the php session
session_start();
@ -17,20 +18,30 @@ if(isset($_POST['login'])){
if($group){
$hashedPassword = $group->password->password;
if(password_verify($password, $hashedPassword )){
$_SESSION['groupName'] = $groupName;
$_SESSION['groupId'] = $group->id;
$_SESSION['success'] = "You are now logged in";
header('location: ../Frontend/index.php?login=success');
$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');
header('location: ../../../Frontend/index.php?login=failed&?reason=password');
}
}
else{
session_destroy();
header('location: ../Frontend/index.php?login=failed?reason=group');
header('location: ../../../Frontend/index.php?login=failed&?reason=group');
}

View File

@ -5,6 +5,7 @@ require "../../../bootstrap.php";
use Backend\Models\Group;
use Backend\Models\Password;
use Backend\Models\GameJam;
use Illuminate\Support\Str;
session_start();
@ -33,7 +34,7 @@ if(isset($_POST['reg_group'])){
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
$token = OAuthProvider::generateToken(100);
$token = Str::random(100);
$password->remember_token = $token;

View File

@ -2,14 +2,23 @@
require "../../../bootstrap.php";
use Backend\Models\Group;
use Backend\Models\Password;
session_start();
if(isset($_SESSION['groupId'])){
if (isset($_POST['updateGroup'])) {
$_POST['updateGroup']
if($group = Group::find($_POST['groupId'])){
if ($group->password->remember_token === $_SESSION['token']){
$group->group_name = $_POST['group_name'];
$group->group_amount = $_POST['group_amount'];
$group->game_jam_id = $_POST['game_jam_id'];
$group->save();
}
}
}
}

View File

@ -1,7 +1,6 @@
{
"require": {
"illuminate/database": "^8.30",
"ext-oauth": "*"
},
"autoload": {
"classmap": [

10
composer.lock generated
View File

@ -438,16 +438,16 @@
},
{
"name": "nesbot/carbon",
"version": "2.45.1",
"version": "2.46.0",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "528783b188bdb853eb21239b1722831e0f000a8d"
"reference": "2fd2c4a77d58a4e95234c8a61c5df1f157a91bf4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/528783b188bdb853eb21239b1722831e0f000a8d",
"reference": "528783b188bdb853eb21239b1722831e0f000a8d",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/2fd2c4a77d58a4e95234c8a61c5df1f157a91bf4",
"reference": "2fd2c4a77d58a4e95234c8a61c5df1f157a91bf4",
"shasum": ""
},
"require": {
@ -527,7 +527,7 @@
"type": "tidelift"
}
],
"time": "2021-02-11T18:30:17+00:00"
"time": "2021-02-24T17:30:44+00:00"
},
{
"name": "psr/container",