jrean / laravel-user-verification Goto Github PK
View Code? Open in Web Editor NEWPHP package built for Laravel to easily handle a user email verification and validate the email
License: Other
PHP package built for Laravel to easily handle a user email verification and validate the email
License: Other
Hi,
What is missing if I get: The model instance provided is not compliant with this package. ? Thats not clear from docs.
which is not so simple, since have to create a new guard based on SessionGuard and overwrite hasValidCredentials.
Exciting news, the registerEvent I asked for, was just merged into Laravel: laravel/framework#15401 (comment) and I hope it will be tagged soon.
We should take advantage of this!
My idea is the following:
config
file to the packageonRegistration
or something similar (true
by default)onRegistration
is true.false
we do nothing.This means the user will not need to add anything to the AuthController
once I finish the resend
PR with the move to the Controller!
However this will need to be a minor
update. It is not really a breaking change, but if you just upgrade the system might send 2 emails (because you send on in the AuthController
).
This will make the installation even easier and maintaining it as well, as we do not have to worry about AuthController
changes.
@jrean What do you think?
In your example you mentioned some exceptions, but how should we display them in somewhere like errors/user-verification.blade.php
view?
I've used $message and:
@if (count($errors) > 0)
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
@endif
but they doesn't displayed any error.
It would be awesome if you add a simple example for errors View.
Thanks!
The verification doesn't work, only work for logged in user
public function getVerification($token)
{
$user = auth()->user();
The $user is null.
Type error: Argument 1 passed to Jrean\UserVerification\UserVerification::isVerified() must be an instance of Illuminate\Contracts\Auth\Authenticatable, null given,
Shouldn't the user be looked up by the verification token?
I think it would be awesome if you could add a test suit, this would make contributing much easier, as travis could immediately tell you when you broke something.
Hey,
I think it could be a nice addition to create a trait that you can add to your User
model which introduces 2 new methods:
isVerified
will return a boolean by checking if the verified column is 1
isPending
will return a boolean by checking if
isVerified
While those functions are not hard to write yourself, I think they can be very useful and its a nice convenience addition.
Using direct URLs is according to a lot of people bad practice:
routes.php
file.This is why named routes are used. Currently, all the redirections you provide are using direct URLs instead of named routes. Would be nice to be able to use route aliases.
I'm implementing an API which requires me to return JSON errors rather than the error view for the package however my application is failing to catch the UserIsVerifiedException when sending the data.
This is my verification method:
public function verify(VerificationRequest $request)
{
try
{
\UserVerification::process($request->input('email'), $request->input('token'), 'users');
}
catch(Jrean\UserVerification\Exceptions\UserNotFoundException $exception)
{
return response()->json([$exception->message], 404);
}
catch(Jrean\UserVerification\Exceptions\UserIsVerifiedException $exception)
{
return response()->json([$exception->message]);
}
catch(Jrean\UserVerification\Exceptions\TokenMismatchException $exception)
{
return response()->json([$exception->message], 409);
}
return response()->json(['verified' => true]);
}
This is failing to catch the exception and I'm getting this as the view:
http://i.imgur.com/WycToIG.png
I would like to offer the option to resend a verification email with the old or a new token. A user should just click a link. Can you add this functionality? I guess it would need to be another get route.
Hey,
I think it might be a good idea to change the master branch to be Laravel 5.1, becasue:
Instead of having the master support 5.0 you could, if you wanted to, have a 5.0 branch an backport stuff.
Adding these 2 feature can be so good:
update_at
field of users and time()
; but having a config item to enable/disable this feature and setting the time for it, is a far better option.In addition if this option consider different types of guards
(in case of using multiple authentication table - for admin and users for instance) it would be ground breaking.
If you give me some hints - as I didn't write any library for Laravel till now - I can help ๐
At line 226 of README.md:
$verifiationErrorView = 'errors.user-verification';
$verificationErrorView = 'errors.user-verification';
Yeah?
Good afternoon.
I have the following code in my RegisterController.php
$user = $this->create($request->all());
UserVerification::generate($user);
UserVerification::emailView('emails.auth.email');
UserVerification::sendQueue($user, 'Subject string');
When the user is registered I get the following exception and stack trace:
ErrorException in SerializableClosure.php line 116: Serialization of closure failed: Serialization of 'Closure' is not allowed
in SerializableClosure.php line 116
at HandleExceptions->handleError('1024', 'Serialization of closure failed: Serialization of 'Closure' is not allowed', '/home/vagrant/project/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php', '116', array('e' => object(Exception)))
at trigger_error('Serialization of closure failed: Serialization of 'Closure' is not allowed', '1024') in SerializableClosure.php line 116
at SerializableClosure->serialize()
at serialize(object(SerializableClosure)) in Serializer.php line 68
at Serializer->serialize(object(Closure)) in HandleQueuedMessage.php line 75
at HandleQueuedMessage->__sleep()
at serialize(object(HandleQueuedMessage)) in Queue.php line 86
at Queue->createPayload(object(HandleQueuedMessage), '') in RedisQueue.php line 202
at RedisQueue->createPayload(object(HandleQueuedMessage), '') in RedisQueue.php line 82
at RedisQueue->push(object(HandleQueuedMessage), '', null) in Queue.php line 37
at Queue->pushOn(null, object(HandleQueuedMessage)) in QueueManager.php line 263
at QueueManager->__call('pushOn', array(null, object(HandleQueuedMessage))) in Mailer.php line 215
at Mailer->queue('emails.auth.email', array('user' => object(User)), object(Closure)) in UserVerification.php line 351
at UserVerification->emailQueueVerificationLink(object(User), 'Subject string', null, null) in UserVerification.php line 137
at UserVerification->sendQueue(object(User), 'Subject string') in Facade.php line 237
at Facade::__callStatic('sendQueue', array(object(User), 'Subject string')) in RegisterController.php line 138
at RegisterController->register(object(Request))
at call_user_func_array(array(object(RegisterController), 'register'), array(object(Request))) in Controller.php line 55
at Controller->callAction('register', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(RegisterController), 'register') in Route.php line 189
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in RedirectIfAuthenticated.php line 24
at RedirectIfAuthenticated->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ClockworkMiddleware.php line 41
at ClockworkMiddleware->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53
If I use the UserVerification::send()
function instead it works, but I would like to take advantage of the Laravel queue. The email view is customized.
Thank you very much for your help ๐
I think resending a verification email is a very typical thing, I see it on nearly every platform. I think it would be good to add a default route that does the resend and redirects back to the page the user comes from.
in your example implementation you rewrite postRegister function although it'd have to be register (at least in laravel 5.2.34) since this is the default route:list
| | POST | register | | App\Http\Controllers\Auth\AuthController@register | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController@showRegistrationForm | web,guest |
and if you look into Illuminate/Foundation/Auth/RegistersUsers.php:
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postRegister(Request $request)
{
return $this->register($request);
}
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
Auth::guard($this->getGuard())->login($this->create($request->all()));
return redirect($this->redirectPath());
}
so IMHO in the example implementation:
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
$user = $this->create($request->all());
// Authenticating the user is not mandatory at all.
// Auth::guard($this->getGuard())->login($user);
UserVerification::generate($user);
UserVerification::send($user, 'ARK Logbook Email Verification');
return redirect($this->redirectPath());
}
regards.
use Jrean\UserVerification\VerificationException
should be added to the top of src/UserVerification.php
Currently spits this out if exception is thrown:
exception 'Symfony\Component\Debug\Exception\FatalErrorException'
with message 'Class 'Jrean\UserVerification\VerificationException' not found'
in C:\wamp\www\attestation\vendor\jrean\laravel-user-verification\src\UserVerification.php:170
Hi,
I would like to keep the user logged out after registration and sign him in after he verified his e-mail.
So i removed the "Auth::login($user);" from the postRegister(Request $request) function. But now the auth()->user does not return a user. (Since the user is not logged in) (btw. I somehow could not overwrite the postRegister method and had to use the register method - don't know why?!)
So what's in your opinion the best way to make this possible with your package? Should we get the user with the User Model and find the entry with the corresponding verification_token?
Hey @jrean,
how about adding a https://styleci.io/ hook to the project? This would let you make sure the code style is consistent.
It is free for open source projects, so the only thing would be to fix the code initially, which can be done automatically via php-cs-fixer
or an automated PR from styleCI.
Of course a https://github.com/FriendsOfPHP/PHP-CS-Fixer should also be added so one can run this to catch most problems locally before submitting a PR.
I'd like the user to have to login before actually being able to verify his account. How would I go about this?
hi and thanks for this - really super helpful
i am having an issue with token mismatch but the token are in fact identical (i compared the email token to the database token) - is there anyway i can see what exactly the verification link params look like to the verification code? i cannot see a way to easily pass the exception object or data thru to the error view, unless i'm missing something
When sending the email I get the following error. I set my mail driver to log
.
I think you should probably change the mailing to use the notification system for laravel 5.3
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
"
in AbstractSmtpTransport.php line 383
at Swift_Transport_AbstractSmtpTransport->_assertResponseCode('530 5.7.1 Authentication required ', array('250')) in AbstractSmtpTransport.php line 281
at Swift_Transport_AbstractSmtpTransport->executeCommand('MAIL FROM:<[email protected]> ', array('250'), array()) in EsmtpTransport.php line 270
at Swift_Transport_EsmtpTransport->executeCommand('MAIL FROM:<[email protected]> ', array('250')) in EsmtpTransport.php line 348
at Swift_Transport_EsmtpTransport->_doMailFromCommand('[email protected]') in AbstractSmtpTransport.php line 416
at Swift_Transport_AbstractSmtpTransport->_doMailTransaction(object(Swift_Message), '[email protected]', array('[email protected]'), array()) in AbstractSmtpTransport.php line 443
at Swift_Transport_AbstractSmtpTransport->_sendTo(object(Swift_Message), '[email protected]', array('[email protected]' => null), array()) in AbstractSmtpTransport.php line 176
at Swift_Transport_AbstractSmtpTransport->send(object(Swift_Message), array()) in Mailer.php line 85
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 374
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 196
at Mailer->send('emails.user-verification', array('user' => object(User), 'message' => object(Message)), object(Closure)) in UserVerification.php line 340
at UserVerification->emailVerificationLink(object(User), 'My Custom E-mail Subject', null, null) in UserVerification.php line 116
at UserVerification->send(object(User), 'My Custom E-mail Subject') in Facade.php line 238
at Facade::__callStatic('send', array(object(User), 'My Custom E-mail Subject')) in web.php line 25
at RouteServiceProvider->{closure}() in Route.php line 176
at Route->runCallable() in Route.php line 147
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 263
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53
at require('/Users/lukasoppermann/Code/fs-cms/public/index.php') in server.php line 106
There's loads of things that don't work, at least with 5.2. The composer.json indicated this works with laravel 5.2, but... can't get it to work.
The example AuthController - shouldn't be 'postRegister' - it needs to be 'register'. The $this-> in the traits seems to get confused maybe?
Auth::login($user);
UserVerification::generate($user);
UserVerification::send($user, 'My Custom Email Subject');
These lines don't make any sense - there's no static methods for generate() or send() on UserVerification class.
Did this used to work on earlier Laravel?
I receive the following exception:
Maximum function nesting level of '100' reached, aborting!
This is my excerpt code from the register method (in AuthController.php):
// Laravel > 5.2.7
Auth::guard($this->getGuard())->login($user);
UserVerification::generate($user);
UserVerification::send($user, 'My Custom E-mail Subject');
return redirect($this->redirectPath());
And this is my inclusion header:
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 Jrean\UserVerification\Traits\VerifiesUsers;
use Jrean\UserVerification\Facades\UserVerification;
use Jrean\UserVerification\UserVerificationServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
I have followed the instructions for setting up laravel-user-verification.
A test user fills out signup form, and is sent an email with a token link.
However, when test user clicks on token link they are redirected to error:
NotFoundHttpException in RouteCollection.php line 161:
What I am guessing is that when the user clicks on the verification link in the email its redirecting them somewhere that doesnt exist. Any guidance would be much appreciated.
Just a suggestion, i think generated token/code should be random and fixed length:
protected function generateToken($email)
{
return sha1(microtime() . Crypt::encrypt($email));
}
Now, Crypt::encrypt($email) returns a string of 272 characters from a 40 characters email, exceeding the 255 limit of the database migration.
Would you consider a PR?
Thank you for this nice laravel package.
this happened running migrations on empty database
[Illuminate\Database\QueryException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'verified' (SQL: alter table users add verified tinyint(1)
not n
ull default '0', add verification_token varchar(255) null)
[PDOException] SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'verified'
This means you already have the column in your table. Why do you try to run the migration again? Apparently your table is already set up. Did you alter your user table migration to include this verified field?
If so you should remove it from the user table migration
.
More a question than anything.
When users register, I am happy for them to be logged in immediately. However, some areas of the application need the user to be verified first, and I intend to implement that by assigning a role (which is checked by the authorisation layer).
I am guessing there are events that are fired which would allow me to update the user (giving them a role)?
This verification confirms the user's email is working. Changing their email would set them back to an unverified state again. That's fine.
How about checking the user is a human as a part of verification? Does this package support hooking in, say, a reCaptcha to do that? Or is that just something to add to the view and controller/middleware?
Hello,
Thanks for the wonderful work.
I tried to implement the code just like you gave in readme. This is my code for AuthController in Laravel 5.2.31.
<?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 Jrean\UserVerification\Traits\VerifiesUsers;
use Jrean\UserVerification\Facades\UserVerification;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
use VerifiesUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
protected $username = 'username';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => ['logout', 'getVerification', 'getVerificationError']]);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|unique:users|min:3',
'password' => 'required|confirmed|min:6',
'email' => 'required|email|max:255|unique:users',
'firstname' => 'required|min:2',
'lastname' => 'min:2',
'agreement' => 'required',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'password' => bcrypt($data['password']),
'email' => $data['email'],
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
]);
}
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
$user = $this->create($request->all());
//Auth::guard($this->getGuard())->login($user);
UserVerification::generate($user);
UserVerification::send($user, 'My Custom E-mail Subject');
return redirect($this->redirectPath());
}
}
But user doesn't receive the email for verification. Actually the mail is working for 'change password' and 'contact us' mail, so the mail should not have problem.
Could you please give me a solution? I'm completely new to this and I'm still trying my best to learn. Thanks in advance.
Hey @jrean,
I think we should add an optional middleware, which if loaded checks if the user is verified and if not redirects the user to a specific page or something like this.
The behaviour should probably be customizable as it depends on your app but I think the general take an action if user is NOT verified is a general concern for many people.
Just installed your package. Found out thats its unable to run migration due to the fact, that migration provided with the package dated on September 2016, my new user migrations is dated October 2016, so engine tries to migrate your file first and then mine files.
I'm running Laravel 5.3.
From here comes the error that there is no users table. Please, find time to fix this problem.
I think the token
and verified
column should be moved from the user table and put into a separate table just like the password reset table, with an email address and a created_at. This would mean there is not need to change the user-table, which might be a bit of an issue if the package is added later on. See: #71
This would:
user_verification
table. This is just a fallback in case a user_verification
table exists already.Error; Trait method redirectIfVerified has not been applied, because there are collisions with other trait methods on App\Http\Controllers\Auth\AuthController
I have this code:
<?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 Jrean\UserVerification\Traits\VerifiesUsers;
use Jrean\UserVerification\Traits\RedirectsUsers;
use UserVerification;
use Auth;
use Carbon\Carbon;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins, VerifiesUsers, RedirectsUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
protected $redirectIfVerified = '/';
Hey, as of laravel 5.3 you can ship migrations that can be execute from within the package directory: https://www.laravel.com/docs/5.3/packages#migrations
I think this would be very beneficial for the packages to add those, at it makes the setup a lot easier.
Also you could register the facades in the service provider, this would reduce another setup step.
public function register()
{
$this->app->booting(function()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('UserVerification', 'Jrean\UserVerification\Facades\UserVerification');
});
}
Additionally an email template would be awesome. You can make it publishable in laravel 5.3 like so: https://www.laravel.com/docs/5.3/packages#public-assets
Hello,
I installed this package, and it works well, with the exception of one thing. A newly registered user who has not verified their account yet (verified = 0) is allowed login access. Is this behavior intended?
Thanks,
Jay
Using a previous version of this package worked great, especially when I wanted a finer grain control over what the user can see on a given page. I would use isVerified to switch things on and off, but that method has gone private for some reason, breaking my implementation. Why is that? Is there a workaround so I can call UserVerification::isVerified($USER) again?
Here is the error:
FatalErrorException in Facade.php line 218:
Call to protected method Jrean\UserVerification\UserVerification::isVerified() from context 'Illuminate\Support\Facades\Facade
I've confirmed this by simply making isVerfied() a public method.
Hey @jrean,
this seems to be nearly exactly the same code:
https://github.com/jrean/laravel-user-verification/blob/master/src/UserVerification.php#L332-L339
https://github.com/jrean/laravel-user-verification/blob/master/src/UserVerification.php#L354-L361
https://github.com/jrean/laravel-user-verification/blob/master/src/UserVerification.php#L377-L384
https://github.com/jrean/laravel-user-verification/blob/master/src/UserVerification.php#L400-L407
https://github.com/jrean/laravel-user-verification/blob/master/src/UserVerification.php#L423-L430
This could be probably refactored into a function and the parts that differ could be moved into the functions above e.g. the sendLater
function. This would reduce much code and make it easier to understand, maintain and refactor.
Would be nice to be able to have a configuration to indicate the path for the views.
By default they are errors.user-verification
and emails.user-verification
which may not be convenient depending on how the project structures its views.
Here is a quick draft. That should be trivial to add.
/** config/user-verification.php */
return [
'views' => [
'email' => 'emails.user-verification',
'error' => 'emails.user-verification',
],
];
/** src/UserVerificationServiceProvider.php */
public function register()
{
$this->mergeConfigFrom(
dirname(__DIR__) . '/config/user-verification.php', 'user-verification'
);
}
/** src/UserVerificationServiceProvider.php */
protected function emailVerificationLink(AuthenticatableContract $user, $subject, $from = null, $name = null)
{
return $this->mailer->send(config('user-verification:user-verification.views.email'), compact('user'), function ($m) use ($user, $subject, $from, $name) {
if (! empty($from)) {
$m->from($from, $name);
}
$m->to($user->email);
$m->subject(is_null($subject) ? 'Your Account Verification Link' : $subject);
});
}
For the 3.0 branch we should move to using the https://laravel.com/docs/5.3/notifications as discussed in other tickets.
This ticket is here to track the process.
Hi,
I am getting the error AuthController::getVerification() does not exist ...
I have included the following and installed the package.
use Auth;
use Jrean\UserVerification\Traits\VerifiesUsers;
use Jrean\UserVerification\Facades\UserVerification;
:(
Do you have tried to use your library with jenssegers/laravel-mongodb on Laravel 5.2 ?
Which steps do I have to modify in the installation instructions ?
Thanks
If we change primary key name other than "id" the user verification doesn't work because your hard coding table primary key in getUserByEmail function inside UserVerification.php file.
I've been following the instructions for your user email verification package. Installing via composer and adding service provider/alias/migration/views/routes have been very straightforward, but the part that is very confusing for me is editing AuthController.php. Here is the sample code in the directions: http://paste.ee/p/AjQSB and here is my own code so far: http://paste.ee/p/5ba7e "ReflectionException in Route.php line 286: Class App\Http\Controllers\Auth\Request does not exist" is the error that I am currently getting when I try to register a user. The other part that is not totally clear to me is when the directions say that "The model representing the User must implement the authenticatable interface Illuminate\Contracts\Auth\Authenticatable which is the default with the Eloquent User model." This is what my user table model currently looks like: http://paste.ee/p/ZdlyY
I think a default template for the error page should be shipped in the package. Maybe the user could even publish it and use it to create a custom one, but if the user choses not to, a default one should be shown.
Hey All,
I don't know how to force the user to authenticate his email (activation link is sent)
he can login without verifying his email.
please advise.
thanks,
avi
Hey,
I think it would be good to add a language file for all the text and move it out of the code, for example here: https://github.com/jrean/laravel-user-verification/blob/master/src/UserVerification.php#L430 but also here: https://github.com/jrean/laravel-user-verification/blob/master/src/resources/views/user-verification.blade.php#L9-L17
This would:
We could make the language file publishable by the artisan publish command as well, I think.
Let me know if you like the idea and I will send a PR.
Hey, currently the user has to set the routes in their routing file. I think it would be much nicer, if the package would define the routes by default.
Like so: https://laravel.com/docs/5.3/packages#routing
If you would be interested I could send a PR with this change.
Hey, as of laravel 5.3 you can ship migrations that can be execute from within the package directory: https://www.laravel.com/docs/5.3/packages#migrations
The user does not even have to export them. I think it would be a very nice addition for the user to add this. One less step to install this package.
I am getting this error when hitting the email-verification/check/ route:
Method [getVerification] does not exist.
I am working with Spark and Laravel 5.3. I am sure its something I am doing wrong, but not sure.
Any help would be appreciated.
Thank You!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.