示例#1
0
 /**
  * Perform activity after a User has been saved
  *
  * @param \Cake\Event\Event $event The event instance
  * @param \Cake\ORM\Entity $entity The user entity saved
  * @param ArrayObject $options Misc options if any
  * @return void
  */
 public function afterSave(Event $event, User $entity, ArrayObject $options)
 {
     if ($entity->isNew()) {
         Log::write('info', 'User created: ' . $entity->id);
         // For a new user write registration verification rec to job_funcs
         $jobFuncsTable = TableRegistry::get('JobFuncs');
         $jobFuncsTable->createVerifyEmailJob($entity);
     } else {
         Log::write('info', 'User saved: ' . $entity->id);
     }
     //        $this->dispatchEvent('UsersTable.afterSave', compact('entity','options'));
 }
示例#2
0
 public function startup()
 {
     parent::startup();
     if (!$this->user->isLoggedIn()) {
         $this->redirect(':Sign:in');
     }
     $this->identity = $this->user->identity;
     $this->userEntity = $this->userService->get($this->identity->id);
     $this->navigation = new NavigationCollection($this->translator);
     $this->template->navigation = $this->navigation;
     $this->template->systemName = systemName;
     $this->template->author = $this->userEntity->getEmail();
 }
 function registerUser(UserEntity $user)
 {
     if ($this->usernameExists($user['username'])) {
         throw new Exception("The username is already taken");
     } elseif ($this->emailExists($user['email'])) {
         throw new Exception("The email is already taken");
     }
     $user['created_at'] = new MongoDate();
     $user['updated_at'] = new MongoDate();
     $userToCommit = $user->toArray();
     unset($userToCommit['_id']);
     $status = $this->_collection->insert($userToCommit, array('safe' => true));
     return new UserEntity($userToCommit);
 }
 /**
  * Provides ListFilter configuration
  *
  * @return array
  */
 public function getListFilters()
 {
     $filters = [];
     if ($this->request->action == 'index') {
         $filters['fields'] = ['Users.role' => ['searchType' => 'select', 'options' => User::getRoles(), 'inputOptions' => ['label' => __('user.role')]], 'Users.status' => ['searchType' => 'select', 'options' => User::getStatuses(), 'inputOptions' => ['label' => __('user.status')]], 'Users.fulltext' => ['searchType' => 'fulltext', 'searchFields' => ['Users.firstname', 'Users.lastname', 'Users.email']]];
     }
     return $filters;
 }
示例#5
0
 public function passwordShouldMatch($val, $ctx)
 {
     if (!is_numeric($ctx['data']['id'])) {
         return true;
     }
     $user = $this->get($ctx['data']['id']);
     return User::passwordMatch($val, $user->password);
 }
 /**
  * Renders a role label with the appropriate color
  *
  * @param string $role One of the Role constants
  * @return string
  */
 public function roleLabel($role)
 {
     $classes = ['label'];
     $caption = User::getTypeDescription($role);
     switch ($role) {
         case User::ROLE_ADMIN:
             $classes[] = 'label label-primary';
             break;
         case User::ROLE_USER:
             $classes[] = 'label label-warning';
             break;
         default:
             $classes[] = 'label-default';
     }
     return sprintf('<span class="%s">%s</span>', implode(' ', $classes), h($caption));
 }
示例#7
0
 /**
  * Add method
  *
  * @return \Cake\Network\Response|void
  */
 public function add()
 {
     $user = $this->Users->newEntity();
     if ($this->request->is('post')) {
         $user = $this->Users->patchEntity($user, $this->request->data);
         $user->set('password', User::hashPassword($user->get('password')));
         $user->set('created_at', time());
         $user->set('updated_at', time());
         if ($this->Users->save($user)) {
             $this->Flash->success(__('The user has been saved.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('The user could not be saved. Please, try again.'));
         }
     }
     $this->set(compact('user'));
     $this->set('_serialize', ['user']);
 }
示例#8
0
 /**
  * Send email for recovery to customer
  */
 private function sendRecoveryEmail($user, $email)
 {
     $hash = User::getHash($user['username'] . $user['first_name'] . $user['gmail'] . $user['skype']);
     $user = $this->Users->patchEntity($user, ['hash' => $hash]);
     $recovery_link = 'http://' . $this->request->host() . $this->recoveryLink . '?' . $this->haskVar . '=' . $hash;
     if ($this->Users->save($user)) {
         $Mail = new Email('default');
         $emailRes = $Mail->from(['*****@*****.**' => 'Onix HRM Systems'])->to($email)->subject(__('Восстановление доступа к сайту {0}', 'Onix HRM Systems'))->send(__('Для того, что-бы восстановить пароль, перейдите по ссылке ') . ' ссылка: ' . $recovery_link);
         $this->Flash->success(__('Листа відправленно'));
     } else {
         $this->Flash->error(__('Не вдалося зберегти налаштування'));
     }
 }
 /**
  * Validates the new_password and password_confirm fields for a user and
  * saves them if valid.
  *
  * @param User $user User entity
  * @param array $postData Array containing new_password and password_confirm keys
  * @return User
  */
 public function changePassword(User $user, array $postData)
 {
     $user->accessible('*', false);
     $user->accessible(['password'], true);
     $this->patchEntity($user, $postData, ['validate' => 'changePassword']);
     if (empty($user->errors())) {
         $user->password = $postData['password'];
         return $this->save($user);
     }
     return $user;
 }
示例#10
0
 /**
  * @param User $user
  * @return $this
  */
 public function setUser(User $user)
 {
     $this->record->user_id = $user->getID();
     return $this;
 }
示例#11
0
文件: User.php 项目: gpsoft/lanmap
 protected function _setPassword($value)
 {
     return User::hashedPassword($value);
 }