%PDF- %PDF-
Direktori : /home/silvzytp/crm-ind-code/app/Http/Controllers/Auth/ |
Current File : //home/silvzytp/crm-ind-code/app/Http/Controllers/Auth/AuthController.php |
<?php namespace App\Http\Controllers\Auth; use App\Models\User; use App\Mail\ForgotMail; use Illuminate\Http\Request; use Illuminate\Support\Facades\URL; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\DB; class AuthController extends Controller { public function logout(){ // activity log $data = [ 'user_id' => Auth::id(), 'type' => 'Logout', 'ip_address' => request()->ip(), 'date_time' => now() ]; $this->activities($data); Auth::logout(); return redirect()->route('login')->with('success','You have successfully signout.'); } public function forgotShowForm(){ return view('auth.forgot-email'); } public function forgotEmail(Request $request){ $request->validate([ 'email'=>['required','email'] ]); DB::beginTransaction(); $user = User::where('email', $request->email)->first(); if (!$user) { return back()->with('error','Failed! email is not registered.'); } try { // mail content $mailContent = ['name'=>$user->name,'reset_url'=>URL::temporarySignedRoute('forgot.email.password',now()->addHours(1),['id'=>$user->id,'email'=>$user->email])]; Mail::to($request->email)->later(now()->addSeconds(10), new ForgotMail($mailContent)); return back()->with('success','Password reset link has been sent to your email'); } catch (\Exception $e) { DB::rollBack(); return back()->with('success',$e->getMessage()); } } public function forgotPassword($id,$email){ $user = User::where(['id'=>$id,'email'=>$email])->firstOrFail(); return view('auth.forgot-password', compact('user')); } public function resetPassword(Request $request){ $this->validate($request, [ 'email' => 'required|email', 'password' => 'required|min:8|max:20|confirmed', ]); // valid user find $user = User::where(['id'=>$request->user_id,'email'=>$request->email])->first(); if ($user) { $user['password'] = Hash::make($request->password); $user->save(); return redirect('/')->with('success','Your password has been changed.'); } else{ return back()->with('error','Something went wrong.'); } } }