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

56 lines
1.3 KiB
PHP
Raw Normal View History

2021-03-04 08:18:32 +00:00
<?php
2021-03-04 10:27:54 +00:00
2021-03-16 11:46:44 +00:00
require_once "../../../bootstrap.php";
2021-03-11 12:20:10 +00:00
require_once "Group.php";
2021-03-04 12:13:07 +00:00
2021-03-04 10:27:54 +00:00
use Backend\Models\Group;
use Backend\Models\Password;
use Backend\Models\GameJam;
2021-03-09 12:16:34 +00:00
use Illuminate\Support\Str;
2021-03-04 10:27:54 +00:00
$groupName = "";
$errors = array();
if(isset($_POST['regGroup'])){
2021-03-04 10:27:54 +00:00
2021-03-12 10:10:14 +00:00
if(passwordValidate($pass = $_POST['password'])){
$group = new Group();
2021-03-04 10:27:54 +00:00
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
2021-03-04 10:27:54 +00:00
$group->group_name = $groupName = $_POST['groupName'];
2021-03-04 10:27:54 +00:00
$group->group_amount = $_POST['groupAmount'];
2021-03-04 10:27:54 +00:00
if(!$group->save()){
return;
}
$password = New Password();
2021-03-04 10:27:54 +00:00
$password->group()->associate($group);
2021-03-04 10:27:54 +00:00
$password->password = password_hash($pass ,PASSWORD_DEFAULT);
2021-03-05 10:23:10 +00:00
$token = Str::random(100);
2021-03-05 10:23:10 +00:00
$password->remember_token = $token;
2021-03-09 09:45:05 +00:00
if(!$password->save()){
return;
}
2021-03-09 09:45:05 +00:00
$_SESSION['groupName'] = $groupName;
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
2021-03-17 08:43:09 +00:00
header("location: ../../../Frontend/index.html?success=GroupRegister");
exit();
2021-03-11 12:20:10 +00:00
}else{
2021-03-17 08:43:09 +00:00
header("location: ../../../Frontend/index.html?error=CouldNotValidatePassword");
exit();
2021-03-05 10:23:10 +00:00
}
2021-03-17 08:43:09 +00:00
}else{
header("location: ../../../Frontend/index.html?error=FailedRegister");
exit();
2021-03-04 10:27:54 +00:00
}