mercredi 25 novembre 2015

Laravel5 and Angular Login,500 internal server error

Iam making login using Angular js and Laravel5, but iam getting error,500 internal server error. How can i solve this.

controller:

public function checkAuth(Request $request)
    {
        // setting the credentials array
        $credentials = [
            'email' => $request->input('email'),
            'password' => $request->input('password'),
        ];

        // if the credentials are wrong
        if (!Auth::attempt($credentials)) {
            return response('Username password does not match', 403);
        }

        return response(Auth::user(), 201);
    }

route

Route::post('auth','UserController@checkAuth');

userController.js

        myApp.constant("CSRF_TOKEN", '{!! csrf_token() !!}');
        myApp.controller('userController',['$scope','$http',function($scope,$http, CSRF_TOKEN){
        angular.extend($scope,{
            doLogin:function(loginForm){
                $http({

                    headers:{
                        'Content-Type':'application/x-www-form-urlencoded'
                    },
                    url:baseUrl+'auth',

                    method:"POST",
                    data:{
                        email:$scope.login.username,
                        password:$scope.login.password,
                        '_token':CSRF_TOKEN

                    }

                }).success(function(response){
                    console.log(response);

                }).error(function(data,status,headers){
                    console.log(data,status,headers);
                alert('Error');

            });



        }
    });
}]);

form

<head><meta name="_token" content="{!! csrf_token() !!}"/></head>

<div class="row">
    <div class="col-sm-5 col-sm-push-3 well">
        <h1>Login</h1>
        <form name="loginForm" ng-submit="doLogin(loginForm)">

            <div class="form-group">
                <input type="email" name="email" ng-model="login.username" 
                required placeholder="Enter your email address" class="form-control">
            </div>



            <div class="form-group">
                <input type="password" name="password" ng-model="login.password" 
                required placeholder="Enter your password" class="form-control">
            </div>
        <input type="hidden" name="_token" value="{{ csrf_token() }}" id="token">

            <input type="submit" name="save" value="Login" class="btn btn-success">
        </form>
    </div>
</div>

Anyone please help me to solve this problem. When i click the submit button i got 500 internal server error



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire