Commit 8d39e3cd authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FIX(creating an account): remove the avatar field

remove the avatar field to avoid the bug of adding a user

Refs: #941
parent 87c6f704
Pipeline #13417 passed with stage
in 5 minutes and 8 seconds
......@@ -478,16 +478,9 @@ class UsersController extends AppController
}
$message = "";
// Get the avatar before unset it to save the user.
// The Upload plugin need an existing entity to attach a file to it.
// Note JGauthier 2019-08-28: This way of doing things does not seem to be correct.
// The addition of a user should be done in one step. I checked up the plugin doc but it's not accurate enough.
// Here's the doc: https://cakephp-upload.readthedocs.io/en/latest/examples.html
if ($this->request->is('post')) {
if (isset($this->request->data['photo']) && !$user->errors()) {
$avatar = $this->request->data['photo'];
$this->request->data['photo'] = "";
}
// do not allow to upload an avatar when creating an account
$this->request->data['photo'] = null;
// the "role" field needs a different treatment in production
// to avoid that a user can be added with an "admin" role
......@@ -511,29 +504,20 @@ class UsersController extends AppController
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$user = $this->Users->get($user->id, ['contain' => []]);
isset($avatar) ? $this->request->data['photo'] = $avatar : null;
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$message = "Success";
$this->Flash->success(__d("Forms", "Your are registred on the Comptoir du Libre, welcome !"));
if (!$this->request->is('json')) {
$currentUser = $this->Auth->identify();
$currentUser["user_type"] = $this->Users
->UserTypes
->get($currentUser["user_type_id"])->get("name");
$this->Auth->setUser($currentUser);
// REDIRECTS TO ---> /<lang>/users/<idUser>
$lang = $this->selectedLanguage;
return $this->redirect("/$lang/users/" . $user->get('id'));
// REDIRECTS TO ---> /api/v1/users/view/<idUser>
// return $this->redirect(['action' => 'view', $user->get('id')]);
}
} else {
$message = "Error";
$message = "Success";
$this->Flash->success(__d("Forms", "Your are registred on the Comptoir du Libre, welcome !"));
if (!$this->request->is('json')) {
$currentUser = $this->Auth->identify();
$currentUser["user_type"] = $this->Users
->UserTypes
->get($currentUser["user_type_id"])->get("name");
$this->Auth->setUser($currentUser);
// REDIRECTS TO ---> /<lang>/users/<idUser>
$lang = $this->selectedLanguage;
return $this->redirect("/$lang/users/" . $user->get('id'));
// REDIRECTS TO ---> /api/v1/users/view/<idUser>
// return $this->redirect(['action' => 'view', $user->get('id')]);
}
} else {
$message = "Error";
......
......@@ -94,25 +94,6 @@ $this->assign('title', __d("Forms", "Create an account {0}", $myMessage));
"escape"=>false,
]
); ?>
<?= $this->Form->input(
'photo',
[
'type' => 'file',
"label" => ["class"=>"control-label","text"=>__d("Forms", " {0} Avatar: ", '') ],
"escape"=>false,
]) ?>
<?php $help = '<div class="help-block">
<ul>';
!isset($user->photo->file) ? $help .= '<li>'.__d("Forms","Accepted formats JPEG, PNG, GIF, SVG.").'</li>' : "";
!isset($user->photo->fileBelowMaxWidth) || !isset($user->photo->fileBelowMaxHeigth) ? $help .= '<li>'.__d("Forms","Maximum size: 350x350px.").'</li>' : "";
!isset($user->photo->fileBelowMaxSize) ? $help .= '<li>'.__d("Forms","Maximum weight: 1{0}.",__d('Forms',"<abbr title='Megabit'>MB</abbr>")).'</li>' : "";
$help .='</ul>
</div>';
echo $help;
?>
</fieldset>
<?= $this->Form->button(__d("Forms","Sign up"),["class"=>"btn btn-default addmore", "id" => "submit_signUpForm", "name" => "submit_signUpForm" ]) ?>
<?= $this->Form->end() ?>
......
......@@ -211,19 +211,19 @@ class UsersControllerTest extends ApiIntegrationTestCase
$userId = $user->id;
//Check in files directory
$this->assertFileExists(
WWW_ROOT . 'img' . DS
. "files/Users/photo/$userId/avatar/"
. $this->correctFile["name"]
);
// $this->assertFileExists(
// WWW_ROOT . 'img' . DS
// . "files/Users/photo/$userId/avatar/"
// . $this->correctFile["name"]
// );
//Delete the file after testing
unlink(WWW_ROOT . 'img' . DS . "files/Users/photo/$userId/avatar/" . $this->correctFile["name"]);
$this->assertFileNotExists(
WWW_ROOT . 'img' . DS
. "files/Users/photo/$userId/avatar/"
. $this->correctFile["name"]
);
// unlink(WWW_ROOT . 'img' . DS . "files/Users/photo/$userId/avatar/" . $this->correctFile["name"]);
// $this->assertFileNotExists(
// WWW_ROOT . 'img' . DS
// . "files/Users/photo/$userId/avatar/"
// . $this->correctFile["name"]
// );
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment