<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Admin;
use Auth;
class AuthController extends Controller
{
public function register_auth(){
return view('admin.custom_auth.register');
}
public function register(Request $request){
$this->validation($request);
$data = $request->all();
$admin = new Admin();
$admin->admin_name = $data['admin_name'];
$admin->admin_phone = $data['admin_phone'];
$admin->admin_email = $data['admin_email'];
$admin->admin_password = md5($data['admin_password']);
$admin->save();
return redirect('/register-auth')->with('message','Đăng ký thành công');
}
public function validation($request){
return $this->validate($request,[
'admin_name' => 'required|max:255',
'admin_phone' => 'required|max:255',
'admin_email' => 'required|email|max:255',
'admin_password' => 'required|max:255',
]);
}
public function login_auth(){
return view('admin.custom_auth.login_auth');
}
public function login(Request $request){
$this->validate($request,[
'admin_email' => 'required|email|max:255',
'admin_password' => 'required|max:255'
]);
if(Auth::attempt(['admin_email'=>$request->admin_email,'admin_password'=>$request->admin_password ])){
return redirect('/dashboard');
}else{
return redirect('/login-auth')->with('message','Lỗi đăng nhập authentication');
}
}
}
<?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' => 'web',
'passwords' => 'customusers',
],
/*
|--------------------------------------------------------------------------
| 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' => 'customusers',
],
'api' => [
'driver' => 'token',
'provider' => 'customusers',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| 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\Models\User::class,
],
'customusers' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| 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',
'table' => 'password_resets',
'expire' => 60,
],
'customusers' => [
'provider' => 'customusers',
'table' => 'password_resets',
'expire' => 15,
],
],
'socialite' => [
'drivers' => [
'google',
],
],
];
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Admin extends Authenticatable
{
use HasFactory, Notifiable;
public $timestamp = false;
protected $table = 'tbl_admin';
protected $primaryKey = 'admin_id';
protected $fillable = [
'admin_email',
'admin_password',
'admin_name',
'admin_phone'
];
public function getAuthPassword(){
return $this->admin_password;
}
}