Skip to content

Commit

Permalink
little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed May 2, 2015
1 parent 262c850 commit 88d0e68
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions src/SmallUser/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,29 @@ class User extends InvokableBase
* @param array $data
* @return bool
*/
public function login( array $data )
public function login( array $data )
{
$class = $this->getUserEntityClassName();
$class = $this->getUserEntityClassName();

$form = $this->getLoginForm();
$form->setHydrator( new HydratorUser() );
$form->bind( new $class );
$form->setData( $data);
$form = $this->getLoginForm();
$form->setHydrator( new HydratorUser() );
$form->bind( new $class );
$form->setData( $data );

$this->getFlashMessenger()->setNamespace(self::ErrorNameSpace)->addMessage($this->getFailedLoginMessage());
$this->getFlashMessenger()->setNamespace( self::ErrorNameSpace )->addMessage( $this->getFailedLoginMessage() );

if(!$form->isValid()){
return false;
}
if (!$form->isValid()) {
return false;
}

if(!$this->isIpAllowed()){
return false;
}
if (!$this->isIpAllowed()) {
return false;
}

$user = $form->getData();
$authService = $this->getAuthService();
$result = $this->getAuthResult($authService, $user);
if($result->isValid()){
$user = $result->getIdentity();
if($this->isValidLogin($user)){
$this->doLogin($user);
return true;
}else{
// Login correct but not active or blocked or smth else
$authService->clearIdentity();
$authService->getStorage()->clear();
}
}else{
$this->handleInvalidLogin($user);
}
$user = $form->getData();

return false;
}
return $this->handleAuth4UserLogin( $user );
}

/**
* TODO
Expand Down Expand Up @@ -201,4 +186,32 @@ protected function getUserEntityUserName()

return $this->userEntityUserName;
}

/**
* @param UserInterface $user
* @return bool
*/
protected function handleAuth4UserLogin( UserInterface $user )
{
$authService = $this->getAuthService();
$authResult = $this->getAuthResult( $authService, $user );
$result = false;

if ($authResult->isValid()) {
$user = $authResult->getIdentity();
if ($this->isValidLogin( $user )) {
$this->doLogin( $user );

$result = true;
} else {
// Login correct but not active or blocked or smth else
$authService->clearIdentity();
$authService->getStorage()->clear();
}
} else {
$this->handleInvalidLogin( $user );
}

return $result;
}
}

0 comments on commit 88d0e68

Please sign in to comment.