| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- -------------------------------------------------
- ✅ Install Laravel
- -------------------------------------------------
- composer create-project laravel/laravel multiauth
- cd multiauth
- php artisan serve
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ config > auth.php
- -------------------------------------------------
- 'guards' => [
- 'web' => [
- 'driver' => 'session',
- 'provider' => 'users',
- ],
- 'admin' => [
- 'driver' => 'session',
- 'provider' => 'admins',
- ],
- ],
- 'providers' => [
- 'users' => [
- 'driver' => 'eloquent',
- 'model' => env('AUTH_MODEL', App\Models\User::class),
- ],
- 'admins' => [
- 'driver' => 'eloquent',
- 'model' => env('AUTH_MODEL', App\Models\Admin::class),
- ],
- ],
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Migrations
- -------------------------------------------------
- php artisan make:migration create_admins_table
- -------------------------------------------------
- ✅ Migration > users table
- -------------------------------------------------
- $table->id();
- $table->string('name');
- $table->string('email')->unique();
- $table->string('photo')->nullable();
- $table->string('password');
- $table->string('phone')->nullable();
- $table->string('country')->nullable();
- $table->string('address')->nullable();
- $table->string('state')->nullable();
- $table->string('city')->nullable();
- $table->string('zip')->nullable();
- $table->string('token')->nullable();
- $table->string('status')->default(0)->comment('0=pending, 1=active, 2=suspended');
- $table->timestamps();
- -------------------------------------------------
- ✅ Migration > admins table
- -------------------------------------------------
- $table->id();
- $table->string('name');
- $table->string('email')->unique();
- $table->string('photo')->nullable();
- $table->string('password');
- $table->string('token')->nullable();
- $table->timestamps();
- -------------------------------------------------
- ✅ Run Migration
- -------------------------------------------------
- php artisan migrate
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Models
- -------------------------------------------------
- php artisan make:model Admin
- -------------------------------------------------
- ✅ app/Models/User.php
- -------------------------------------------------
- use Illuminate\Contracts\Auth\MustVerifyEmail;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- class User extends Authenticatable implements MustVerifyEmail
- use HasFactory, Notifiable;
- protected $fillable = [
- 'name',
- 'email',
- 'photo',
- 'password',
- 'phone',
- 'country',
- 'address',
- 'state',
- 'city',
- 'zip',
- 'token',
- 'status',
- ];
- -------------------------------------------------
- ✅ app/Models/Admin.php
- -------------------------------------------------
- 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;
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Seeder
- -------------------------------------------------
- php artisan make:seeder AdminSeeder
- -------------------------------------------------
- ✅ seeders/AdminSeeder.php
- -------------------------------------------------
- use App\Models\Admin;
- use Hash;
- public function run(): void
- {
- $obj = new Admin;
- $obj->name = "Admin";
- $obj->email = "admin@gmail.com";
- $obj->photo = "";
- $obj->password = Hash::make('1234');
- $obj->token = "";
- $obj->save();
- }
- -------------------------------------------------
- ✅ seeders/DatabaseSeeder.php
- -------------------------------------------------
- public function run(): void
- {
- $this->call([AdminSeeder::class]);
- }
- -------------------------------------------------
- ✅ Run Seeder
- -------------------------------------------------
- php artisan db:seed
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Email
- -------------------------------------------------
- php artisan make:mail Websitemail
- -------------------------------------------------
- ✅ app/Mail/Websitemail.php
- -------------------------------------------------
- public $subject, $body;
- public function __construct($subject,$body)
- {
- $this->subject = $subject;
- $this->body = $body;
- }
- public function envelope(): Envelope
- {
- return new Envelope(
- subject: $this->subject,
- );
- }
- public function content(): Content
- {
- return new Content(
- view: 'email'
- );
- }
- -------------------------------------------------
- ✅ resources/views/email.blade.php
- -------------------------------------------------
- {!! $body !!}
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Middlewares
- -------------------------------------------------
- php artisan make:middleware User
- php artisan make:middleware Admin
- -------------------------------------------------
- ✅ app/Http/Middleware/User.php
- -------------------------------------------------
- use Auth;
- public function handle(Request $request, Closure $next): Response
- {
- if(!Auth::guard('web')->check()) {
- return redirect()->route('login');
- }
- return $next($request);
- }
- -------------------------------------------------
- ✅ app/Http/Middleware/Admin.php
- -------------------------------------------------
- use Auth;
- public function handle(Request $request, Closure $next): Response
- {
- if(!Auth::guard('admin')->check()) {
- return redirect()->route('admin_login');
- }
- return $next($request);
- }
- -------------------------------------------------
- ✅ bootstrap/app.php
- -------------------------------------------------
- ->withMiddleware(function (Middleware $middleware) {
- $middleware->alias([
- 'admin' => \App\Http\Middleware\Admin::class,
- 'auth' => \App\Http\Middleware\User::class,
- ]);
- })
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ routes/web.php
- -------------------------------------------------
- use App\Http\Controllers\FrontController;
- use App\Http\Controllers\User\UserController;
- use App\Http\Controllers\Admin\AdminController;
- // Front
- Route::get('/', [FrontController::class, 'home'])->name('home');
- Route::get('/about', [FrontController::class, 'about'])->name('about');
- // User
- Route::middleware('auth')->group(function () {
- Route::get('/dashboard',[UserController::class,'dashboard'])->name('dashboard');
- });
- Route::get('/register',[UserController::class,'register'])->name('register');
- Route::post('/register_submit',[UserController::class,'register_submit'])->name('register_submit');
- Route::get('/register_verify/{token}/{email}',[UserController::class,'register_verify'])->name('register_verify');
- Route::get('/login',[UserController::class,'login'])->name('login');
- Route::post('/login',[UserController::class,'login_submit'])->name('login_submit');
- Route::get('/logout',[UserController::class,'logout'])->name('logout');
- Route::get('/forget_password',[UserController::class,'forget_password'])->name('forget_password');
- Route::post('/forget_password',[UserController::class,'forget_password_submit'])->name('forget_password_submit');
- Route::get('/reset-password/{token}/{email}',[UserController::class,'reset_password'])->name('reset_password');
- Route::post('/reset-password/{token}/{email}',[UserController::class,'reset_password_submit'])->name('reset_password_submit');
- // Admin
- Route::middleware('admin')->prefix('admin')->group(function () {
- Route::get('/dashboard',[AdminController::class,'dashboard'])->name('admin_dashboard');
- Route::get('/profile',[AdminController::class,'profile'])->name('admin_profile');
- Route::post('/profile',[AdminController::class,'profile_update'])->name('admin_profile_update');
- });
- Route::prefix('admin')->group(function () {
- Route::get('/', function () {return redirect('/admin/login');});
- Route::get('/login',[AdminController::class,'login'])->name('admin_login');
- Route::post('/login',[AdminController::class,'login_submit'])->name('admin_login_submit');
- Route::get('/logout',[AdminController::class,'logout'])->name('admin_logout');
- Route::get('/forget-password',[AdminController::class,'forget_password'])->name('admin_forget_password');
- Route::post('/forget_password_submit',[AdminController::class,'forget_password_submit'])->name('admin_forget_password_submit');
- Route::get('/reset-password/{token}/{email}',[AdminController::class,'reset_password'])->name('admin_reset_password');
- Route::post('/reset-password/{token}/{email}',[AdminController::class,'reset_password_submit'])->name('admin_reset_password_submit');
- });
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Views
- -------------------------------------------------
- php artisan make:view front/home
- php artisan make:view front/about
- php artisan make:view admin/login
- php artisan make:view admin/dashboard
- php artisan make:view admin/forget-password
- php artisan make:view admin/reset-password
- php artisan make:view user/register
- php artisan make:view user/login
- php artisan make:view user/dashboard
- php artisan make:view user/forget-password
- php artisan make:view user/reset-password
- -------------------------------------------------
- ✅ views/front/home.blade.php
- -------------------------------------------------
- <a href="{{ route('home') }}">Home</a> | <a href="{{ route('about') }}">About</a> | <a href="{{ route('login') }}">Login</a> | <a href="{{ route('register') }}">Register</a>
- <h2>Home Page</h2>
- -------------------------------------------------
- ✅ views/front/about.blade.php
- -------------------------------------------------
- <a href="{{ route('home') }}">Home</a> | <a href="{{ route('about') }}">About</a> | <a href="{{ route('login') }}">Login</a> | <a href="{{ route('register') }}">Register</a>
- <h2>About Page</h2>
- -------------------------------------------------
- ✅ views/admin/login.blade.php
- -------------------------------------------------
- <h2>Admin Login</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('admin_login_submit') }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Email: </td>
- <td><input type="text" name="email" placeholder="Email"></td>
- </tr>
- <tr>
- <td>Password: </td>
- <td><input type="password" name="password" placeholder="Password"></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="submit">Login</button>
- <div><a href="{{ route('admin_forget_password') }}">Forget Password?</a></div>
- </td>
- </tr>
- </table>
- </form>
- -------------------------------------------------
- ✅ views/admin/dashboard.blade.php
- -------------------------------------------------
- <h2>Admin Dashboard</h2>
- <a href="{{ route('admin_logout') }}">Logout</a>
- -------------------------------------------------
- ✅ views/admin/forget-password.blade.php
- -------------------------------------------------
- <h2>Admin Forget Password</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('admin_forget_password_submit') }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Email: </td>
- <td><input type="text" name="email" placeholder="Email"></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="submit">Submit</button>
- <div><a href="{{ route('admin_login') }}">Back to login page</a></div>
- </td>
- </tr>
- </table>
- </form>
- -------------------------------------------------
- ✅ views/admin/reset-password.blade.php
- -------------------------------------------------
- <h2>Admin Reset Password</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('admin_reset_password_submit',[$token,$email]) }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Password: </td>
- <td><input type="password" name="password"></td>
- </tr>
- <tr>
- <td>Confirm Password: </td>
- <td><input type="password" name="confirm_password"></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="submit">Submit</button>
- </td>
- </tr>
- </table>
- </form>
- -------------------------------------------------
- ✅ views/user/register.blade.php
- -------------------------------------------------
- <a href="{{ route('home') }}">Home</a> | <a href="{{ route('about') }}">About</a> | <a href="{{ route('login') }}">Login</a> | <a href="{{ route('register') }}">Register</a>
- <h2>User Registration</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('register_submit') }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Name: </td>
- <td><input type="text" name="name" placeholder="Name"></td>
- </tr>
- <tr>
- <td>Email: </td>
- <td><input type="text" name="email" placeholder="Email"></td>
- </tr>
- <tr>
- <td>Password: </td>
- <td><input type="password" name="password" placeholder="Password"></td>
- </tr>
- <tr>
- <td>Confirm Password: </td>
- <td><input type="password" name="confirm_password" placeholder="Confirm Password"></td>
- </tr>
- <tr>
- <td></td>
- <td><button type="submit">Submit</button></td>
- </tr>
- </table>
- </form>
- -------------------------------------------------
- ✅ views/user/login.blade.php
- -------------------------------------------------
- <a href="{{ route('home') }}">Home</a> | <a href="{{ route('about') }}">About</a> | <a href="{{ route('login') }}">Login</a> | <a href="{{ route('register') }}">Register</a>
- <h2>User Login</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('login_submit') }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Email: </td>
- <td><input type="text" name="email" placeholder="Email"></td>
- </tr>
- <tr>
- <td>Password: </td>
- <td><input type="password" name="password" placeholder="Password"></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="submit">Login</button>
- <div><a href="{{ route('forget_password') }}">Forget Password?</a></div>
- </td>
- </tr>
- </table>
- </form>
- -------------------------------------------------
- ✅ views/user/dashboard.blade.php
- -------------------------------------------------
- <h2>User Dashboard</h2>
- <a href="{{ route('logout') }}">Logout</a>
- -------------------------------------------------
- ✅ views/user/forget-password.blade.php
- -------------------------------------------------
- <a href="{{ route('home') }}">Home</a> | <a href="{{ route('about') }}">About</a> | <a href="{{ route('login') }}">Login</a> | <a href="{{ route('register') }}">Register</a>
- <h2>User Forget Password</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('forget_password_submit') }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Email: </td>
- <td><input type="text" name="email" placeholder="Email"></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="submit">Submit</button>
- <div><a href="{{ route('login') }}">Back to login page</a></div>
- </td>
- </tr>
- </table>
- </form>
- -------------------------------------------------
- ✅ views/user/reset-password.blade.php
- -------------------------------------------------
- <a href="{{ route('home') }}">Home</a> | <a href="{{ route('about') }}">About</a> | <a href="{{ route('login') }}">Login</a> | <a href="{{ route('register') }}">Register</a>
- <h2>User Reset Password</h2>
- @if($errors->any())
- @foreach ($errors->all() as $error)
- {{ $error }}<br>
- @endforeach
- @endif
- @if(session('success'))
- {{ session('success') }}
- @endif
- @if(session('error'))
- {{ session('error') }}
- @endif
- <form action="{{ route('reset_password_submit',[$token,$email]) }}" method="post">
- @csrf
- <table>
- <tr>
- <td>Password: </td>
- <td><input type="password" name="password"></td>
- </tr>
- <tr>
- <td>Confirm Password: </td>
- <td><input type="password" name="confirm_password"></td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="submit">Submit</button>
- </td>
- </tr>
- </table>
- </form>
- ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
- -------------------------------------------------
- ✅ Controllers
- -------------------------------------------------
- php artisan make:controller FrontController
- php artisan make:controller Admin/AdminController
- php artisan make:controller User/UserController
- -------------------------------------------------
- ✅ app\Http\Controllers\FrontController.php
- -------------------------------------------------
- public function home()
- {
- return view('front.home');
- }
- public function about()
- {
- return view('front.about');
- }
- -------------------------------------------------
- ✅ app\Http\Controllers\Admin\AdminController.php
- -------------------------------------------------
- use Auth;
- use Hash;
- use App\Models\Admin;
- use App\Mail\Websitemail;
- public function dashboard()
- {
- return view('admin.dashboard');
- }
- public function login()
- {
- return view('admin.login');
- }
- public function login_submit(Request $request)
- {
- $request->validate([
- 'email' => ['required', 'email'],
- 'password' => ['required'],
- ]);
- $check = $request->all();
- $data = [
- 'email' => $check['email'],
- 'password' => $check['password']
- ];
- if(Auth::guard('admin')->attempt($data)) {
- return redirect()->route('admin_dashboard');
- } else {
- return redirect()->route('admin_login')->with('error','The information you entered is incorrect! Please try again!');
- }
- }
- public function logout()
- {
- Auth::guard('admin')->logout();
- return redirect()->route('admin_login')->with('success','Logout is successful!');
- }
- public function forget_password()
- {
- return view('admin.forget-password');
- }
- public function forget_password_submit(Request $request)
- {
- $request->validate([
- 'email' => ['required', 'email'],
- ]);
- $admin = Admin::where('email',$request->email)->first();
- if(!$admin) {
- return redirect()->back()->with('error','Email is not found');
- }
- $token = hash('sha256',time());
- $admin->token = $token;
- $admin->update();
- $reset_link = url('admin/reset-password/'.$token.'/'.$request->email);
- $subject = "Password Reset";
- $message = "To reset password, please click on the link below:<br>";
- $message .= "<a href='".$reset_link."'>Click Here</a>";
- \Mail::to($request->email)->send(new Websitemail($subject,$message));
- return redirect()->back()->with('success','We have sent a password reset link to your email. Please check your email. If you do not find the email in your inbox, please check your spam folder.');
- }
- public function reset_password($token,$email)
- {
- $admin = Admin::where('email',$email)->where('token',$token)->first();
- if(!$admin) {
- return redirect()->route('admin_login')->with('error','Token or email is not correct');
- }
- return view('admin.reset-password', compact('token','email'));
- }
- public function reset_password_submit(Request $request, $token, $email)
- {
- $request->validate([
- 'password' => ['required'],
- 'confirm_password' => ['required','same:password'],
- ]);
- $admin = Admin::where('email',$request->email)->where('token',$request->token)->first();
- $admin->password = Hash::make($request->password);
- $admin->token = "";
- $admin->update();
- return redirect()->route('admin_login')->with('success','Password reset is successful. You can login now.');
- }
- -------------------------------------------------
- ✅ app\Http\Controllers\User\UserController.php
- -------------------------------------------------
- use Auth;
- use Hash;
- use App\Models\User;
- use App\Mail\Websitemail;
- public function dashboard()
- {
- return view('user.dashboard');
- }
- public function login()
- {
- return view('user.login');
- }
- public function login_submit(Request $request)
- {
- $request->validate([
- 'email' => ['required', 'email'],
- 'password' => ['required'],
- ]);
- $check = $request->all();
- $data = [
- 'email' => $check['email'],
- 'password' => $check['password'],
- 'status' => 1,
- ];
- if(Auth::guard('web')->attempt($data)) {
- return redirect()->route('dashboard');
- } else {
- return redirect()->route('login')->with('error','The information you entered is incorrect! Please try again!');
- }
- }
- public function logout()
- {
- Auth::guard('web')->logout();
- return redirect()->route('login')->with('success','Logout is successful!');
- }
- public function register()
- {
- return view('user.register');
- }
- public function register_submit(Request $request)
- {
- $request->validate([
- 'name' => ['required'],
- 'email' => ['required', 'email', 'unique:users'],
- 'password' => ['required'],
- 'confirm_password' => ['required','same:password'],
- ]);
- $user = new User();
- $user->name = $request->name;
- $user->email = $request->email;
- $user->password = Hash::make($request->password);
- $token = hash('sha256',time());
- $user->token = $token;
- $user->save();
- $verification_link = url('register_verify/'.$token.'/'.$request->email);
- $subject = "Registration Verification";
- $message = "To complete registration, please click on the link below:<br>";
- $message .= "<a href='".$verification_link."'>Click Here</a>";
- \Mail::to($request->email)->send(new Websitemail($subject,$message));
- return redirect()->back()->with('success','Your registration is completed. Please check your email for verification. If you do not find the email in your inbox, please check your spam folder.');
- }
- public function register_verify($token,$email)
- {
- $user = User::where('token',$token)->where('email',$email)->first();
- if(!$user) {
- return redirect()->route('login');
- }
- $user->token = '';
- $user->status = 1;
- $user->update();
- return redirect()->route('login')->with('success', 'Your email is verified. You can login now.');
- }
- public function forget_password()
- {
- return view('user.forget-password');
- }
- public function forget_password_submit(Request $request)
- {
- $request->validate([
- 'email' => ['required', 'email'],
- ]);
- $user = User::where('email',$request->email)->first();
- if(!$user) {
- return redirect()->back()->with('error','Email is not found');
- }
- $token = hash('sha256',time());
- $user->token = $token;
- $user->update();
- $reset_link = url('reset-password/'.$token.'/'.$request->email);
- $subject = "Password Reset";
- $message = "To reset password, please click on the link below:<br>";
- $message .= "<a href='".$reset_link."'>Click Here</a>";
- \Mail::to($request->email)->send(new Websitemail($subject,$message));
- return redirect()->back()->with('success','We have sent a password reset link to your email. Please check your email. If you do not find the email in your inbox, please check your spam folder.');
- }
- public function reset_password($token,$email)
- {
- $user = User::where('email',$email)->where('token',$token)->first();
- if(!$user) {
- return redirect()->route('login')->with('error','Token or email is not correct');
- }
- return view('user.reset-password', compact('token','email'));
- }
- public function reset_password_submit(Request $request, $token, $email)
- {
- $request->validate([
- 'password' => ['required'],
- 'confirm_password' => ['required','same:password'],
- ]);
- $user = User::where('email',$request->email)->where('token',$request->token)->first();
- $user->password = Hash::make($request->password);
- $user->token = "";
- $user->update();
- return redirect()->route('login')->with('success','Password reset is successful. You can login now.');
- }
|