Пример #1
0
 public function autocomplete()
 {
     if (is_numeric($this->getParam('q'))) {
         $user = $this->userStore->getById($this->getParam('q'));
         if ($user) {
             die(json_encode(['more' => false, 'results' => [['id' => $user->getId(), 'text' => $user->getName()]]]));
         }
     }
     $users = $this->userStore->search($this->getParam('q', ''));
     $rtn = ['results' => [], 'more' => false];
     foreach ($users as $user) {
         $rtn['results'][] = ['id' => $user->getId(), 'text' => $user->getName()];
     }
     die(json_encode($rtn));
 }
Пример #2
0
 public function resetPassword($userId, $key)
 {
     $user = $this->userStore->getById($userId);
     $userKey = md5(date('Y-m-d') . $user->getHash());
     if (empty($user) || $key != $userKey) {
         $this->view->error = 'Invalid password reset request.';
         return;
     }
     if ($this->request->getMethod() == 'POST') {
         $hash = password_hash($this->getParam('password'), PASSWORD_DEFAULT);
         $user->setHash($hash);
         $this->userStore->save($user);
         $_SESSION['user_id'] = $user->getId();
         $this->redirect('/');
     }
     $this->view->userId = $userId;
     $this->view->key = $key;
     return;
 }