imrealashu / laravel-multiauth Goto Github PK
View Code? Open in Web Editor NEWLaravel 5.2 Multiauth Implementation
Laravel 5.2 Multiauth Implementation
After I login with an admin account, when I click on home instead of the page displaying "You are logged in" the login page for user is shown. There must be some issue on redirect.
After logging in as a Admin.
When clicking on 'Home' at top left corner beside 'Laravel', instead of going to "/home" page it goes to the "/login" page.
Middleware Web affecting display of validation messages.
Route::group([ 'middlewareGroups' => ['web']], function() {
}
Hi @imrealashu, I have used your steps from http://stackoverflow.com/questions/34614753/can-anyone-explain-laravel-5-2-multi-auth-with-example, and I downloaded your repo laravel-multiauth and it worked great, now I have to assign a new table with its own authenticated. So I would have a third auth.
I have followed the steps, I have a Member model with its own MemberAuth folder which contains its AuthController and Password. I set the protected $guard and $redirect to member. I created the middleware ifNotMember and registered it in the Kernel. But when a Member logs in It gets redirected to the /login page. BTW the url for member login is member/login.
If in Authenticate.php I set return redirect()->guest('member'); Then it will go to the member dashboard.
but if that defeats the purpose of the middleware. My MemberController also has the member middleware on the construct function.
The website shows two "Whoops, looks like something went wrong." message when run with 'php artisan server'.
Hi, I have used your package for multi auth and it is working well so far for login. But now I am working on reset password and it isn't working. I mean when I go to reset password link received in email and submit form it returns to same page with no notification and password isn't reset. Even on this form if I give some wrong credentials, proper error message is shown.
Here is my code
auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'user',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'user' => [
'driver' => 'session',
'provider' => 'users'
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'dealer' => [
'driver' => 'session',
'provider' => 'dealers',
]
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'dealers' => [
'driver' => 'eloquent',
'model' => App\Models\Dealer::class,
]
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
'dealers' => [
'provider' => 'dealers',
'email' => 'dealer.auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],
];
PasswordController
<?php
namespace App\Http\Controllers\DealerAuth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Password;
use Message;
class PasswordController extends Controller
{
protected $guard = 'dealer'; //For guard
protected $broker = 'dealers';
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function getEmail()
{
return $this->showLinkRequestForm();
}
public function showLinkRequestForm()
{
if (property_exists($this, 'linkRequestView')) {
return view($this->linkRequestView);
}
if (view()->exists('dealer_cms.auth.passwords.email')) {
return view('dealer_cms.auth.passwords.email');
}
return view('dealer_cms.auth.password');
}
public function showResetForm(Request $request, $token = null)
{
if (is_null($token)) {
return $this->getEmail();
}
$email = $request->input('email');
if (property_exists($this, 'resetView')) {
return view($this->resetView)->with(compact('token', 'email'));
}
if (view()->exists('dealer_cms.auth.passwords.reset')) {
return view('dealer_cms.auth.passwords.reset')->with(compact('token', 'email'));
}
return view('dealer_cms.passwords.auth.reset')->with(compact('token', 'email'));
}
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function ($message) {
$message->subject($this->getEmailSubject());
$message->from('[email protected]',"abc Password Reset");
});
switch ($response) {
case Password::RESET_LINK_SENT:
return redirect()->back()->with('status', trans($response));
case Password::INVALID_USER:
return redirect()->back()->withErrors(['email' => trans($response)]);
}
}
}
And I use authtenticable in my dealers model
/**
* @file Dealer.php
* @Package: App/Models
* @author: Awais Qarni
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Dealer extends Authenticatable {}
routes.php
Route::post('dealer/password/email','DealerAuth\PasswordController@postEmail');
Route::post('dealer/password/reset','DealerAuth\PasswordController@reset');
Route::get('dealer/password/reset/{token?}','DealerAuth\PasswordController@showResetForm');
Can you please look into as it is very urgent matter for me to work on
How to generate a laravel ".env" file if I have downloaded the application from git. Cause when I have downloaded it, I did not see the ".env" in the folder. It supposes to be in the same range with some files (such as ".env.example", "composer.json", etc..) and also some others folders. I know I'll have the APP_KEY of my application in this ".env" file. So how to generate it in order to have the APP_KEY automatically ? Or will I generate it manually myself by copying and modifying the ".env.example" file to an ".env" file with my own APP_KEY inside ? Your answer will help me.
The Registration and Login Page shows no error on wrong validation, instead gets reloaded.
When I typed 'php artisan route:list' I got all the routes, both admin and users. But, in the 'routes.php' file there are no User routes defined, only the routes with admin are present. Where are the user login/register routes defined in????
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.