Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…User into develop
  • Loading branch information
gregorybesson committed Apr 12, 2019
2 parents 6b18375 + 8dd1f3c commit 8c893c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
48 changes: 18 additions & 30 deletions src/Controller/Frontend/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,22 +506,17 @@ public function profileAction()

$request = $this->getRequest();
// I don't want to rely on the browser's info for these key datas
$request->getPost()->set('identity', $this->getUserService()
->getAuthService()
->getIdentity()
->getEmail());
$request->getPost()->set('email', $this->getUserService()
->getAuthService()
->getIdentity()
->getEmail());
$userId = $this->getUserService()
->getAuthService()
->getIdentity()
->getId();
$request->getPost()->set(
'identity',
$this->getUserService()->getAuthService()->getIdentity()->getEmail()
);
$request->getPost()->set(
'email',
$this->getUserService()->getAuthService()->getIdentity()->getEmail()
);
$userId = $this->getUserService()->getAuthService()->getIdentity()->getId();

$user = $this->getUserService()
->getUserMapper()
->findById($userId);
$user = $this->getUserService()->getUserMapper()->findById($userId);
$formInfo->bind($user);

$username = $formInfo->get('username')->getValue();
Expand All @@ -532,28 +527,22 @@ public function profileAction()
$usernamePoint = '';
}

$fmPassword = $this->flashMessenger()
->setNamespace('change-password')
->getMessages();
$fmPassword = $this->flashMessenger()->setNamespace('change-password')->getMessages();

if (isset($fmPassword[0])) {
$statusPassword = $fmPassword[0];
} else {
$statusPassword = null;
}

$fmEmail = $this->flashMessenger()
->setNamespace('change-email')
->getMessages();
$fmEmail = $this->flashMessenger()->setNamespace('change-email')->getMessages();
if (isset($fmEmail[0])) {
$statusEmail = $fmEmail[0];
} else {
$statusEmail = null;
}

$fmInfo = $this->flashMessenger()
->setNamespace('change-info')
->getMessages();
$fmInfo = $this->flashMessenger()->setNamespace('change-info')->getMessages();
if (isset($fmInfo[0])) {
$statusInfo = $fmInfo[0];
} else {
Expand All @@ -565,9 +554,10 @@ public function profileAction()
$data = $request->getPost()->toArray();
$file = $this->params()->fromFiles('avatar');
if ($file['name']) {
$data = array_merge($data, array(
'avatar' => $file['name']
));
$data = array_merge(
$data,
['avatar' => $file['name']]
);
}

$result = $this->getUserService()->updateInfo($data, $user);
Expand All @@ -586,9 +576,7 @@ public function profileAction()
);
}

$this->flashMessenger()
->setNamespace('change-info')
->addMessage(true);
$this->flashMessenger()->setNamespace('change-info')->addMessage(true);

$redirect = (!empty($this->params()->fromQuery('redirect')))?
$this->params()->fromQuery('redirect'):
Expand Down
14 changes: 12 additions & 2 deletions src/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function create(array $data)
$form->bind($user);

$avatarPath = $this->getOptions()->getAvatarPath() . DIRECTORY_SEPARATOR;
if (!is_dir($avatarPath)) {
mkdir($avatarPath, 0777, true);
}
$avatarUrl = $this->getOptions()->getAvatarUrl() . '/';

$clearPassword = (isset($data['password']))? $data['password'] : '';
Expand Down Expand Up @@ -215,6 +218,9 @@ public function edit(array $data, $user)
$zfcUserOptions = $this->getServiceManager()->get('zfcuser_module_options');
$class = $zfcUserOptions->getUserEntityClass();
$path = $this->getOptions()->getAvatarPath() . DIRECTORY_SEPARATOR;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$avatar_url = $this->getOptions()->getAvatarUrl() . '/';
$roleMapper = $this->getRoleMapper();
$defaultRegisterRole = $this->getOptions()->getDefaultRegisterRole();
Expand Down Expand Up @@ -578,10 +584,13 @@ public function updateInfo(array $data, $user)

$data['id'] = $user->getId();
$avatarPath = $this->getOptions()->getAvatarPath() . DIRECTORY_SEPARATOR;
if (!is_dir($avatarPath)) {
mkdir($avatarPath, 0777, true);
}
$avatarUrl = $this->getOptions()->getAvatarUrl() . '/';

// If avatar is set, I prepend the url path to the image
$fileName=null;
$fileName = null;
if (isset($data['avatar'])) {
$fileName = $data['avatar'];
$data['avatar'] = $avatarUrl . $fileName;
Expand Down Expand Up @@ -638,7 +647,8 @@ public function updateInfo(array $data, $user)
$form->setMessages(array('avatar'=>$error ));
} else {
$adapter->setDestination($avatarPath);
if ($adapter->receive($fileName)) {
if ($adapter->receive()) {
$user->setAvatar($avatarUrl . $adapter->getFileName(null, false));
$user = $this->getUserMapper()->update($user);
$this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('user' => $user, 'data' => $data));

Expand Down

0 comments on commit 8c893c9

Please sign in to comment.