예제 #1
0
 /**
  * Updates a backend user based on the passed
  * values.
  *
  * Note that this method needs the following
  * fields: id, username, name, email, password and admin
  *
  * @return void
  */
 public function updateUserAction()
 {
     $id = $this->Request()->getParam('id', null);
     $isNewUser = false;
     if (!empty($id)) {
         $user = $this->getUserRepository()->find($id);
     } else {
         $user = new User();
         $isNewUser = true;
     }
     try {
         $params = $this->Request()->getParams();
         if (!empty($params["password"])) {
             $params["encoder"] = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
             $params["password"] = Shopware()->PasswordEncoder()->encodePassword($params["password"], $params["encoder"]);
         } else {
             unset($params["password"]);
         }
         $params['attribute'] = $params['attribute'][0];
         $user->fromArray($params);
         // Do logout
         // $user->setSessionId('');
         Shopware()->Models()->persist($user);
         Shopware()->Models()->flush();
         if ($isNewUser) {
             $sql = "INSERT INTO `s_core_widget_views` (`widget_id`, `auth_id`) VALUES ((SELECT id FROM `s_core_widgets` WHERE `name` = :widgetName LIMIT 1), :userId);";
             Shopware()->Db()->executeQuery($sql, [':widgetName' => 'swag-shopware-news-widget', ':userId' => $user->getId()]);
         }
         $this->View()->assign(array('success' => true, 'data' => Shopware()->Models()->toArray($user)));
     } catch (Exception $e) {
         $this->View()->assign(array('success' => false, 'data' => $this->Request()->getParams(), 'message' => $e->getMessage()));
     }
 }
예제 #2
0
 /**
  * Updates a backend user based on the passed
  * values.
  *
  * Note that this method needs the following
  * fields: id, username, name, email, password and admin
  *
  * @return void
  */
 public function updateUserAction()
 {
     $id = $this->Request()->getParam('id', null);
     if (!empty($id)) {
         $user = $this->getUserRepository()->find($id);
     } else {
         $user = new User();
     }
     try {
         $params = $this->Request()->getParams();
         if (!empty($params["password"])) {
             $params["encoder"] = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
             $params["password"] = Shopware()->PasswordEncoder()->encodePassword($params["password"], $params["encoder"]);
         } else {
             unset($params["password"]);
         }
         $params['attribute'] = $params['attribute'][0];
         $user->fromArray($params);
         // Do logout
         // $user->setSessionId('');
         Shopware()->Models()->persist($user);
         Shopware()->Models()->flush();
         $this->View()->assign(array('success' => true, 'data' => Shopware()->Models()->toArray($user)));
     } catch (Exception $e) {
         $this->View()->assign(array('success' => false, 'data' => $this->Request()->getParams(), 'message' => $e->getMessage()));
     }
 }