VaKeR CYBER ARMY
Logo of a company Server : Apache
System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
User : vapecompany ( 2719)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Frontend/Auth/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Frontend/Auth/LoginController.php
<?php

namespace App\Http\Controllers\Frontend\Auth;

use App\Http\Controllers\Controller;
use App\Models\Customer;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */
    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest:web')->except('logout');
    }

    function get_login()
    {
        return view('frontend.pages.login');
    }

    function register()
    {
        return view('frontend.pages.singup');
    }

    public function login(Request $request)
    {
        $request->validate([
            'email' => 'required',
            'password' => 'required|min:6',
        ]);
        if (Auth::attempt($request->only('email', 'password'))) {
            return redirect()->route('user.dashboard');
        } else {
            session()->flash('error', 'Incorrect Password Or Username !! Please Try Again');
            return redirect()->back()->withInput($request->only('email'));
        }
    }


    public function registerUser(Request $request)
    {
        $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'phone' => ['required', 'string', 'max:20', 'unique:users'],
            'password' => ['required', 'string', 'min:6', 'confirmed'],
        ]);

        $user = new User;
        $user->name = $request->name;
        $user->email = $request->email;
        $user->phone = $request->phone;
        $user->password = Hash::make($request->password);
        $user->is_admin = "0";
        $user->status = "1";
        $user->save();

        $customer =  new Customer;
        $customer->customer_name = $request->name;
        $customer->user_id = $user->user_id;
        $customer->customer_email = $request->email;
        $customer->customer_phone = $request->phone;
        $customer->customer_address = $request->address ?: '';
        $customer->customer_type_id = 5;
        $customer->customer_mobile = $request->phone;
        $customer->customer_website = $request->customer_website ?: '';
        $customer->division_id = $request->division ? $request->division : 0;
        $customer->district_id = $request->district ? $request->district : 0;
        $customer->area_id = $request->area ? $request->area : 0;
        $customer->region_id = $request->region ? $request->region : 0;
        $customer->status = 1;
        // $customer->created_by = auth()->user()->user_id;
        $customer->save();

        return redirect('/login');
    }

    /**
     * Log the user out of the application.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
     */
    public function logout(Request $request)
    {
        Auth::guard('web')->logout();

        $request->session()->invalidate();

        $request->session()->regenerateToken();

        return redirect()->back();
    }
}

VaKeR 2022