PHP code example of whyounes / laravel-passwordless-auth
1. Go to this page and download the library: Download whyounes/laravel-passwordless-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
whyounes / laravel-passwordless-auth example snippets
// app/User.php
class User extends Authenticatable
{
use Whyounes\Passwordless\Traits\Passwordless;
// ...
}
// app/User.php
class User extends Authenticatable
{
use Whyounes\Passwordless\Traits\Passwordless;
// ...
protected function getIdentifierKey()
{
return 'email';
}
}
// config/passwordless.php
return [
'expire_in' => 15, // Minutes
'empty_tokens_after_login' => true // Empty user tokens after login
];
// routes/web.php
Route::post('/login/direct', function(Request $request) {
// send link to user mail
$user = App\User::where('email', $request->get('email'))->first();
if (!$user) {
return redirect()->back(404)->with('error', 'User not found');
}
// generate token and save it
$token = $user->generateToken(true);
// send email to user
\Mail::send("mails.login", ['token' => $token], function($message) use($token) {
$message->to($token->user->email);
});
});