protected function _actionAdd(AnCommandContext $context)
    {
        $data = $context->data;

        dispatch_plugin('user.onBeforeLoginPerson', array('credentials' => $data));

        if ($data->return) {
            AnRequest::set('session.return', $data->return);
            $context->url = base64UrlDecode($data->return);
        } else {
            AnRequest::set('session.return', '');
        }

        $credentials = array(
            'username' => $data->username,
            'password' => $data->password
        );

        $response = $this->getService('com:people.authentication.response');

        dispatch_plugin('authentication.onAuthenticate', array(
                            'credentials' => $credentials,
                            'response' => $response
                        ));

        if ($response->status === ComPeopleAuthentication::STATUS_SUCCESS) {
            $person = $this->getService('com:people.helper.person')->login($credentials);
            $this->_state->setItem($person);
            $this->getResponse()->status = AnHttpResponse::CREATED;

            dispatch_plugin('user.onAfterLoginPerson', array('person' => $this->person));

            if(! $context->url) {
                $context->url = route(array(
                    'option' => 'com_people',
                    'view' => 'people',
                    'uniqueAlias' => $person->username
                ));
            }

            $this->getResponse()->setRedirect($context->url);
            AnRequest::set('session.return', '');
        } else {
            $this->setMessage(translate('COM-PEOPLE-AUTHENTICATION-FAILED'), 'error');
            throw new LibBaseControllerExceptionUnauthorized('Authentication Failed. Check username/password');
            $this->getResponse()->status = AnHttpResponse::FORBIDDEN;
            $this->getResponse()->setRedirect(route('option=com_people&view=session'));
        }
    }
protected function _actionAdd(AnCommandContext $context)
    {
        $data = $context->data;

        dispatch_plugin('user.onBeforeLoginPerson', array('credentials' => $data));

        if ($data->return) {
            AnRequest::set('session.return', $data->return);
            $context->url = base64UrlDecode($data->return);
        } else {
            AnRequest::set('session.return', '');
        }

        $credentials = array(
            'username' => $data->username,
            'password' => $data->password
        );

        $response = $this->getService('com:people.authentication.response');

        dispatch_plugin('authentication.onAuthenticate', array(
                            'credentials' => $credentials,
                            'response' => $response
                        ));

        if ($response->status === ComPeopleAuthentication::STATUS_SUCCESS) {
            $person = $this->getService('com:people.helper.person')->login($credentials);
            $this->_state->setItem($person);
            $this->getResponse()->status = AnHttpResponse::CREATED;

            dispatch_plugin('user.onAfterLoginPerson', array('person' => $this->person));

            if(! $context->url) {
                $context->url = route(array(
                    'option' => 'com_people',
                    'view' => 'people',
                    'uniqueAlias' => $person->username
                ));
            }

            $this->getResponse()->setRedirect($context->url);
            AnRequest::set('session.return', '');
        } else {
            $this->setMessage(translate('COM-PEOPLE-AUTHENTICATION-FAILED'), 'error');
            throw new LibBaseControllerExceptionUnauthorized('Authentication Failed. Check username/password');
            $this->getResponse()->status = AnHttpResponse::FORBIDDEN;
            $this->getResponse()->setRedirect(route('option=com_people&view=session'));
        }
    }
protected function _actionAdd ( AnCommandContext $ context ) { $ data = $ context -> data ; dispatch_plugin ( 'user.onBeforeLoginPerson' , array ( 'credentials' => $ data ) ) ; if ( $ data -> return ) { AnRequest :: set ( 'session.return' , $ data -> return ) ; $ context -> url = base64UrlDecode ( $ data -> return ) ; } else { AnRequest :: set ( 'session.return' , '' ) ; } $ credentials = array ( 'username' => $ data -> username , 'password' => $ data -> password ) ; $ response = $ this -> getService ( 'com:people.authentication.response' ) ; dispatch_plugin ( 'authentication.onAuthenticate' , array ( 'credentials' => $ credentials , 'response' => $ response ) ) ; if ( $ response -> status === ComPeopleAuthentication :: STATUS_SUCCESS ) { $ person = $ this -> getService ( 'com:people.helper.person' ) -> login ( $ credentials ) ; $ this -> _state -> setItem ( $ person ) ; $ this -> getResponse ( ) -> status = AnHttpResponse :: CREATED ; dispatch_plugin ( 'user.onAfterLoginPerson' , array ( 'person' => $ this -> person ) ) ; if ( ! $ context -> url ) { $ context -> url = route ( array ( 'option' => 'com_people' , 'view' => 'people' , 'uniqueAlias' => $ person -> username ) ) ; } $ this -> getResponse ( ) -> setRedirect ( $ context -> url ) ; AnRequest :: set ( 'session.return' , '' ) ; } else { $ this -> setMessage ( translate ( 'COM-PEOPLE-AUTHENTICATION-FAILED' ) , 'error' ) ; throw new LibBaseControllerExceptionUnauthorized ( 'Authentication Failed. Check username/password' ) ; $ this -> getResponse ( ) -> status = AnHttpResponse :: FORBIDDEN ; $ this -> getResponse ( ) -> setRedirect ( route ( 'option=com_people&view=session' ) ) ; } }
Authenticate a person and create a new session If a username password is passed then the user is first logged in.

@param AnCommandContext $context Command chain context

@throws LibBaseControllerExceptionUnauthorized If authentication failed
@throws LibBaseControllerExceptionForbidden    If person is authenticated but forbidden
@throws RuntimeException                       for unkown error
Authenticate a person and create a new session If a username password is passed then the user is first logged in .