Exemple #1
0
 /**
  * Initialize hook.
  *
  * @param array $config The config for this behavior.
  * @return void
  */
 public function initialize(array $config)
 {
     $config = Hash::merge($this->_defaultConfig, $config);
     $this->_path = EntityPath::getInstance('users');
     $this->config($config);
 }
Exemple #2
0
 /**
  * Remove avatar action.
  *
  * @param null $key
  * @return void|\Cake\Network\Response
  */
 public function removeAvatar($key = null)
 {
     if (!$this->Auth->user('id')) {
         $this->Flash->error(__d('community', 'You are not logged in'));
         $this->redirect($this->Auth->config('loginAction'));
     }
     $user = $this->Users->get($this->Auth->user('id'), ['contain' => []]);
     if (base64_decode($key) === 'user' . $user->get('id')) {
         $Path = EntityPath::getInstance('users');
         $fullPath = $Path->entityFolderPath($user->get('id'), DS);
         $Folder = new Folder($fullPath);
         $user->set('image', null);
         if ($Folder->delete() && $this->Users->save($user)) {
             $this->Flash->success(__d('community', '«{0}», you have deleted an image, please upload the new', sprintf('<strong>%s</strong>', $user->get('name'))));
         } else {
             $this->Flash->error(__d('community', '«{0}», an error has occurred, please try again', sprintf('<strong>%s</strong>', $user->get('name'))));
         }
     } else {
         $this->Flash->error(__d('community', '«{0}», you can not make this action', sprintf('<strong>%s</strong>', $user->get('name'))));
     }
     return $this->redirect(['action' => 'edit']);
 }