hipsterjazzbo / LaraParse

LaraParse provides a nice integration for using Parse (parse.com) with Laravel 5+
MIT License
27 stars 19 forks source link

Cannot get LaraParse started (working) for user authentication #36

Closed Marc-Tanne closed 9 years ago

Marc-Tanne commented 9 years ago

I am new to parse and am trying to get this working in my laravel site. I am running 5.1.7 and followed the install steps and tried to use the out-of-the-box methods in the registersUsers.php middleware to get the data sent to parse. after seeing that not work, I added this to the postRegister function:

$user = new ParseUser(); $user->set("username", $request['user_name']); $user->set("password", $request['password']); $user->set("arcardz_id", $request['arcardz_id']);

    try {
      $user->signUp();
      // Hooray! Let them use the app now.
    } catch (ParseException $ex) {
      // Show the error message somewhere and let the user try again.
      return("Error: " . $ex->getCode() . " " . $ex->getMessage());
    }

this did not work either. There is no error thrown and a return of $request['user_name'] and others returns the correct data. What am I doing wrong here?

nicklee1990 commented 9 years ago

without seeing all the code, here's a few things to check:

  1. have you set your auth provider to 'parse' in the auth config file?
  2. have you updated your model in the auth config file? if you aren't extending the User class, then it should be LaraParse\Subclasses\User
  3. in your postRegister function you should be creating a new LaraParse\Subclasses\User not ParseUser. Remember you're creating a new User in your application, and the library will take care of interacting with the storage system (in this case Parse)

What exception are you seeing?

Marc-Tanne commented 9 years ago

Ok, so looking at what you said, it looks like I am doing everything incorrectly. Can you please outline how to get this setup the correct way? there was no mention of interacting with models in the setup instructions. I went to the RegistersUsers.php trait after tracing the calls in laravel back to where it attempts to login the user. Please see my attached files containing my user model, RegistersUsers.php trait file, my AuthController, my routes.php file, and my view, register.blade.php. I have never used parse before and am trying to learn as I go. I am familiar with the front-end of laravel and starting to become dangerous with the back-end section of laravel. Any help on getting started would be greatly appreciated!

Sincerely, Marc Tanne

On Wed, Sep 23, 2015 at 2:14 AM, nicklee1990 notifications@github.com wrote:

without seeing all the code, here's a few things to check:

  1. have you set your auth provider to 'parse' in the auth config file?
  2. have you updated your model in the auth config file? if you aren't extending the User class, then it should be LaraParse\Subclasses\User
  3. in your postRegister function you should be creating a new LaraParse\Subclasses\User not ParseUser. Remember you're creating a new User in your application, and the library will take care of interacting with the storage system (in this case Parse)

What exception are you seeing?

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142537069 .

Marc-Tanne commented 9 years ago

to answer your questions:

  1. yes
  2. no it is currently showing app\user::class
  3. I do not understand what you mean. I am going to research subclasses now.

On Wed, Sep 23, 2015 at 10:20 AM, Marc Tanne tannem9@gmail.com wrote:

Ok, so looking at what you said, it looks like I am doing everything incorrectly. Can you please outline how to get this setup the correct way? there was no mention of interacting with models in the setup instructions. I went to the RegistersUsers.php trait after tracing the calls in laravel back to where it attempts to login the user. Please see my attached files containing my user model, RegistersUsers.php trait file, my AuthController, my routes.php file, and my view, register.blade.php. I have never used parse before and am trying to learn as I go. I am familiar with the front-end of laravel and starting to become dangerous with the back-end section of laravel. Any help on getting started would be greatly appreciated!

Sincerely, Marc Tanne

On Wed, Sep 23, 2015 at 2:14 AM, nicklee1990 notifications@github.com wrote:

without seeing all the code, here's a few things to check:

  1. have you set your auth provider to 'parse' in the auth config file?
  2. have you updated your model in the auth config file? if you aren't extending the User class, then it should be LaraParse\Subclasses\User
  3. in your postRegister function you should be creating a new LaraParse\Subclasses\User not ParseUser. Remember you're creating a new User in your application, and the library will take care of interacting with the storage system (in this case Parse)

What exception are you seeing?

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142537069 .

nicklee1990 commented 9 years ago

well the readme assumes you have an \App\User model which is the default in auth settings and it advises that you should extend LaraParse\Subclasses\User.

I can't see your attached files? but here's some code that should work i think:

public function __construct(Guard $auth,  \LaraParse\Auth\Registrar $registrar, LaraParse\Subclasses\User $user)
{
    $this->auth = $auth;
    $this->registrar = $registrar;
    $this->user = $user;
    $this->middleware('guest', ['except' => 'getLogout']);
}

/**
 * Handle a login request to the application.
 *
 * @param  \Illuminate\Http\Request $request
 * @return \Illuminate\Http\Response
 */
public function postLogin(Request $request)
{
    $this->validate($request, [
        'email' => 'required|email',
        'password' => 'required',
    ]);

    $credentials = $request->only('email', 'password');

    if ($this->auth->attempt($credentials, $request->has('remember_token'))) {
        return redirect()->intended($this->redirectPath());
    }

    return redirect($this->loginPath())
        ->withInput($request->only('email', 'remember_token'))
        ->withErrors([
            'email' => $this->getFailedLoginMessage(),
        ]);
}

 /**
 * @param Request $request
 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 */
public function postRegister(Request $request)
{
    $validator = $this->registrar->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    $this->auth->login($this->registrar->create($request->all()));

    return redirect()->intended($this->redirectPath());
}
Marc-Tanne commented 9 years ago

ok, so should I delete the current class User extends Model implements AuthenticatebleContract, CanResetPasswordContract{}? To confirm, the code you sent me goes in side the class User extends LaraParse\Subclasses\User{}?

On Wed, Sep 23, 2015 at 10:31 AM, nicklee1990 notifications@github.com wrote:

well the readme assumes you have an \App\User model which is the default in auth settings and it advises that you should extend LaraParse\Subclasses\User. Basically in your User model, just put

class User extends LaraParse\Subclasses\User{ //code }

I can't see your attached files? but here's some code that should work i think:

public function __construct(Guard $auth, \LaraParse\Auth\Registrar $registrar, User $user) { $this->auth = $auth; $this->registrar = $registrar; $this->user = $user; $this->middleware('guest', ['except' => 'getLogout']); }

/**

  • Handle a login request to the application. *
  • @param \Illuminate\Http\Request $request
  • @return \Illuminate\Http\Response */ public function postLogin(Request $request) { $this->validate($request, [ 'email' => 'required|email', 'password' => 'required', ]);

    $credentials = $request->only('email', 'password');

    if ($this->auth->attempt($credentials, $request->has('remember_token'))) { return redirect()->intended($this->redirectPath()); }

    return redirect($this->loginPath()) ->withInput($request->only('email', 'remember_token')) ->withErrors([ 'email' => $this->getFailedLoginMessage(), ]); }

    /**

  • @param Request $request
  • @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function postRegister(Request $request) { $validator = $this->registrar->validator($request->all());

    if ($validator->fails()) { $this->throwValidationException( $request, $validator ); }

    $this->auth->login($this->registrar->create($request->all()));

    return redirect()->intended($this->redirectPath()); }

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142673241 .

Marc-Tanne commented 9 years ago

let me share the files with you in drive ​ RegistersUsers.php https://drive.google.com/file/d/0B_Gko_M4eE0wenFuaEE5eldqOGtyVE05b3BnR2lGWDhXVG1J/view?usp=drive_web ​​ AuthController.php https://drive.google.com/file/d/0B_Gko_M4eE0wNXY1RTlvdFM2WUhmMlBLVm5obVVGUkU3bEp3/view?usp=drive_web ​​ routes.php https://drive.google.com/file/d/0B_Gko_M4eE0wUGg4YUx4ZHNWelplNE9HenI5TExTWVBhT0dV/view?usp=drive_web ​​ User.php https://drive.google.com/file/d/0B_Gko_M4eE0wY2RqODRQQXZvYXk4cE5VMjlMUmhuRHlJVzlz/view?usp=drive_web ​​ register.blade.php https://drive.google.com/file/d/0B_Gko_M4eE0wa05JSVRhM21Vdkw4THVQN3JwdmdwYzFsQmpr/view?usp=drive_web

On Wed, Sep 23, 2015 at 10:42 AM, Marc Tanne tannem9@gmail.com wrote:

ok, so should I delete the current class User extends Model implements AuthenticatebleContract, CanResetPasswordContract{}? To confirm, the code you sent me goes in side the class User extends LaraParse\Subclasses\User{}?

On Wed, Sep 23, 2015 at 10:31 AM, nicklee1990 notifications@github.com wrote:

well the readme assumes you have an \App\User model which is the default in auth settings and it advises that you should extend LaraParse\Subclasses\User. Basically in your User model, just put

class User extends LaraParse\Subclasses\User{ //code }

I can't see your attached files? but here's some code that should work i think:

public function __construct(Guard $auth, \LaraParse\Auth\Registrar $registrar, User $user) { $this->auth = $auth; $this->registrar = $registrar; $this->user = $user; $this->middleware('guest', ['except' => 'getLogout']); }

/**

  • Handle a login request to the application. *
  • @param \Illuminate\Http\Request $request
  • @return \Illuminate\Http\Response */ public function postLogin(Request $request) { $this->validate($request, [ 'email' => 'required|email', 'password' => 'required', ]);

    $credentials = $request->only('email', 'password');

    if ($this->auth->attempt($credentials, $request->has('remember_token'))) { return redirect()->intended($this->redirectPath()); }

    return redirect($this->loginPath()) ->withInput($request->only('email', 'remember_token')) ->withErrors([ 'email' => $this->getFailedLoginMessage(), ]); }

    /**

  • @param Request $request
  • @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function postRegister(Request $request) { $validator = $this->registrar->validator($request->all());

    if ($validator->fails()) { $this->throwValidationException( $request, $validator ); }

    $this->auth->login($this->registrar->create($request->all()));

    return redirect()->intended($this->redirectPath()); }

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142673241 .

nicklee1990 commented 9 years ago

just modify User.php to extend LaraParse\Subclasses\User

Then the big chunk of code i pasted goes in your AuthController

Marc-Tanne commented 9 years ago

the code you sent me. Does it replace the existing code in the auth controller?

On Thu, Sep 24, 2015 at 5:54 AM, nicklee1990 notifications@github.com wrote:

just modify User.php to extend LaraParse\Subclasses\User

Then the big chunk of code i pasted goes in your AuthController

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142918988 .

Marc-Tanne commented 9 years ago

it looks like the code in the auth controller is for a different class. I first implemented it in the user model. that did not work. I got an illegal offset error in the parse object. I will try this and let you know what happens. Thanks again for all of your help. I cannot express enough to you how much this means to me!

On Thu, Sep 24, 2015 at 11:05 AM, Marc Tanne tannem9@gmail.com wrote:

the code you sent me. Does it replace the existing code in the auth controller?

On Thu, Sep 24, 2015 at 5:54 AM, nicklee1990 notifications@github.com wrote:

just modify User.php to extend LaraParse\Subclasses\User

Then the big chunk of code i pasted goes in your AuthController

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142918988 .

Marc-Tanne commented 9 years ago

Hi NickLee,

I have worked with another developer on my team and tried to implement what you have said. We are still getting errors.

Are you sure your code is supposed to be dropped in the AuthController?

We dropped the code in the user.php model and got closer to what we want. We are still getting errors on the constructor:

Argument 1 passed to App\User::__construct() must be an instance of App\Guard, none given, called in /Users/Marc/Sites/ local.arcardz.com/app/Http/Controllers/Auth/AuthController.php on line 60 and defined

I feel like we are missing a fundamental step here to get this working. At this phase, I am trying to get a new user to save to our parse DB. Here are our updated files:

Sincerely, Marc Tanne

On Thu, Sep 24, 2015 at 11:06 AM, Marc Tanne tannem9@gmail.com wrote:

it looks like the code in the auth controller is for a different class. I first implemented it in the user model. that did not work. I got an illegal offset error in the parse object. I will try this and let you know what happens. Thanks again for all of your help. I cannot express enough to you how much this means to me!

On Thu, Sep 24, 2015 at 11:05 AM, Marc Tanne tannem9@gmail.com wrote:

the code you sent me. Does it replace the existing code in the auth controller?

On Thu, Sep 24, 2015 at 5:54 AM, nicklee1990 notifications@github.com wrote:

just modify User.php to extend LaraParse\Subclasses\User

Then the big chunk of code i pasted goes in your AuthController

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-142918988 .

nicklee1990 commented 9 years ago

ok, so let's try it this way.

step 1. Update your auth config to have the driver set as Parse. step 2. Update your auth config to have the model set as:

 use LaraParse\SubClasses\User;

step 3. Add the code from above into your AuthController (deleting any methods already there with the same name.

Paste any exception you get here.

Marc-Tanne commented 9 years ago

ok, to confirm, you wanted me to alter the auth.php file under the config folder: I am now getting a Failed to load resource: the server responded with a status of 500 (Internal Server Error)

On Thu, Sep 24, 2015 at 4:34 PM, nicklee1990 notifications@github.com wrote:

ok, so let's try it this way.

step 1. Update your auth config to have the driver set as Parse. step 2. Update your auth config to have the model set as:

use LaraParse\SubClasses\User;

step 3. Add the code from above into your AuthController (deleting any methods already there with the same name.

Paste any exception you get here.

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-143079859 .

Marc-Tanne commented 9 years ago

If I do not change the model delcaration in auth.php (change driver to parse) and load the page, I get this error: FatalErrorException in AuthController.php line 71:Cannot declare class App\Http\Controllers\Auth\User because the name is already in use

On Thu, Sep 24, 2015 at 4:45 PM, Marc Tanne tannem9@gmail.com wrote:

ok, to confirm, you wanted me to alter the auth.php file under the config folder: I am now getting a Failed to load resource: the server responded with a status of 500 (Internal Server Error)

On Thu, Sep 24, 2015 at 4:34 PM, nicklee1990 notifications@github.com wrote:

ok, so let's try it this way.

step 1. Update your auth config to have the driver set as Parse. step 2. Update your auth config to have the model set as:

use LaraParse\SubClasses\User;

step 3. Add the code from above into your AuthController (deleting any methods already there with the same name.

Paste any exception you get here.

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-143079859 .

nicklee1990 commented 9 years ago

what is the actual exception when you get the 500 error and have set the model in your auth config? check your laravel logs

nicklee1990 commented 9 years ago

check your use statements at the top of your Auth Controller. I imagine you've already include a class called User. if so just delete that use statement, or at least but 'as AppUser' or something just while you try to get it to work

Marc-Tanne commented 9 years ago

ok, will do. Let me do that and I will let you know what happens.

On Fri, Sep 25, 2015 at 4:14 AM, nicklee1990 notifications@github.com wrote:

check your use statements at the top of your Auth Controller. I imagine you've already include a class called User. if so just delete that use statement, or at least but 'as AppUser' or something just while you try to get it to work

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-143189317 .

Marc-Tanne commented 9 years ago

ok, so I did not have any use statements declaring App\User I tried to rename the user class you declared and that stopped the error but it still did not work. I began looking at the parseUser.php file and found the signUp() method. I got it to hit the DB once, but then I got a Guard error. I reverted the code and attached my authController.php to show you the code. with the code like this, it throws the same error: FatalErrorException in/Users/Marc/Sites/local.arcardz.com/app/Http/Controllers/Auth/AuthController.php line 74:Cannot declare class App\Http\Controllers\Auth\User because the name is already in use

  1. in AuthController.php line 74

If you have any time, can we skype or gchat? I think that will help stop this back-and-forth. Thanks again! ​ AuthController.php https://drive.google.com/file/d/0B_Gko_M4eE0wMm5WcFItU29wNGs/view?usp=drive_web

On Fri, Sep 25, 2015 at 11:37 AM, Marc Tanne tannem9@gmail.com wrote:

ok, will do. Let me do that and I will let you know what happens.

On Fri, Sep 25, 2015 at 4:14 AM, nicklee1990 notifications@github.com wrote:

check your use statements at the top of your Auth Controller. I imagine you've already include a class called User. if so just delete that use statement, or at least but 'as AppUser' or something just while you try to get it to work

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-143189317 .

Marc-Tanne commented 9 years ago

ok, Looking back at the train of messages I see I misunderstood you. I placed the functions in the authController and extended the model as you mentioned. this is now what the error message displays as: ReflectionException in Container.php line 790:Class App\Http\Controllers\Auth\Guard does not exist

On Fri, Sep 25, 2015 at 12:19 PM, Marc Tanne tannem9@gmail.com wrote:

ok, so I did not have any use statements declaring App\User I tried to rename the user class you declared and that stopped the error but it still did not work. I began looking at the parseUser.php file and found the signUp() method. I got it to hit the DB once, but then I got a Guard error. I reverted the code and attached my authController.php to show you the code. with the code like this, it throws the same error: FatalErrorException in/Users/Marc/Sites/local.arcardz.com/app/Http/Controllers/Auth/AuthController.php line 74:Cannot declare class App\Http\Controllers\Auth\User because the name is already in use

  1. in AuthController.php line 74

If you have any time, can we skype or gchat? I think that will help stop this back-and-forth. Thanks again! ​ AuthController.php https://drive.google.com/file/d/0B_Gko_M4eE0wMm5WcFItU29wNGs/view?usp=drive_web

On Fri, Sep 25, 2015 at 11:37 AM, Marc Tanne tannem9@gmail.com wrote:

ok, will do. Let me do that and I will let you know what happens.

On Fri, Sep 25, 2015 at 4:14 AM, nicklee1990 notifications@github.com wrote:

check your use statements at the top of your Auth Controller. I imagine you've already include a class called User. if so just delete that use statement, or at least but 'as AppUser' or something just while you try to get it to work

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-143189317 .

Marc-Tanne commented 9 years ago

Hey man,

I teamed up with my lead developer and we got it working. Thanks for all your help!

On Fri, Sep 25, 2015 at 3:50 PM, Marc Tanne tannem9@gmail.com wrote:

ok, Looking back at the train of messages I see I misunderstood you. I placed the functions in the authController and extended the model as you mentioned. this is now what the error message displays as: ReflectionException in Container.php line 790:Class App\Http\Controllers\Auth\Guard does not exist

On Fri, Sep 25, 2015 at 12:19 PM, Marc Tanne tannem9@gmail.com wrote:

ok, so I did not have any use statements declaring App\User I tried to rename the user class you declared and that stopped the error but it still did not work. I began looking at the parseUser.php file and found the signUp() method. I got it to hit the DB once, but then I got a Guard error. I reverted the code and attached my authController.php to show you the code. with the code like this, it throws the same error: FatalErrorException in/Users/Marc/Sites/local.arcardz.com/app/Http/Controllers/Auth/AuthController.php line 74:Cannot declare class App\Http\Controllers\Auth\User because the name is already in use

  1. in AuthController.php line 74

If you have any time, can we skype or gchat? I think that will help stop this back-and-forth. Thanks again! ​ AuthController.php https://drive.google.com/file/d/0B_Gko_M4eE0wMm5WcFItU29wNGs/view?usp=drive_web

On Fri, Sep 25, 2015 at 11:37 AM, Marc Tanne tannem9@gmail.com wrote:

ok, will do. Let me do that and I will let you know what happens.

On Fri, Sep 25, 2015 at 4:14 AM, nicklee1990 notifications@github.com wrote:

check your use statements at the top of your Auth Controller. I imagine you've already include a class called User. if so just delete that use statement, or at least but 'as AppUser' or something just while you try to get it to work

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/36#issuecomment-143189317 .

nicklee1990 commented 9 years ago

no problem, glad its working for you now

backersh commented 8 years ago

Hello Dear @nicklee1990

I followed your instructions that you mentioned here , am also working with laraParse provider . I am trying to login with exist users on my parse User table but the login failed and I am getting this message

These credentials do not match our records.

Note : registration work fine

thanks

dmarcos89 commented 8 years ago

Hi @nicklee1990, im almost finishing the installation of laraparse. below i share with you the code of my AuthController.php class. when typing ../auth/login, im getting:

BadMethodCallException in Controller.php line 283: Method [getLogin] does not exist.

Thanks in advance! Damian

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

// use LaraParse\Auth\Subclasses\User;
use Illuminate\Auth\Guard;

class AuthController extends Controller
{
    public function __construct(Guard $auth,  \LaraParse\Auth\Registrar $registrar, User $user)
{
    $this->auth = $auth;
    $this->registrar = $registrar;
    $this->user = $user;
    $this->middleware('guest', ['except' => 'getLogout']);
}

/**
 * Handle a login request to the application.
 *
 * @param  \Illuminate\Http\Request $request
 * @return \Illuminate\Http\Response
 */
public function postLogin(Request $request)
{
    $this->validate($request, [
        'email' => 'required|email',
        'password' => 'required',
    ]);

    $credentials = $request->only('email', 'password');

    if ($this->auth->attempt($credentials, $request->has('remember_token'))) {
        return redirect()->intended($this->redirectPath());
    }

    return redirect($this->loginPath())
        ->withInput($request->only('email', 'remember_token'))
        ->withErrors([
            'email' => $this->getFailedLoginMessage(),
        ]);
}

 /**
 * @param Request $request
 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 */
public function postRegister(Request $request)
{
    $validator = $this->registrar->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    $this->auth->login($this->registrar->create($request->all()));

    return redirect()->intended($this->redirectPath());
}
}
nicklee1990 commented 8 years ago

You need to use the traits which contain these methods. At the top of your class put use AuthenticatesAndRegistersUsers

El 9 ene 2016, a las 6:22, Damian Marcos notifications@github.com escribió:

Hi @nicklee1990, im almost finishing the installation of laraparse. below i share with you the code of my AuthController.php class. when typing ../auth/login, im getting:

BadMethodCallException in Controller.php line 283: Method [getLogin] does not exist.

Thanks in advance! Damian

<?php

namespace App\Http\Controllers\Auth;

use App\User; use Validator; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ThrottlesLogins; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

// use LaraParse\Auth\Subclasses\User; use Illuminate\Auth\Guard;

class AuthController extends Controller { public function __construct(Guard $auth, \LaraParse\Auth\Registrar $registrar, User $user) { $this->auth = $auth; $this->registrar = $registrar; $this->user = $user; $this->middleware('guest', ['except' => 'getLogout']); }

/**

  • Handle a login request to the application. *
  • @param \Illuminate\Http\Request $request
  • @return \Illuminate\Http\Response */ public function postLogin(Request $request) { $this->validate($request, [ 'email' => 'required|email', 'password' => 'required', ]);

    $credentials = $request->only('email', 'password');

    if ($this->auth->attempt($credentials, $request->has('remember_token'))) { return redirect()->intended($this->redirectPath()); }

    return redirect($this->loginPath()) ->withInput($request->only('email', 'remember_token')) ->withErrors([ 'email' => $this->getFailedLoginMessage(), ]); }

    /**

  • @param Request $request
  • @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function postRegister(Request $request) { $validator = $this->registrar->validator($request->all());

    if ($validator->fails()) { $this->throwValidationException( $request, $validator ); }

    $this->auth->login($this->registrar->create($request->all()));

    return redirect()->intended($this->redirectPath()); } }

— Reply to this email directly or view it on GitHub.

dmarcos89 commented 8 years ago

But its already there! This is what i have at the top of my AuthController.php class.

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use AuthenticatesAndRegistersUsers;
use Illuminate\Auth\Guard;

I had changed the driver to parse, and the model is 'model' => LaraParse\Subclasses\User::class.

If i do what you say, this happens: Cannot use AuthenticatesAndRegistersUsers as AuthenticatesAndRegistersUsers because the name is already in use

Then, i comment the line use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; BadMethodCallException in Controller.php line 283: Method [getLogin] does not exist.

Which is exactly the trait i have to include? I couldn't find any AuthenticatesAndRegistersUsers class inside laraparse... Thank you very much for your help!

ghost commented 8 years ago

no what you had was correct

use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

that's just importing/aliasing the file (http://php.net/manual/en/language.namespaces.importing.php). AuthenticatesAndRegistersUsers is a Trait that is included in the base installation of laravel, so your auth controller has to actually use the trait

class AuthController extends Controller
{
        use AuthenticatesAndRegistersUsers, ThrottlesLogins;

// Rest of your class

PHP Traits - http://php.net/manual/en/language.oop5.traits.php