/** * Handle the command. * * @param Repository $config * @param Encrypter $encrypter * @return string */ public function handle(Repository $config, Encrypter $encrypter) { $email = $encrypter->encrypt($this->user->getEmail()); $code = $encrypter->encrypt($this->user->getResetCode()); $query = "?email={$email}&code={$code}&redirect={$this->redirect}"; return $config->get('anomaly.module.users::paths.reset') . $query; }
/** * Handle the command. * * @param Mailer $mailer * @param SettingRepositoryInterface $settings * @return mixed */ public function handle(Mailer $mailer, SettingRepositoryInterface $settings) { $path = $this->dispatch(new GetResetPasswordPath($this->user, $this->redirect)); return $mailer->send('anomaly.module.users::emails/reset', ['user' => $this->user, 'path' => $path], function (Message $message) use($settings) { $message->subject('Reset your password')->to($this->user->getEmail(), $this->user->getDisplayName())->from($settings->value('streams::server_email', 'noreply@localhost')); }); }
/** * Handle the command. * * @param Mailer $mailer * @param Repository $config * @return bool */ public function handle(Mailer $mailer, Repository $config) { $path = $this->dispatch(new GetResetPasswordPath($this->user, $this->redirect)); $mailer->send('anomaly.module.users::message/reset', compact('user', 'path'), function (Message $message) use($config) { $message->subject('Reset your password')->to($this->user->getEmail(), $this->user->getDisplayName())->from($config->get('mail.from.address', 'noreply@localhost')); }); return empty($mailer->failures()); }
/** * Handle the command. * * @param UserRepositoryInterface $users * @return bool */ public function handle(UserRepositoryInterface $users) { if (!($user = $users->findByActivationCode($this->code))) { return false; } if ($this->user->getId() !== $user->getId()) { return false; } $this->user->activated = true; $this->user->activation_code = null; $users->save($this->user); return true; }
/** * Handle the command. * * @param UserRepositoryInterface $users * @return bool */ public function handle(UserRepositoryInterface $users) { $user = $users->findByResetCode($this->code); if (!$user) { return false; } if ($user->getId() !== $this->user->getId()) { return false; } $this->user->setAttribute('reset_code', null); $this->user->setAttribute('password', $this->password); $users->save($this->user); return true; }
/** * @param UserAuthenticator $authenticator * @param MessageBag $message * @param Redirector $redirect * @return bool|\Illuminate\Http\RedirectResponse */ public function handle(UserAuthenticator $authenticator, MessageBag $message, Redirector $redirect) { if (!$this->user->isActivated()) { $message->error('Your account has not been activated.'); $authenticator->logout(); // Just in case. return $redirect->back(); } if (!$this->user->isEnabled()) { $message->error('Your account has been disabled.'); $authenticator->logout(); // Just in case. return $redirect->back(); } return true; }
/** * Return the status key. * * @return null|string */ public function status() { if (!$this->object->isEnabled()) { return 'disabled'; } if ($this->object->isEnabled() && !$this->object->isActivated()) { return 'inactive'; } if ($this->object->isEnabled() && $this->object->isActivated()) { return 'active'; } return null; }
/** * Handle the command. * * @param UserRepositoryInterface $users * @return bool */ public function handle(UserRepositoryInterface $users) { $users->save($this->user->setActivationCode(str_random(40))); return true; }
/** * Limit to preferences belonging to the provided user. * * @param Builder $query * @param UserInterface $user */ public function scopeBelongingToUser(Builder $query, UserInterface $user) { $query->where('user_id', $user->getId()); }
/** * Handle the command. * * @param Encrypter $encrypter * @return string */ public function handle(Encrypter $encrypter) { $email = $encrypter->encrypt($this->user->getEmail()); $code = $encrypter->encrypt($this->user->getResetCode()); return "/users/password/reset?email={$email}&code={$code}&redirect={$this->redirect}"; }
/** * Handle the command. * * @param UserRepositoryInterface $users * @return bool */ public function handle(UserRepositoryInterface $users) { $users->save($this->user->setAttribute('activation_code', str_random(40))); return true; }
/** * Return a user's permission. * * @param $permission * @param UserInterface $user * @return bool */ protected function checkPermission($permission, UserInterface $user) { /** * No permission, let it proceed. */ if (!$permission) { return true; } /** * If the permission does not actually exist * then we cant really do anything with it. */ if (str_is('*::*.*', $permission) && !ends_with($permission, '*')) { $parts = explode('.', str_replace('::', '.', $permission)); $end = array_pop($parts); $group = array_pop($parts); $parts = explode('::', $permission); // If it does not exist, we are authorized. if (!in_array($end, (array) $this->config->get($parts[0] . '::permissions.' . $group))) { return true; } } elseif (ends_with($permission, '*')) { $parts = explode('::', $permission); $addon = array_shift($parts); /** * Check vendor.module.slug::group.* * then check vendor.module.slug::* */ if (str_is('*.*.*::*.*.*', $permission)) { $end = trim(substr($permission, strpos($permission, '::') + 2), '.*'); if (!($permissions = $this->config->get($addon . '::permissions.' . $end))) { return true; } else { return $user->hasAnyPermission($permissions); } } elseif (str_is('*.*.*::*.*', $permission)) { $end = trim(substr($permission, strpos($permission, '::') + 2), '.*'); if (!($permissions = $this->config->get($addon . '::permissions.' . $end))) { return true; } else { $check = []; foreach ($permissions as &$permission) { $check[] = $addon . '::' . $end . '.' . $permission; } return $user->hasAnyPermission($check); } } else { if (!($permissions = $this->config->get($addon . '::permissions'))) { return true; } else { $check = []; foreach ($permissions as $group => &$permission) { foreach ($permission as $access) { $check[] = $addon . '::' . $group . '.' . $access; } } return $user->hasAnyPermission($check); } } } else { $parts = explode('::', $permission); $end = array_pop($parts); if (!in_array($end, (array) $this->config->get($parts[0] . '::permissions'))) { return true; } } // Check if the user actually has permission. if (!$user || !$user->hasPermission($permission)) { return false; } return true; }
/** * Handle the command. * * @param UserRepositoryInterface $users * @return bool */ public function handle(UserRepositoryInterface $users) { return $users->save($this->user->setAttribute('reset_code', str_random(40))); }
/** * Handle the command. * * @return string|null */ public function handle(Encrypter $encrypter) { $email = $encrypter->encrypt($this->user->getEmail()); $code = $encrypter->encrypt($this->user->getActivationCode()); return "/users/activate?email={$email}&code={$code}&redirect={$this->redirect}"; }
/** * Return the users name. * * @return string */ public function name() { return implode(' ', array_filter([$this->object->getFirstName(), $this->object->getLastName()])); }