public function postStore()
 {
     $redirect_url = 'admin/orders/create';
     $validation = $this->validateStoreInputs(Input::all());
     if ($validation->fails()) {
         return redirect($redirect_url)->withErrors($validation)->withInput();
     }
     $transaction_id = Input::get('transaction_id');
     $payment_status = Input::get('payment_status');
     $paid = Input::get('paid');
     $email = Input::get('email');
     // Check user first
     $user = User::where('email', $email)->first();
     if ($user == null) {
         // No such user
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('userError', "The user may have been deleted. Please try again.");
         return redirect($redirect_url)->withErrors($errors)->withInput();
     }
     $apply_to_models = array();
     // Save products to order
     $selected_products = Input::get('selected_products');
     $apply_to_models = array_merge($apply_to_models, $this->addModelToArray($selected_products, new Product()));
     // Save bundles to order
     $selected_bundles = Input::get('selected_bundles');
     $apply_to_models = array_merge($apply_to_models, $this->addModelToArray($selected_bundles, new Bundle()));
     // Save pricelists to order
     $pricelists = Input::get('pricelist_id');
     $apply_to_models = array_merge($apply_to_models, $this->addModelToArraySimpleMode($pricelists, new Pricelist()));
     // No product/bundle to add
     if (count($apply_to_models) == 0) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('productError', "The items selected may have been deleted. Please try again.");
         return redirect($redirect_url)->withErrors($errors)->withInput();
     }
     $new_order = new Order();
     $new_order->user_id = $user->id;
     $new_order->paid = $paid;
     $new_order->transaction_id = $transaction_id;
     $new_order->payment_status = $payment_status;
     $new_order->save();
     // Save the products/bundles
     foreach ($apply_to_models as $apply_to_model) {
         $apply_to_model->orders()->save($new_order);
     }
     // Save coupons to order
     $coupons = Input::get('coupon_id');
     $errors = $this->addCouponToOrder($coupons, $new_order);
     if ($errors) {
         return redirect($this->pageRoute)->withErrors($errors);
     }
     return redirect($this->pageRoute);
 }
 public function run()
 {
     DB::table('users')->delete();
     DB::table('groups')->delete();
     DB::table('users_groups')->delete();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = \Hash::make("admin");
     $user->first_name = 'System';
     $user->last_name = 'Admin';
     $user->activated = 1;
     $user->save();
     $admin_group = new Group();
     $admin_group->name = 'Admin';
     $admin_group->permissions = json_encode(array('admin.view' => 1, 'admin.create' => 1, 'admin.delete' => 1, 'admin.update' => 1));
     $admin_group->save();
     $user_group = new Group();
     $user_group->name = 'User';
     $user_group->permissions = json_encode(array('admin.view' => 0, 'admin.create' => 0, 'admin.delete' => 0, 'admin.update' => 0));
     $user_group->save();
     // Assign user permissions
     $user->groups()->save($admin_group);
 }
 public function postStore()
 {
     $sid = \Input::get('id');
     $rules = array('pricelist_id' => 'required|integer', 'transaction_id' => 'required', 'payment_status' => 'required', 'paid' => 'numeric', 'email' => 'required|email');
     $validation = \Validator::make(\Input::all(), $rules);
     $redirect_url = isset($sid) ? 'admin/purchases/edit/' . $sid : 'admin/purchases/create';
     if ($validation->fails()) {
         return redirect($redirect_url)->withErrors($validation)->withInput();
     }
     $pricelist_id = \Input::get('pricelist_id');
     $transaction_id = \Input::get('transaction_id');
     $payment_status = \Input::get('payment_status');
     $paid = \Input::get('paid');
     $email = \Input::get('email');
     $pricelist = Pricelist::find($pricelist_id);
     // No such pricelist
     if ($pricelist == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('pricelistError', "The Module/Membership may have been deleted. Please try again.");
         return redirect($redirect_url)->withErrors($errors)->withInput();
     }
     $user = User::where('email', $email)->first();
     if ($user == null) {
         // No such user
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('userError', "The user may have been deleted. Please try again.");
         return redirect($redirect_url)->withErrors($errors)->withInput();
     }
     // Check if user_pricelist already exist
     $existing = UserPricelist::join('order_pricelist', 'orders.id', '=', 'order_pricelist.id')->where('orders.user_id', $user->id)->where('order_pricelist.pricelist_id', $pricelist->id)->count();
     if ($existing > 0) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('userpricelistError', $email . " has already purchased " . $pricelist->module->name . " (" . $pricelist->membership->name . ").");
         return redirect($redirect_url)->withErrors($errors)->withInput();
     }
     $new_purchase = new UserPricelist();
     $new_purchase->user_id = $user->id;
     $new_purchase->pricelist_id = $pricelist->id;
     $new_purchase->paid = $paid;
     $new_purchase->transaction_id = $transaction_id;
     $new_purchase->payment_status = $payment_status;
     $new_purchase->save();
     return redirect('admin/purchases');
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return view('redminportal::users.notauthorized');
         } else {
             return redirect()->guest('login');
         }
     }
     $email = Auth::user()->email;
     // Check if user is in Admin group
     $user = User::where('email', $email)->first();
     if ($user != null) {
         $group = $user->groups()->where('name', 'Admin')->first();
         if ($group != null) {
             // Save login time
             $user->last_login = date('Y-m-d H:i:s');
             $user->save();
             return $next($request);
         }
     }
     return redirect('login/unauthorized');
 }
Exemple #5
0
 public function getAll()
 {
     $list = User::lists('email');
     return response()->json($list);
 }
 public function getSort($sortBy = 'email', $orderBy = 'asc')
 {
     $inputs = array('sortBy' => $sortBy, 'orderBy' => $orderBy);
     $rules = array('sortBy' => 'required|regex:/^[a-zA-Z0-9 _-]*$/', 'orderBy' => 'required|regex:/^[a-zA-Z0-9 _-]*$/');
     $validation = \Validator::make($inputs, $rules);
     if ($validation->fails()) {
         return redirect('admin/users')->withErrors($validation);
     }
     if ($orderBy != 'asc' && $orderBy != 'desc') {
         $orderBy = 'asc';
     }
     if ($sortBy == 'group') {
         $users = User::LeftJoin('users_groups', 'users_groups.user_id', '=', 'users.id')->LeftJoin('groups', 'groups.id', '=', 'users_groups.group_id')->select('users.*', 'groups.name')->orderBy('groups.name', $orderBy)->paginate(20);
     } else {
         $users = User::orderBy($sortBy, $orderBy)->paginate(20);
     }
     $data = array('sortBy' => $sortBy, 'orderBy' => $orderBy, 'users' => $users);
     return view('redminportal::users/view', $data);
 }
 public function getDeactivate($sid)
 {
     $this_user = Auth::user();
     if ($this_user->id == $sid) {
         $errors = new MessageBag();
         $errors->add('editError', Lang::get('redminportal::messages.user_error_deactivate_own_account'));
         return redirect('/admin/users')->withErrors($errors);
     }
     $user = User::find($sid);
     if ($user == null) {
         $errors = new MessageBag();
         $errors->add('editError', Lang::get('redminportal::messages.user_error_user_not_found'));
         return redirect('/admin/users')->withErrors($errors);
     }
     // Deactivate the user
     $user->activated = false;
     $user->save();
     return redirect()->back();
 }