Laravel login (Auth :: attempt) not working

Hi, I have a problem with Laravel. I can not enter. I tried everything I found on the Internet. Maybe someone has an idea where I made a mistake. Create a new user and send email. Log in. I do not know how the loop works in order to return to errors or messages. I am working with debug mode in laravel, but it had no errors.

<?php
    class AccountController extends BaseController {

        //Sign in function start

        public function getSignIn(){
            return View::make('account.signin');
        }

        public function postSignIn(){
            $validator = Validator::make(Input::all(),
                array(
                    'email'                 => 'required|email',
                    'username'          => 'required'
                )
            );

            if($validator->fails()){

                return Redirect::route('account-sign-in')
                    ->withErrors($validator)
                    ->withInput();  

            }else{

                if($auth = Auth::attempt(array(
                    'email' => Input::get('email'),
                    'password' => Input::get('password'),
                    'active' => 1

                ), true)){
                    return Redirect::to('/');
                }else{
                    return Redirect::route('account-sign-in')
                        ->with('global', 'Email/password wrong or account not activated');
                }

            }

            return Redirect::route('account-sign-in')
                ->with('global', 'There was a problem signing you in');
        }

        //Sign in function end




        //Create new account function start

        public function getCreate(){
            return View::make('account.create');
        }

        public function postCreate(){
            $validator = Validator::make(Input::all(),
                array(
                    'email'                 => 'required|max:50|email|unique:users',
                    'username'          => 'required|max:20|min:3|unique:users',
                    'password'          => 'required|min:6',
                    'password_again'    => 'required|same:password'
                )
            );


            if($validator->fails()){
                return Redirect::route('account-create')
                    ->withErrors($validator)
                    ->withInput();
            }else{

                $email      = Input::get('email');
                $username   = Input::get('username');
                $password   = Input::get('password');

                //Activation code

                $code       = str_random(60);

                $user = User::create(array(
                    'email'         => $email,
                    'username'  => $username,
                    'password'  => Hash::make($password),
                    'code'      => $code,
                    'active'    => 0

                ));

                if($user){

                    //Send link function start

                    Mail::send('emails.auth.active', array(
                        'link' => URL::route('account-active', $code),
                        'username' => $username),function($message) use ($user){$message->to($user->email, $user->username)->subject('Activation your account');});

                    //Send link function end

                    return Redirect::route('home')
                        ->with('global', 'Your account has been created! We have sent you an email with activation link');
                }
            }
        }
        public function getActivate($code){
            $user = User::where('code', '=', $code)->where('active', '=', 0);

            if($user->count()){
                $user = $user->first();

                //Update user to active state

                $user->active   = 1;
                $user->code         ='';

                if($user->save()){
                    return Redirect::route('home')
                        ->with('global', 'Activated! You can now sign in!');
                }
            }
                return Redirect::route('home')
                    ->with('global', 'We could not activate your account. Please try again later.');


        }

        //Create new account function end

    }

?>
+4
source share
1 answer

In the postSignIn()validator, you specify what usernameis required when you need to specify an email address and password to enter from what I see from your logic and error messages. Try instead:

$validator = Validator::make(Input::all(),
    array(
        'email'                 => 'required|email',
        'password'          => 'required'
    )
);

email password , username

+1

All Articles