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();
|
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
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'])){
|
2021-03-11 08:28:30 +00:00
|
|
|
$group = new Group();
|
2021-03-04 10:27:54 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
|
2021-03-04 10:27:54 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$group->group_name = $groupName = $_POST['groupName'];
|
2021-03-04 10:27:54 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$group->group_amount = $_POST['groupAmount'];
|
2021-03-04 10:27:54 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
if(!$group->save()){
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(500);
|
|
|
|
exit();
|
2021-03-11 08:28:30 +00:00
|
|
|
}
|
2021-03-23 12:39:44 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$password = New Password();
|
2021-03-04 10:27:54 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$password->group()->associate($group);
|
2021-03-04 10:27:54 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$password->password = password_hash($pass ,PASSWORD_DEFAULT);
|
2021-03-05 10:23:10 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$token = Str::random(100);
|
2021-03-05 10:23:10 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$password->remember_token = $token;
|
2021-03-09 09:45:05 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
if(!$password->save()){
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(500);
|
|
|
|
exit();
|
2021-03-11 08:28:30 +00:00
|
|
|
}
|
2021-03-09 09:45:05 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
$_SESSION['groupName'] = $groupName;
|
|
|
|
$_SESSION['token'] = $token;
|
|
|
|
$_SESSION['success'] = "You are now logged in";
|
2021-03-25 08:33:04 +00:00
|
|
|
makeLogin($groupName,$group->id);
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(201);
|
|
|
|
echo json_encode(["message" => "you are login"]);
|
2021-03-19 12:25:27 +00:00
|
|
|
|
2021-03-11 12:20:10 +00:00
|
|
|
}else{
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(400);
|
|
|
|
echo json_encode(["message" => "password not valid"]);
|
2021-03-05 10:23:10 +00:00
|
|
|
}
|
2021-03-17 08:43:09 +00:00
|
|
|
}else{
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(400);
|
2021-03-04 10:27:54 +00:00
|
|
|
}
|