Edit File: AuthController.php
<?php namespace App\Http\Controllers\StoresDashboard; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Http\Requests\StoreStoreRequest; use App\Http\Requests\DelegatesDashboard\CodeRequest; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; use App\Traits\GeneralTrait; use App\Rules\CheckCodeRule; use App\Traits\ApiTrait; use App\Traits\Uploadable; use App\Models\Setting; use App\Models\StoreTiming; use App\Models\Category; use App\Models\User; use App\Models\Country; use App\Models\Store; use App\Models\StoreCategory; use Session; use Validator; use Auth; use App\Jobs\NewJoinierRequestNotify; use App\Rules\ValidateEmailEnd; use Carbon\Carbon; class AuthController extends Controller { // use ApiTrait, GeneralTrait, Uploadable; public function get_register(){ Auth::logout(); $countries = Country::all(); return view('stores_dashboard.Auth.register',compact('countries')); } public function post_register(Request $request){ $validator = Validator::make($request->all(), [ 'name' => 'required|string|min:3|max:191', 'country_key' => 'required', // 'avatar' => 'required', 'phone' => ['required','min:9'], 'email' => ['required', 'email',new ValidateEmailEnd], // 'password' => 'required|confirmed|min:8', 'type' =>'nullable' ]); if ($validator->fails()) { return $this->requestFailsReturn($validator); } $number = $this->convert2english($request->phone); $phone = $this->phoneValidate($number); if($user = User::where('phone' , $phone)->where('country_key' , $request['country_key'])->first()) { Auth::login($user); $request['remember_token'] = Str::random(10); $request['phone'] = $phone; $request['status'] = 'pending'; $request['type'] = 'store'; $request['approve'] = 'pending'; $request['completed_info'] = 'false'; $user->update($request->except('password_confirmation', 'password')); $user->store->delete(); }else{ $request['remember_token'] = Str::random(10); $request['phone'] = $phone; $request['status'] = 'pending'; $request['type'] = 'store'; $request['approve'] = 'pending'; $request['completed_info'] = 'false'; $user= User::create($request->except('password_confirmation', 'password')); Auth::login($user); } $msg = route('stores_dashboard.get_store_register'); return response()->json([ 'key' => 'success', 'msg' => $msg ]); } public function get_account_activation(){ return view('stores_dashboard.Auth.activate_store'); } public function get_subcategories($id){ $category = Category::where('slug' , $id)->first(); $menus = Category::where('category_id' , $category->id)->get()->toArray(); return $this->dataReturn($menus); } #submit activate phone public function post_account_activation(CodeRequest $request) { $data=$request->validated(); $store = Auth::user(); $store->update([ 'status'=> 'active', 'code' =>NULL ]); $msg = route('stores_dashboard.get_success_page'); if ($store->approve == 'accept') { $msg = route('stores_dashboard.index'); }else{ $msg = route('stores_dashboard.get_success_page'); } return $this->dashboardSuccessReturn($msg); } public function get_store_register(){ $user = Auth::user(); $categories = Category::where('slug','!=','free_delivery')->where('category_id',null)->get(); return view('stores_dashboard.Auth.store_register',compact('categories','user')); } public function post_store_register(StoreStoreRequest $request){ // dd($request->all()); $user = Auth::user(); $data = $request->validated(); if ($request->has('icon')) { $data['icon'] = $this->uploadFile($request->icon, 'stores', true, 250, null); } if ($request->has('cover')) { $data['cover'] = $this->uploadFile($request->cover, 'stores', true, 250, null); } if ($request->has('commercial_image')) { $data['commercial_image'] = $this->uploadFile($request->commercial_image, 'stores', true, 250, null); } if ($request->has('iban_image')) { $data['iban_image'] = $this->uploadFile($request->iban_image, 'stores', true, 250, null); } $data['name'] = [ 'ar' => $data['name_ar'], 'en' => $data['name_en'], ]; $data['user_id'] = $user->id; $store = Store::create($data); if($store) { if ($request['category_id']) { foreach ($request['category_id'] as $id) { StoreCategory::create([ 'category_id' => $id, 'store_id' => $store->id, ]); } } if($request['days']){ foreach($request['days'] as $key=>$ex){ if($request['from'][$key] && $request['to'][$key]){ $timing = new StoreTiming(); $timing->day = $request['days'][$key]; $timing->from = $request['from'][$key]; $timing->to = $request['to'][$key]; if(Carbon::parse($timing->to) < Carbon::parse($timing->from)){ return response()->json(['key' => 'error',"msg" => 'يجب ان يكون توقيت الغلق بعد توقيت الفتح']); } $timing->store_id = $store->id; $timing->save(); } } } } $user->update(['completed_info' => 'true']); $user->sendVerificationCode(); dispatch(new NewJoinierRequestNotify($store , 'store')); $url = route('stores_dashboard.get_account_activation'); return response()->json([ 'key' => 'success', 'url' => $url ]); } public function get_login(){ Auth::logout(); $welcome_title = Session::has('lang') && Session::get('lang') == 'en' ? Setting::where('key','welcome_title_en')->first()->value:Setting::where('key','welcome_title_ar')->first()->value; $welcome_content = Session::has('lang') && Session::get('lang') == 'en' ? Setting::where('key','welcome_content_en')->first()->value:Setting::where('key','welcome_content_ar')->first()->value; return view('stores_dashboard.Auth.login',compact('welcome_title','welcome_content')); } public function post_login(Request $request){ $validator = Validator::make($request->all(), [ 'phone' => 'required|numeric', 'password' => 'required', ]); if ($validator->fails()) { $msg = implode(' , ',$validator->errors()->all()); return response()->json(['key'=>'fail','msg'=>$msg]); } $number = $this->convert2english($request->phone); $phone = $this->phoneValidate($number); if(Auth::attempt(['phone' => $phone, 'password' => $request->password])){ $user = Auth::user(); if ($user->type !== 'store') { $msg = trans('auth.wrong_credentials'); return response()->json([ 'key' => 'fail', 'msg' => $msg, ]); } $msg = route('stores_dashboard.index'); return response()->json([ 'key' => 'success', 'msg' => $msg ]); }else{ $msg = trans('auth.wrong_credentials'); return response()->json([ 'key' => 'fail', 'msg' => $msg ]); } } public function get_forget_password(){ return view('stores_dashboard.Auth.forget'); } public function post_forget_password(Request $request){ $validator = Validator::make($request->all(), [ 'phone' => 'required', ]); if ($validator->fails()) { return $this->requestFailsReturn($validator); } $number = $this->convert2english($request->phone); $phone = $this->phoneValidate($number); $user = User::where('phone', $phone)->first(); if (!$user) { $msg = trans('auth.user_not_found'); return $this->failMsg('User not Exists'); } $user->sendVerificationCode(); Session::put('forgotpassword',$user); $msg = trans('auth.activation_code_sent'); $url = route('stores_dashboard.get_reset_password'); return response()->json([ 'key' => 'success', 'url' => $url, 'msg' => $msg ]); return $this->successMsg($msg); } public function get_reset_password(){ if(!Session::has('forgotpassword')){ return redirect()->route('stores_dashboard.get_forget_password'); } return view('stores_dashboard.Auth.reset'); } public function reset_code_again(){ if(!Session::has('forgotpassword')){ return redirect()->route('stores_dashboard.get_forget_password'); } $user = Session::get('forgotpassword'); $user->sendVerificationCode(); return response()->json(['location' => route('stores_dashboard.get_reset_password') ,'key' => 'success', 'msg' => awtTrans('تم اعاده ارسال الكود بنجاح')]); } public function post_reset_password(Request $request){ if(!Session::has('forgotpassword')){ $msg = trans('auth.user_not_found'); $url = route('stores_dashboard.get_forget_password'); return response()->json([ 'key' => 'success', 'msg' => $msg , 'url' => $url ]); } $user = Session::get('forgotpassword'); $codeArr = $request['code']; $code = implode("", $codeArr); $validator = Validator::make($request->all(), [ 'password'=>'required|min:6', 'password_confirmation' => 'required|same:password', ]); if ($validator->fails()) { return $this->requestFailsReturn($validator); } if(!$code){ $msg = trans('auth.required_code'); return response()->json([ 'key' => 'fail', 'msg' => $msg ]); } if($user->code !== $code){ $msg = trans('auth.false_code'); return response()->json([ 'key' => 'fail', 'msg' => $msg ]); } $user->password = $request['password']; $user->save(); $msg = trans('auth.password_changed'); $url = route('stores_dashboard.get_login'); return response()->json([ 'key' => 'success', 'msg' => $msg , 'url' => $url ]); } public function get_success_page(){ return view('stores_dashboard.Auth.successfuly-sent'); } public function get_confirmation_page(){ $user = Auth::user(); if($user->store()){ $store=Store::where('store_id',$user->id)->first(); if($store->join_request=="true"){ return view('stores_dashboard.index'); }else{ return view('stores_dashboard.index'); } } return view('stores_dashboard.Auth.login'); } public function logout() { Auth::logout(); return redirect()->route('stores_dashboard.get_login'); } }
Back to File Manager