Skip to content
Snippets Groups Projects
Commit a6759dc4 authored by Moreau Elise's avatar Moreau Elise
Browse files

Modify your profile with form

parent fe5dea35
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ class ModifyUserAction extends UserAction
{
$parsedRequestBody = (array)$this->request->getParsedBody();
$id = $this->checkvalue($parsedRequestBody['id']);
$username = $this->checkvalue($parsedRequestBody['username']);
$firstname = $this->checkvalue($parsedRequestBody['firstname']);
$lastname = $this->checkvalue($parsedRequestBody['lastname']);
......@@ -41,18 +41,25 @@ class ModifyUserAction extends UserAction
)
);
}
$user_db = $this->userRepository->find($_SESSION['userId']);
if (isset($password)){
$password = password_hash($password, PASSWORD_DEFAULT);
$user_db->setPassword($password);
}
$user_db->setUsername($username);
$user_db->setFirstname($firstname);
$user_db->setLastname($lastname);
$user_db->setMail($mail);
$password = password_hash($password, PASSWORD_DEFAULT);
$user = new User(null, $username, $firstname, $lastname, $mail, 0, null, $password, null);
$this->em->find('User', $id);
$this->em->persist($user_db);
$this->em->flush();
$this->logger->info("Your account has been changed.");
return $this->twig->render(
$this->response, "/user/user_profile.twig",
["user" => $user, "id" => $user->getId()]
);
return $this->response
->withHeader('Location', '/account')
->withStatus(302);
}
/**
......
{% extends 'common/layout.twig' %}
\ No newline at end of file
{% extends 'common/layout.twig' %}
{% block content %}
<div class="form_format">
<form class="ui form {% if formstatus %} {{formstatus}} {% endif %} " action="/account/modify" method="post">
<h4 class="ui dividing header">Modify your profile</h4>
<div class="field">
<input type="text" name="firstname" id="firstname" placeholder="Firstname" value="{{user.firstname}}">
</div>
<div class="field">
<input type="text" name="lastname" id="lastname" placeholder="Lastname" value="{{user.lastname}}">
</div>
<div class="field">
<input type="text" name="username" id="username" placeholder="Username" value="{{user.username}}">
{% if username_formstatus %}
<div class="ui {{formstatus}} message">
<div class="header">Action Forbidden</div>
<p>Username already used.</p>
</div>
{% endif %}
</div>
<div class="field">
<input type="password" name="password" id="password" placeholder="Password">
</div>
<div class="field">
<input type="password" name="confirmpassword" id="confirmpassword" placeholder="Confirm your password">
{% if password_formstatus %}
<div class="ui {{formstatus}} message">
<ul class="list">
<li>{{password_message}}</li>
</ul>
</div>
{% endif %}
</div>
<div class="field">
<input type="email" name="mail" id="mail" placeholder="Email" value="{{user.mail}}">
{% if email_formstatus %}
<div class="ui {{formstatus}} message">
<ul class="list">
<li>{{email_message}}</li>
</ul>
</div>
{% endif %}
</div>
<input type="submit" class="ui submit button">
</form>
</div>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment