119 lines
3.3 KiB
PHP
119 lines
3.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Http\Requests\ChangePass;
|
||
|
use App\Http\Requests\LoginRequset;
|
||
|
use App\Http\Requests\UploadProfilePicRequest;
|
||
|
use App\Http\Requests\SignupRequest;
|
||
|
use App\Http\Requests\UpdateProfile;
|
||
|
|
||
|
use App\User;
|
||
|
use App\Order;
|
||
|
|
||
|
use Session;
|
||
|
|
||
|
class UserController extends MainController
|
||
|
{
|
||
|
function __construct(){
|
||
|
$this->middleware('signmid' , ['except' =>['uploadNewPic', 'changePic', 'orderedId','userOrderList','logOut' , 'profile' , 'postProfile' , 'changePass','postChangePass'] ]);
|
||
|
}
|
||
|
static public function getLogin(){
|
||
|
self::$data['title'] .= 'Log in';
|
||
|
return view('forms.login' , self::$data);
|
||
|
}
|
||
|
|
||
|
public function postLogin(LoginRequset $request){
|
||
|
|
||
|
$rt = !empty($request['rt']) ? $request['rt'] : '';
|
||
|
// dd($rt);
|
||
|
if (User::validate($request) ){
|
||
|
return redirect('' . $rt);
|
||
|
}else{
|
||
|
return view('forms.login' , self::$data) -> withErrors('Wrong Email / Password');
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public function getSignup(){
|
||
|
return view('forms.signup' , self::$data);
|
||
|
|
||
|
|
||
|
}
|
||
|
public function postSignup(SignupRequest $request){
|
||
|
User::save_new($request);
|
||
|
return redirect('');
|
||
|
}
|
||
|
|
||
|
public function logOut(){
|
||
|
// $name = Session::get('user_name');
|
||
|
Session::flush();
|
||
|
Session::flash('sm' , ' you have loged Out ! ');
|
||
|
return redirect('user/login');
|
||
|
}
|
||
|
|
||
|
public function profile(){
|
||
|
$user = User::getUserInfo();
|
||
|
self::$data['user_orders'] = count(Order::getUserOrders($user));
|
||
|
self::$data['user'] = $user;
|
||
|
self::$data['title'] .= 'Profile Page';
|
||
|
return view('user.profile' , self::$data);
|
||
|
}
|
||
|
|
||
|
public function postProfile(UpdateProfile $request){
|
||
|
User::updateUser($request);
|
||
|
$user = User::getUserInfo();
|
||
|
self::$data['user_orders'] = count(Order::getUserOrders($user));
|
||
|
self::$data['user'] = $user;
|
||
|
return view('user.profile' , self::$data);
|
||
|
}
|
||
|
public function changePass(){
|
||
|
return view('user.changePass' , self::$data);
|
||
|
}
|
||
|
|
||
|
public function postChangePass(ChangePass $request){
|
||
|
|
||
|
if (User::getPass($request)) {
|
||
|
$user = User::getUserInfo();
|
||
|
|
||
|
self::$data['user_orders'] = count(Order::getUserOrders($user));
|
||
|
$user = User::getUserInfo();
|
||
|
|
||
|
self::$data['user'] = $user;
|
||
|
return view('user.profile' , self::$data);
|
||
|
}else{
|
||
|
return view('user.changePass' , self::$data);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function userOrderList(){
|
||
|
$user = User::getUserInfo();
|
||
|
self::$data['user_orders'] = Order::getUserOrders($user);
|
||
|
self::$data['user'] = $user;
|
||
|
self::$data['title'] .= 'customer-orders';
|
||
|
return view('user.customer-orders' , self::$data);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public function orderedId($oid){
|
||
|
self::$data['order'] = Order::getOrder($oid);
|
||
|
self::$data['oid'] = $oid;
|
||
|
$user = self::$data['user'] = User::getUserInfo();
|
||
|
self::$data['user_orders'] = count(Order::getUserOrders($user));
|
||
|
return view('user.customer-order' , self::$data);
|
||
|
}
|
||
|
|
||
|
public function changePic($uid){
|
||
|
self::$data['user'] = User::find($uid)->toArray();
|
||
|
return view('user.changePic' , self::$data);
|
||
|
}
|
||
|
|
||
|
public function uploadNewPic(UploadProfilePicRequest $request , $uid){
|
||
|
User::update_Pic($request , $uid);
|
||
|
return redirect('user/profile');
|
||
|
}
|
||
|
|
||
|
}
|