die("Pirate reconnu !"); } if (!isset($_POST['user_mail'])) { include_once 'view/auth/register-team.php'; } else { $form = $_POST; if ($form['user_password'] != $form['user_password_2'] || $form['team_password'] != $form['team_password_2']) { header('Location: ?module=auth&action=register-team&error=password'); } else { require_once 'model/auth/register-team.php'; require_once 'model/auth/register-user.php'; require_once 'model/auth/set-team-as-user.php'; require_once 'model/auth/get-session-param.php'; $form['user_password'] = md5($form['user_password']); $form['team_password'] = md5($form['team_password']); $team = register_team($form); $user = register_user($form); if ($team && $user) { $both = set_team_as_user($form); if ($both) { $session_param = get_session_param($form); $_SESSION['user_ID'] = $session_param['0']['ID']; $_SESSION['user_login'] = $session_param['0']['login']; $_SESSION['team_ID'] = $session_param['1']['ID']; $_SESSION['team_name'] = $session_param['1']['name']; header('Location: ?module=home'); } else { header('Location: ?module=auth&action=register-team&error=teamasuser'); } } else { if (!$team && $user) {
function handle_team_registration($bid, $pin, $extra_args = array()) { $team_registration = sanitized_team_registration(); $user = get_user($bid); $tid = $user["tid"]; $team = get_team($tid); $team_members = get_team_members($tid); // Choose appropriate action to perform. if (strcmp($team_registration["teamRegistrationAction"], "remove") == 0) { $userToRemove = get_user($team_registration["teamRegistrationBid"]); if ($userToRemove != null && $userToRemove["tid"] == $tid) { assign_user_to_team($userToRemove["bid"], PASSPORT_NO_TEAM_TID); log_entry(LOG_MODE_USER, LOG_USER_ACTION_REMOVE_TEAM_MEMBER, array("actorUid" => $user["uid"], "actorBid" => $user["bid"], "targetUid" => $user_to_add["uid"], "targetBid" => $user_to_add["bid"], "targetTid" => PASSPORT_NO_TEAM_TID, comment => addslashes(serialize($team_registration)))); $team = get_team($tid); $team_members = get_team_members($tid); return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "teamMemberJustRemoved" => $user_to_remove, "teamMembers" => $team_members, "team" => $team) + $extra_args); } } else { if (strcmp($team_registration["teamRegistrationAction"], "create") == 0) { if (valid_team_name($team_registration["teamName"])) { $tid = register_team($team_registration["teamName"], $user["uid"]); log_entry(LOG_MODE_USER, LOG_USER_ACTION_CREATE_TEAM, array("actorUid" => $user["uid"], "actorBid" => $user["bid"], "targetTid" => $tid, comment => addslashes(serialize($team_registration)))); if ($tid == PASSPORT_NO_TEAM_TID) { return array("view" => "team_registration_create", "args" => array("bid" => $bid, "pin" => $pin) + $extra_args); } assign_user_to_team($bid, $tid); log_entry(LOG_MODE_USER, LOG_USER_ACTION_ADD_TEAM_MEMBER, array("actorUid" => $user["uid"], "actorBid" => $user["bid"], "targetUid" => $user["uid"], "targetBid" => $user["bid"], "targetTid" => $tid, comment => addslashes(serialize($team_registration)))); $team_members = get_team_members($tid); $team = get_team($tid); return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "teamJustCreated" => true, "teamMembers" => $team_members, "team" => $team) + $extra_args); } else { return array("view" => "team_registration_create", "args" => array("bid" => $bid, "pin" => $pin, "teamNameInvalid" => true) + $extra_args); } } else { if (strcmp($team_registration["teamRegistrationAction"], "add") == 0) { $user = get_user($bid); $team = get_team($user["tid"]); $team_members = get_team_members($user["tid"]); if (count($team_members) < MAX_TEAM_MEMBERS) { if (validate_login($team_registration["teamRegistrationBid"], $team_registration["teamRegistrationPin"])) { $user_to_add = get_user($team_registration["teamRegistrationBid"]); if ($user_to_add["tid"] == PASSPORT_NO_TEAM_TID) { assign_user_to_team($user_to_add["bid"], $tid); log_entry(LOG_MODE_USER, LOG_USER_ACTION_ADD_TEAM_MEMBER, array("actorUid" => $user["uid"], "actorBid" => $user["bid"], "targetUid" => $user_to_add["uid"], "targetBid" => $user_to_add["bid"], "targetTid" => $tid, comment => addslashes(serialize($team_registration)))); $team_members = get_team_members($user["tid"]); return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "teamMemberJustAdded" => $user_to_add, "teamMembers" => $team_members, "team" => $team) + $extra_args); } else { return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "alreadyOnTeam" => true, "teamMembers" => $team_members, "team" => $team) + $extra_args); } } else { return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "teamMemberBad" => true, "teamMembers" => $team_members, "team" => $team) + $extra_args); } } else { return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "teamFull" => true, "teamMembers" => $team_members, "team" => $team) + $extra_args); } } } } // No action specified, just need to show the user the current members. return array("view" => "team_registration_add", "args" => array("bid" => $bid, "pin" => $pin, "teamMembers" => $team_members, "team" => $team) + $extra_args); }