Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

[Tournament] Allow a captain to edit his team's name and password #44

Merged
merged 1 commit into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/InsaLan/TournamentBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,55 @@ public function leaveTeamAction($teamId) {
return $this->redirect($this->generateUrl('insalan_tournament_user_index'));
}

/**
* Allow a captain to edit his team's name and password
* @Route("/user/edit/team/{teamId}")
* @Template()
*/

public function editTeamAction(Request $request, $teamId) {
$em = $this->getDoctrine()->getManager();

$team = $em
->getRepository('InsaLanTournamentBundle:Team')
->findOneById($teamId);

// does the team exist ?
if($team === null)
return $this->redirect($this->generateUrl('insalan_tournament_user_index'));

// get current logged user corresponding player
$usr = $this->get('security.context')->getToken()->getUser();
$captain = $em
->getRepository('InsaLanTournamentBundle:Player')
->findOneByUserAndPendingTournament($usr, $team->getTournament());

// is he really the captain ? (also check for null)
if($team->getCaptain() !== $captain)
return $this->redirect($this->generateUrl('insalan_tournament_user_index'));

$form = $this->createForm(new TeamType(), $team);
$form->handleRequest($request);

if ($form->isValid()) {
// update password if not empty
if ($team->getPlainPassword() != ""){
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($usr);
$team->setPassword($encoder->encodePassword($team->getPlainPassword(), $team->getPasswordSalt()));
}

$em->persist($team);
$em->flush();

return $this->redirect($this->generateUrl('insalan_tournament_user_index'));
}

$tournament = $team->getTournament();

return array('team' => $team, 'tournament' => $tournament, 'form' => $form->createView());
}

/**
* Allow a captain to ban another player from a team
* Only possible if the player didn't pay anything yet OR if this is a free tournament
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% extends 'InsaLanTournamentBundle:User:layout.html.twig' %}

{% block body %}
{{ parent() }}

<article>
<aside>
<div class="square">
<a href="#body"><span></span></a>
</div>
</aside>

<header>
<h2>Inscription à &laquo; {{ tournament.name }} &raquo;</h2>
{{ tournament.description }}
</header>

<section>

<div class="frame frame-active">
<header class="full">
<div class="step pull-left">&#x2699;</div>
<div class="title pull-left">Modifier une équipe</div>
<br class="clear">
</header>

<form action="{{ path('insalan_tournament_user_editteam', {teamId: team.id}) }}" id="step1" method="post" {{ form_enctype(form) }}>

{{ form_widget(form._token) }}
{{ form_errors(form) }}

<div class="input field">
{{ form_widget(form.name, {'attr': {'placeholder': 'Nom de votre équipe'}}) }}
</div>

<div class="input field">
{{ form_widget(form.plainPassword.first, {'attr': {'placeholder': 'Nouveau mot de passe (Laissez vide pour ne pas modifier)'}}) }}
</div>

<div class="input field">
{{ form_widget(form.plainPassword.second, {'attr': {'placeholder': 'Confirmation de mot de passe'}}) }}
</div>

<a class="btn btn-danger ctrl grid-2 pull-left" href="{{ path('insalan_tournament_user_index') }}">Annuler</a>
<a class="btn btn-primary ctrl grid-8 pull-left" href="javascript:{}" onclick="document.getElementById('step1').submit();">Modifier mon équipe</a>
<br class="clear">
</form>
</div>

</section>
</article>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
{% if participant.validated == 2 %} &#10003; {% else %} ! {% endif %}
</div>
<div class="title pull-left">
{% if participant.participantType == 'team' %}
{% if participant.captain.user == app.user %} <a href="{{ path('insalan_tournament_user_editteam', {teamId: participant.id}) }}">&#x2699;</a> {% endif %}
{% endif %}
{{ participant.tournament.name }} -
{% if participant.participantType == 'team' %} Équipe {% endif %}
{{ participant.name }}
Expand Down