Viewing file: AuthController.php (4.64 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Frontend; use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\ProductImage; use App\Models\ProductOption; use App\Models\ProductRelated; use App\Models\StoreProductOption; use App\User; use Illuminate\Http\Request; use App\Models\Banner; use App\Models\Category; use App\Models\Manufacturer; use App\Models\Language; use App\Models\Product; use App\Models\DOD; use DB; use Illuminate\Support\Facades\Hash; use Validator; use Auth; use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; use robertogallea\LaravelPython\Services\LaravelPython;
class AuthController extends Controller { public function __construct() { }
public function pythonTest(LaravelPython $service) { // $process = new Process(['python', 'laravel.py']); $result = $service->run('/laravel.py'); dd($result); // executes after the command finishes if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } echo $process->getOutput(); }
//view customer login public function customerGetRegister(Request $request) { return view('frontend.user.register'); }
//customer registration public function customerRegister(Request $request){
$validator = $request->validate([ 'firstName' => 'required|max:255', 'lastName' => 'required|max:255', 'signupemail'=> 'required|max:255', 'telephone'=> 'required', 'signuppassword'=> 'required|max:255', 'comfirmPassword'=> 'required|same:signuppassword' ],[ 'firstName' => 'First name is required', 'lastName' => 'Last name is required', 'signupemail' => 'Email address is required', 'telephone' => 'Mobile number is required', 'signuppassword' => 'Password is required', 'comfirmPassword' => 'Confirm password does not match' ]);
$customerArray = array( 'firstname' => $request->firstName, 'lastname' => $request->lastName, 'email' => $request->signupemail, 'telephone' => $request->telephone, 'password' => Hash::make($request->signuppassword), 'creation' => 'D' );
$customer = Customer::create($customerArray);
if($customer){ $data = array('email'=>$request->signupemail,'password'=>$request->signuppassword);
if (Auth::guard('customer')->attempt($data)) { $wishlistData = DB::table("wishlist")->where('customer_id',$customer->id)->pluck('product_id'); $cartCount = DB::table("cart")->where('customer_id',$customer->id)->sum('quantity'); return redirect(route('customer.getlogin'))->with('registerSuccess', "Success! Registration completed"); } else { return redirect()->back()->with('autherror','Unable to login')->withInput(); } } else{ return back()->with("registererror", "Alert! Failed to register"); } }
//view customer login public function viewcustomerLogin(Request $request) { return view('frontend.user.login'); }
//customer login public function customerLogin(Request $request) { $validator = $request->validate([ 'email'=> 'required|max:255', 'password'=> 'required|max:255' ],['email' => 'Email address is required','password' =>'Password is required']);
$customer = Customer::select('id','email','image','image','firstname','lastname','telephone','creation')->where('email',$request->email)->first(); if($customer) { $data = array('email'=>$request->email,'password'=>$request->password); if (Auth::guard('customer')->attempt($data)) { //update cart table DB::table('cart')->where('customer_id',$customer->id)->update(['session_id' =>session()->getId() ]); return redirect('/user-dashboard')->with('loginSuccess','Login Success'); } else { return redirect()->back()->with('autherror','Email/Password Wrong')->withInput(); } } else { return redirect()->back()->with('autherror','Customer not found')->withInput(); } }
//customer logout public function customerLogout() { Auth::guard('customer')->logout(); return redirect('/'); } }
|