diff --git a/src/Controller/Frontend/UserController.php b/src/Controller/Frontend/UserController.php index 3e0ff36..8bef849 100644 --- a/src/Controller/Frontend/UserController.php +++ b/src/Controller/Frontend/UserController.php @@ -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(); @@ -532,9 +527,7 @@ 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]; @@ -542,18 +535,14 @@ public function profileAction() $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 { @@ -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); @@ -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'): diff --git a/src/Service/User.php b/src/Service/User.php index 219df88..493a7d3 100644 --- a/src/Service/User.php +++ b/src/Service/User.php @@ -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'] : ''; @@ -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(); @@ -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; @@ -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));