Ejemplo n.º 1
0
 /**
  * Finds a throttler by the given Model.
  *
  * @param  \Cartalyst\Sentry\Users\UserInterface $user
  * @param  string  $ipAddress
  * @return \Cartalyst\Sentry\Throttling\ThrottleInterface
  */
 public function findByUser(UserInterface $user, $ipAddress = null)
 {
     $model = $this->createModel();
     $query = $model->where('user_id', '=', $userId = $user->getId());
     if ($ipAddress) {
         $query->where(function ($query) use($ipAddress) {
             $query->where('ip_address', '=', $ipAddress);
             $query->orWhere('ip_address', '=', NULL);
         });
     }
     if (!($throttle = $query->first())) {
         $throttle = $this->createModel();
         $throttle->user_id = $userId;
         if ($ipAddress) {
             $throttle->ip_address = $ipAddress;
         }
         $throttle->save();
     }
     return $throttle;
 }
Ejemplo n.º 2
0
 /**
  * Set the user associated with the social link.
  *
  * @param  Cartalyst\Sentry\Users\UserInterface  $user
  * @return void
  */
 public function setUser(UserInterface $user)
 {
     $this->user_id = $user->getId();
     $this->save();
 }
Ejemplo n.º 3
0
	/**
	 * Logs in the given user and sets properties
	 * in the session.
	 *
	 * @param  \Cartalyst\Sentry\Users\UserInterface  $user
	 * @param  bool  $remember
	 * @return void
	 * @throws \Cartalyst\Sentry\Users\UserNotActivatedException
	 */
	public function login(UserInterface $user, $remember = false)
	{
		if ( ! $user->isActivated())
		{
			$login = $user->getLogin();
			throw new UserNotActivatedException("Cannot login user [$login] as they are not activated.");
		}

		$this->user = $user;

		// Create an array of data to persist to the session and / or cookie
		$toPersist = array($user->getId(), $user->getPersistCode());

		// Set sessions
		$this->session->put($toPersist);

		if ($remember)
		{
			$this->cookie->forever($toPersist);
		}

		// The user model can attach any handlers
		// to the "recordLogin" event.
		$user->recordLogin();
	}
Ejemplo n.º 4
0
 /**
  * Logs in the given user and sets properties
  * in the session.
  *
  * @param  \Cartalyst\Sentry\Users\UserInterface  $user
  * @param  bool  $remember
  * @return void
  * @throws \Cartalyst\Sentry\Users\UserNotActivatedException
  */
 public function login(UserInterface $user, $remember = false)
 {
     if ($user->hasActivationRelaxed()) {
         $user->setActivationReminder(true);
         $c_date = new \DateTime(preg_replace('/\\s+(\\d{2})\\:(\\d{2})\\:(\\d{2})$/', '', $user->created_at));
         $t_date = new \DateTime();
         $difference = $c_date->diff($t_date);
         /* @all, this code works, but we'll keep it on the low for now....
         			
         			 if($difference->days >= 3){
         			    // @all, we'll stop relaxing the activation (i.e start enforcing activation) because the users time limit for activation is up!
         				$user->relax_activation = false;
         				$user->save();
         				
         			 }
         			 
         			*/
     } else {
         if (!$user->isActivated()) {
             $login = $user->getLogin();
             throw new UserNotActivatedException("Cannot login user [{$login}] as they are not activated.");
         } else {
             $user->setActivationReminder(false);
         }
     }
     $this->user = $user;
     // Create an array of data to persist to the session and / or cookie
     $toPersist = array($user->getId(), $user->getPersistCode());
     // Set sessions
     $this->session->put($toPersist);
     // TEMPORARY - Set Synergixe cookie -- Later we'll drive cross-domain access on native PHP sessions (instead of cookies) by creating a 'session_save_handler' for session based on the database!!
     setcookie('synergixe_sso', serialize($toPersist), time() + 24 * 3600, "/", ".synergixe.ng", FALSE, TRUE);
     if ($remember) {
         $this->cookie->forever($toPersist);
     }
     // The user model can attach any handlers
     // to the "recordLogin" event.
     $user->recordLogin();
 }
Ejemplo n.º 5
0
 /**
  * Logs the given user into Sentry.
  *
  * @param  \Cartalyst\Sentry\Users\UserInterface  $user
  * @param  bool  $remember
  * @return void
  */
 protected function login(UserInterface $user, $remember = false)
 {
     $throttleProvider = $this->sentry->getThrottleProvider();
     // Now, we will check the throttling to ensure we are
     // not logging in a user which shouldn't be allowed.
     if ($throttleProvider->isEnabled()) {
         $throttle = $throttleProvider->findByUserId($user->getId(), $this->sentry->getIpAddress());
         $throttle->check();
     }
     $this->sentry->login($user, $remember);
 }
Ejemplo n.º 6
0
 /**
  * Unsuspend the user and give him a new password
  *
  * @param User $user
  * @param string $reset_code The password reset code
  * @throws PasswordResetFailedException
  * @return string Returns the new password on success
  */
 protected function unsuspendUserAndResetPassword($user, $reset_code)
 {
     $throttle = $this->sentry->findThrottlerByUserId($user->getId());
     $throttle->unsuspend();
     $new_password = $this->mockably->str_random(16);
     if ($user->attemptResetPassword($reset_code, $new_password)) {
         return $new_password;
     } else {
         throw new PasswordResetFailedException();
     }
 }