SHARE
TWEET

Untitled

a guest Aug 18th, 2018 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Using applyFilter for updates
  2. Users::applyFilter('save', function($self, $params, $chain) {
  3.     if ($params['data']) {
  4.         $params['entity']->set($params['data']);
  5.         $params['data'] = array();
  6.     }
  7.     if (!$params['entity']->exists()) {
  8.         $params['entity']->password = Password::hash($params['entity']->password);
  9.     }
  10.     return $chain->next($self, $params, $chain);
  11. });
  12.    
  13. $user = Users::first($id);
  14. if (!empty($this->request->data) && !empty($user)) {
  15.     if ($user->save($this->request->data)) {
  16.         // woohoo
  17.     } else {
  18.         // bummer
  19.     }
  20. }
  21.    
  22. Users::applyFilter('save', function($self, $params, $chain) {
  23.     if ($params['data']) {
  24.         $params['entity']->set($params['data']);
  25.         $params['data'] = array();
  26.     }
  27.     $entity = $params['entity'];
  28.     if ($entity->password) {
  29.         $export = $entity->export();
  30.         if (empty($export['data']['password']) || $export['data']['password'] != $entity->password) {
  31.             $entity->password = Password::hash($entity->password);
  32.         }
  33.     }
  34.     return $chain->next($self, $params, $chain);
  35. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top