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

50 lines
963 B
PHP
Raw Normal View History

2021-03-04 08:18:32 +00:00
<?php
2021-03-04 10:27:54 +00:00
2021-03-08 12:01:01 +00:00
require "../../../bootstrap.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
session_start();
$groupName = "";
$errors = array();
if(isset($_POST['reg_group'])){
$group = new Group();
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
2021-03-08 12:09:50 +00:00
$group->group_name = $groupName = $_POST['groupName'];
2021-03-04 10:27:54 +00:00
2021-03-08 12:09:50 +00:00
$group->group_amount = $_POST['groupAmount'];
2021-03-04 10:27:54 +00:00
if(!$group->save()){
return;
}
2021-03-05 10:23:10 +00:00
$password = New Password();
$password->group()->associate($group);
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
2021-03-09 12:16:34 +00:00
$token = Str::random(100);
2021-03-09 09:45:05 +00:00
$password->remember_token = $token;
2021-03-05 10:23:10 +00:00
if(!$password->save()){
return;
}
2021-03-04 10:27:54 +00:00
$_SESSION['groupName'] = $groupName;
2021-03-09 09:45:05 +00:00
$_SESSION['token'] = $token;
2021-03-04 10:27:54 +00:00
$_SESSION['success'] = "You are now logged in";
2021-03-09 09:45:05 +00:00
header('location: ../../../Frontend/index.php');
2021-03-04 10:27:54 +00:00
}