Giter VIP home page Giter VIP logo

Comments (7)

jrean avatar jrean commented on August 18, 2024

Hi @Chalkin thank you for your feedback.
Until the next update you "must" get the user logged in prior to verify the e-mail.
It will be changed and updated soon to allow more flexibility.
Look at this workaround:
#5

About the postRegister method it's weird! Which version of Laravel do you use?
For Laravel 5.0, 5.1 & 5.2 we overwrite the public function postRegister(Request $request) in the AuthController.php file.

Cheers

from laravel-user-verification.

jrean avatar jrean commented on August 18, 2024

So...
The first thing I would like to share is about the default behaviour of Laravel 5.0 / 5.1 / 5.2:

postRegister() 5.0

postRegister() 5.1

register() 5.2

The postRegister / register method log the user in:
5.0 => $this->auth->login($this->registrar->create($request->all()));
5.1 => Auth::login($this->create($request->all()));
5.2 => Auth::guard($this->getGuard())->login($this->create($request->all()));

That said, I built this package with that in mind without thinking one would like to change this default behaviour. My bad. I think if I want this package to be totally agnostic it should just be able to work without any user logged in.

It means it's probably time for a rewrite and so a version 1.0!

Do you have any comments?

from laravel-user-verification.

Chalkin avatar Chalkin commented on August 18, 2024

thanks a lot for the quick response.

I'm gonna check out the register() thing. I'm using Laravel 5.2
I will keep the user logged in after registration for now. But I can't wait until you update that :)

thanks a lot!

from laravel-user-verification.

jrean avatar jrean commented on August 18, 2024

@Chalkin I just commited the update in the release v2.0.
The package works now without the need of an authenticated user.
Can you please find the time to test? I updated the documentation too.

Cheers

from laravel-user-verification.

Chalkin avatar Chalkin commented on August 18, 2024

Yep, works now! It's a looooong verification token now.
I probably would have done it another way. But both work.

  • Check if the user is authenticated
  • If not, i would have gotten the user via the passed verification token

Don't know which way is better.

One thing is still wrong in the documentation.
"Click here to verify your account {{ url('auth/verification/' . $model->verification_token) }}"
needs to be
Click here to verify your account {{ url('auth/verification/' . $user->verification_token) }}

Thanks a lot for changing your package!

from laravel-user-verification.

Chalkin avatar Chalkin commented on August 18, 2024

Just tried to login the user after verification is complete. It does not work with Auth::login($user);

"Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of stdClass given"

So i tried to use the Code suggested in #5 from damarev and now it's possible to log the user in. (slightly changed)

`protected function getUserByEmail($email, $table)
{
$userClassName = auth()->getProvider()->getModel();
$userModel = new $userClassName;
$user = $userModel::where('email', $email)->first();

    // Already verified
    if($user->verified) {
        // todo - do something
    }

    $user->table = $table;

    return $user;
}`

from laravel-user-verification.

jrean avatar jrean commented on August 18, 2024

@Chalkin thank you for the feedback.
The code is still under review and will probably be updated but please let me clarify some details for us.
The wish was to not be tied to to the authentification flow anymore. It is.

  • The token is long.
    Yes, it's, but is it an issue? I don't think so. I used what Laravel offers us. Crypt (AES-256-CBC).
    I tried to be smart because I knew I will also need to get access to the email address so what I did is simple. I encrypt the email address which becomes the token and then later during the verification process I can just decrypt the token and get the email address.
    https://laravel.com/docs/5.2/encryption
  • Auth::login($user) doesn't work anymore.
    Agree. I thought you guys may say one day!

Hey, you designed the package with the User model in mind. What if I want to user another model instead!

So now the retrieved user is an instance of stdClass.

If you want to authenticate the user you may simply use the Auth::loginUsingId($userId);.
If you look at the content of the stdClass $user you will see the following:

{#233 ▼
  +"id": "13"
  +"name": "jean"
  +"email": "[email protected]"
  +"password": "xxxx"
  +"remember_token": null
  +"created_at": "2016-03-23 02:24:06"
  +"updated_at": "2016-03-23 02:24:06"
  +"verified": "0"
  +"verification_token": "eyJpdiI6Ilg3ZHgxZDV1eTNzaUJBZVZCWjUzNGc9PSIsInZhbHVlIjoiSGIycVBjUCtcL1d2bkJPY1lLdk5YZ3gzZklDbTh6TVwvTnFQcHdYWlozdDFjPSIsIm1hYyI6IjBiYWxxxhYjU5ODY3NmQzYzVjZGM3NzFlZDViMjJiOGMxODk2Mjk5ZDQyYWFmOWUwZmExY2FkODMwOTczZjIifQ=="
  +"table": "users"

Simply use the id and your are done.
I hope it will help.
I will check how to improve again.

Cheers

from laravel-user-verification.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.