Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function findByCredentials(array $credentials)
 {
     if (isset($credentials['password'])) {
         unset($credentials['password']);
     }
     return User::where($credentials)->first();
 }
Exemplo n.º 2
0
 /**
  * @Request({"user", "key"})
  */
 public function confirmAction($username = "", $activation = "")
 {
     if (empty($username) || empty($activation) || !($user = User::where(compact('username', 'activation'))->first())) {
         return $this->messageView(__('Invalid key.'), $success = false);
     }
     if ($user->isBlocked()) {
         return $this->messageView(__('Your account has not been activated or is blocked.'), $success = false);
     }
     $error = '';
     if ('POST' === App::request()->getMethod()) {
         try {
             if (!App::csrf()->validate()) {
                 throw new Exception(__('Invalid token. Please try again.'));
             }
             $password = App::request()->request->get('password');
             if (empty($password)) {
                 throw new Exception(__('Enter password.'));
             }
             if ($password != trim($password)) {
                 throw new Exception(__('Invalid password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
             $user->activation = null;
             $user->save();
             App::message()->success(__('Your password has been reset.'));
             return App::redirect('@user/login');
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     return ['$view' => ['title' => __('Reset Confirm'), 'name' => 'system/user/reset-confirm.php'], 'username' => $username, 'activation' => $activation, 'error' => $error];
 }
Exemplo n.º 3
0
 /**
  * @Request({"user", "key"})
  */
 public function activateAction($username, $activation)
 {
     $message = '';
     if (empty($username) || empty($activation) || !($user = User::where(['username' => $username, 'activation' => $activation, 'status' => User::STATUS_BLOCKED, 'login IS NULL'])->first())) {
         return AuthController::messageView(['message' => __('Invalid key.'), 'success' => false]);
     }
     if ($admin = $this->module->config('registration') == 'approval' and !$user->get('verified')) {
         $user->activation = App::get('auth.random')->generateString(32);
         $this->sendApproveMail($user);
         $message = __('Your email has been verified. Once an administrator approves your account, you will be notified by email.');
     } else {
         $user->set('verified', true);
         $user->status = User::STATUS_ACTIVE;
         $user->activation = '';
         $this->sendWelcomeEmail($user);
         if ($admin) {
             $message = __('The user\'s account has been activated and the user has been notified about it.');
         } else {
             $message = __('Your account has been activated.');
         }
     }
     $user->save();
     App::message()->success($message);
     return App::redirect('@user/login');
 }
 /**
  * {@inheritdoc}
  */
 public static function queryProfileValues($condition, $exact = false)
 {
     /** @var QueryBuilder $query */
     $query = User::where(['status' => User::STATUS_ACTIVE]);
     $query->from('@system_user AS u')->select('u.*');
     $params = [];
     foreach ($condition as $slug => $search) {
         $slg = str_replace('-', '_', $slug);
         $query->leftJoin(sprintf('@userprofile_field AS pf_%s', $slg), sprintf('pf_%1$s.slug = :slug_%1$s', $slg))->leftJoin(sprintf('@userprofile_value AS pv_%s', $slg), sprintf('pv_%1$s.field_id = pf_%1$s.id AND pv_%1$s.user_id = u.id', $slg));
         if ($exact) {
             $query->where(sprintf('pv_%1$s.value = :search_%1$s', $slg));
         } else {
             $query->where(sprintf('pv_%1$s.value LIKE :search_%1$s', $slg));
             $search = "%{$search}%";
         }
         $params["slug_{$slg}"] = $slug;
         $params["search_{$slg}"] = $search;
     }
     $query->params($params);
     return $query;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function match(array $parameters = [])
 {
     if (isset($parameters['id'])) {
         return $parameters;
     }
     if (!isset($parameters['slug'])) {
         App::abort(404, 'Userprofile not found.');
     }
     $slug_key = App::module('bixie/userprofile')->config('slug_key', 'username');
     $slug = $parameters['slug'];
     $id = false;
     foreach ($this->cacheEntries as $entry) {
         if ($entry[$slug_key] === $slug) {
             $id = $entry['id'];
         }
     }
     if (!$id) {
         switch ($slug_key) {
             case 'id':
                 $user = User::find($slug);
                 break;
             case 'name':
                 $user = User::where(['name' => $slug])->first();
                 break;
             case 'username':
                 $user = User::findByUsername($slug);
                 break;
             default:
                 $user = false;
                 break;
         }
         if (!$user) {
             App::abort(404, 'Userprofile not found.');
         }
         $this->addCache($user);
         $id = $user->id;
     }
     $parameters['id'] = $id;
     return $parameters;
 }
Exemplo n.º 6
0
 /**
  * @Request({"user", "key"})
  */
 public function activateAction($username, $activation)
 {
     if (empty($username) || empty($activation) || !($user = User::where(['username' => $username, 'activation' => $activation, 'login IS NULL'])->first())) {
         App::abort(400, __('Invalid key.'));
     }
     $verifying = false;
     if ($this->module->config('require_verification') && !$user->get('verified')) {
         $user->set('verified', true);
         $verifying = true;
     }
     if ($this->module->config('registration') === 'approval' && $user->status === User::STATUS_BLOCKED && $verifying) {
         $user->activation = App::get('auth.random')->generateString(32);
         $this->sendApproveMail($user);
         $message = __('Your email has been verified. Once an administrator approves your account, you will be notified by email.');
     } else {
         $user->status = User::STATUS_ACTIVE;
         $user->activation = '';
         $this->sendWelcomeEmail($user);
         $message = $verifying ? __('Your account has been activated.') : __('The user\'s account has been activated and the user has been notified about it.');
     }
     $user->save();
     App::message()->success($message);
     return App::redirect('@user/login');
 }