public function index()
    {
        //  If you're logged in you shouldn't be accessing this method
        if (isLoggedIn()) {
            redirect($this->data['return_to']);
        }

        // --------------------------------------------------------------------------

        //  If there's POST data attempt to log user in
        $oInput = Factory::service('Input');
        if ($oInput->post()) {

            //  Validate input
            $oFormValidation = Factory::service('FormValidation');

            //  The rules vary depending on what login methods are enabled.
            switch (APP_NATIVE_LOGIN_USING) {

                case 'EMAIL':
                    $oFormValidation->set_rules('identifier', 'Email', 'required|trim|valid_email');
                    break;

                case 'USERNAME':
                    $oFormValidation->set_rules('identifier', 'Username', 'required|trim');
                    break;

                default:
                    $oFormValidation->set_rules('identifier', 'Username or Email', 'trim');
                    break;
            }

            //  Password is always required, obviously.
            $oFormValidation->set_rules('password', 'Password', 'required');
            $oFormValidation->set_message('required', lang('fv_required'));
            $oFormValidation->set_message('valid_email', lang('fv_valid_email'));

            if ($oFormValidation->run()) {

                //  Attempt the log in
                $sIdentifier = $oInput->post('identifier');
                $sPassword   = $oInput->post('password');
                $bRememberMe = (bool) $oInput->post('remember');
                $oAuthModel  = Factory::model('Auth', 'nails/module-auth');

                $oUser = $oAuthModel->login($sIdentifier, $sPassword, $bRememberMe);

                if ($oUser) {
                    $this->_login($oUser, $bRememberMe);
                } else {
                    $this->data['error'] = $oAuthModel->lastError();
                }

            } else {
                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        $oSocial                               = Factory::service('SocialSignOn', 'nails/module-auth');
        $this->data['social_signon_enabled']   = $oSocial->isEnabled();
        $this->data['social_signon_providers'] = $oSocial->getProviders('ENABLED');

        // --------------------------------------------------------------------------

        $this->loadStyles(NAILS_APP_PATH . 'application/modules/auth/views/login/form.php');

        Factory::service('View')
            ->load([
                'structure/header/blank',
                'auth/login/form',
                'structure/footer/blank',
            ]);
    }