/** * Save role * * @param Illuminate\Http\Request $request * * @return response * * @throws \Exception */ public function save(Request $request) { if ($request->isMethod('POST')) { $edit = $request->has('id'); $role = $edit ? $this->_getRoleById($request->get('id')) : $this->role; $rules = $this->role->rules(); $messages = $this->role->messages(); if ($edit && str_equal($role->role, $request->get('role'))) { $rules = remove_rules($rules, ['role.unique:roles,role']); } $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return back()->withInput()->withErrors($validator, 'all'); } try { $role = $this->bind($role, $request->all()); if (!$edit) { $role->created_at = new \DateTime(); } $role->updated_at = new \DateTime(); $role->save(); } catch (Exception $ex) { throw new \Exception(_t('backend_common_opp') . $ex->getMessage()); } return redirect(route('backend_roles'))->with('success', _t('backend_common_saved')); } }
/** * Save product info * * @param Illuminate\Http\Request $request * * @return type */ public function ajaxSaveProduct(Request $request) { //Only accept ajax request if ($request->ajax() && $request->isMethod('POST')) { if (store() === null) { return pong(0, _t('not_found'), 404); } $store = store(); $productId = (int) $request->get('id'); if ($productId) { $product = $store->products->find($productId); } else { $product = new Product(); } if ($product === null) { return pong(0, _t('not_found'), 404); } $rules = $this->_product->getRules(); $messages = $this->_product->getMessages(); if ($productId) { $rules = remove_rules($rules, 'product_image_1'); } $validator = Validator::make($request->all(), $rules, $messages); $tempImages = [$request->get('product_image_1'), $request->get('product_image_2'), $request->get('product_image_3'), $request->get('product_image_4')]; if ($validator->fails()) { return pong(0, $validator->messages(), is_null($product) ? 404 : 403); } /** * 1. Copy product images from temporary folder to product folder. * 2. Delete old product image(s). * 3. Save product. */ try { // 1 $images = $this->_copyTempProductImages($tempImages); // 2 if ($productId) { $this->_deleteOldImages($images, $product->images); } // 3 $product->store_id = $store->id; $product->name = $request->get('name'); $product->price = $request->get('price'); $product->old_price = $request->get('old_price'); $product->description = $request->get('description'); $product->setImages($images); $product->save(); } catch (Exception $ex) { return pong(0, _t('opp'), 500); } return pong(1, ['messages' => _t('saved_info'), 'data' => ['id' => $product->id, 'name' => $product->name, 'price' => product_price($product->price), 'old_price' => product_price($product->old_price), 'image' => ($i = $product->toImage()->image_1) !== null ? product_image($i->medium) : '']]); } }
/** * User registering * * @param \Illuminate\Http\Request $request * * @return response * * @throws Exception */ public function register(Request $request) { if ($request->isMethod('POST')) { $rules = remove_rules($this->_user->getRules(), ['first_name', 'last_name']); $messages = $this->_user->getMessages(); $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return back()->withInput()->withErrors($validator, 'auth'); } $user = $this->bind($this->_user, $request->all()); try { $user->save(); } catch (Exception $ex) { throw new Exception(_t('opp')); } $credentials = ['email' => $request->get('email'), 'password' => $request->get('password')]; auth()->attempt($credentials); return redirect(route('front_home')); } return view('frontend::auth.register'); }
/** * Save post category * * @param Illuminate\Http\Request $request * * @return response * @throws \Exception */ public function save(Request $request) { if ($request->isMethod('POST')) { $edit = $request->has('id'); $postCategory = $edit ? $this->_getPostCategoryById($request->get('id')) : $this->postCategory; $rules = $this->postCategory->rules(); $messages = $this->postCategory->messages(); if ($edit && str_equal($postCategory->slug, $request->get('slug'))) { $rules = remove_rules($rules, ['slug.unique:post_categories,slug']); } $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return back()->withInput()->withErrors($validator, 'all'); } try { $postCategory = $this->bind($postCategory, $request->all()); $postCategory->save(); } catch (Exception $ex) { throw new \Exception(_t('backend_common_opp') . $ex->getMessage()); } return redirect(route('backend_post_categories'))->with('success', _t('backend_common_saved')); } }
/** * Remove one or many rules in a list of rules * * @param array $rules List of rules will be removed out * @param array|string $rulesRemove Rule to be found in $rules to remove * * @return array */ function remove_rules($rules, $rulesRemove) { //Remove list rules if (is_array($rulesRemove) && count($rulesRemove)) { foreach ($rulesRemove as $one) { $rules = remove_rules($rules, $one); } return $rules; } /** * Remove rule string * 1. If rule contains dot "." then remove rule after dot for rule name * before the dot. * 2. If rule doesn't contain dot then remove the rule name present * */ if (is_string($rulesRemove)) { if (str_contains($rulesRemove, '.')) { $ruleInField = explode('.', $rulesRemove); if (isset($rules[$ruleInField[0]])) { $ruleSplit = explode('|', $rules[$ruleInField[0]]); $ruleFlip = array_flip($ruleSplit); if (isset($ruleFlip[$ruleInField[1]])) { unset($ruleSplit[$ruleFlip[$ruleInField[1]]]); } //Remove the rule name if it contains no rule if (count($ruleSplit)) { $rules[$ruleInField[0]] = implode('|', $ruleSplit); } else { unset($rules[$ruleInField[0]]); } } } elseif (isset($rules[$rulesRemove])) { unset($rules[$rulesRemove]); } return $rules; } return $rules; }
/** * Save user * * @param Illuminate\Http\Request $request * * @return response * * @throws \Exception */ public function save(Request $request) { if ($request->isMethod('POST')) { $edit = $request->has('id'); $user = $edit ? $this->_getUserById($request->get('id')) : $this->user; $rules = $this->user->rules(); $messages = $this->user->messages(); if ($edit && str_equal($user->username, $request->get('username'))) { $rules = remove_rules($rules, ['username.unique:users,username']); } if ($edit && str_equal($user->email, $request->get('email'))) { $rules = remove_rules($rules, ['email.unique:users,email']); } if ($edit) { $rules = remove_rules($rules, ['password.required']); } $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return back()->withInput()->withErrors($validator, 'all'); } try { $except = []; if ($request->password === '') { $except = ['password']; } $user = $this->bind($user, $request->all(), $except); if (!$edit) { $user->created_at = new \DateTime(); } $user->updated_at = new \DateTime(); //Upload avatar if ($request->hasFile('avatar')) { $avatarPath = config('back.avatar_path'); $file = $request->file('avatar'); $filename = new FileName($avatarPath, $file->getClientOriginalExtension()); $filename->avatar()->generate(); $filename->setPrefix(_const('AVATAR_PREFIX')); $filename->avatar()->group($this->_getAvatarGroup(), false); $upload = new Upload($file); $upload->setDirectory($avatarPath)->setName($filename->getName())->move(); $image = new Image($avatarPath . $upload->getName()); $image->setDirectory($avatarPath)->resizeGroup($filename->getGroup()); delete_file($avatarPath . $upload->getName()); $resizes = $image->getResizes(); $user->avatar = $resizes['small']; } $user->save(); } catch (Exception $ex) { throw new \Exception(_t('backend_common_opp') . $ex->getMessage()); } return redirect(route('backend_users'))->with('success', _t('backend_common_saved')); } }
public function ajaxSaveStoreInfo(Request $request) { //Only accept AJAX request if ($request->ajax() && $request->isMethod('POST')) { $user = user(); if (($us = $user->store) === null) { $store = $this->store; } else { $store = store(); } $rules = $store->getRules(); if ($us === null) { $rules = remove_rules($rules, 'slug.required'); } if (str_equal($store->slug, $request->get('slug'))) { $rules = remove_rules($rules, 'slug.unique:stores,slug'); } $messages = $store->getMessages(); $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return pong(0, $validator->messages(), 403); } try { $store->user_id = $user->id; $store->name = $request->get('name'); $store->category_id = $request->get('category_id'); $store->street = $request->get('street'); $store->city_id = $request->get('city_id'); $store->district_id = $request->get('district_id'); $store->ward_id = $request->get('ward_id'); $store->phone_number = $request->get('phone_number'); if ($user->store === null) { $slug = str_slug($store->name); if ($store->findStoreBySlug($slug)) { $store->slug = $slug . '-' . $user->id; } else { $store->slug = $slug; } } else { $store->slug = str_replace('_', '-', $request->get('slug')); } if ($store->save()) { $productPath = config('front.product_path') . $store->id; $oldmask = umask(0); if (!file_exists($productPath)) { mkdir($productPath, 0777); umask($oldmask); } } } catch (Exception $ex) { $validator->errors()->add('name', _t('opp')); return pong(0, $validator->messages(), 500); } return pong(1, _t('saved_info')); } }
/** * Change basic info * * @param Illuminate\Http\Request $request * * @return JSON */ public function ajaxSaveBasicInfo(Request $request) { //Only accept ajax request. if ($request->ajax()) { $rules = remove_rules($this->_user->getRules(), 'password.min:6'); $messages = $this->_user->getMessages(); $user = user(); $dbUname = $user->user_name; $dbEmail = $user->email; $dbPass = $user->password; $uname = $request->get('user_name'); $email = $request->get('email'); $fname = $request->get('first_name'); $lname = $request->get('last_name'); $password = $request->get('password'); $checkPass = false; if (str_equal($dbUname, $uname)) { $rules = remove_rules($rules, 'user_name.unique:users,user_name'); } else { $checkPass = true; } if (str_equal($dbEmail, $email)) { $rules = remove_rules($rules, 'email.unique:users,email'); } else { $checkPass = true; } if (!$checkPass) { $rules = remove_rules($rules, 'password'); } $validator = Validator::make($request->all(), $rules, $messages); if ($checkPass && !Hash::check($password, $dbPass)) { $validator->after(function ($validator) { $validator->errors()->add('password', _t('pass_incorrect')); }); } if ($validator->fails()) { return pong(0, $validator->messages(), 403); } try { $user->user_name = $uname; $user->email = $email; $user->first_name = $fname; $user->last_name = $lname; $user->save(); } catch (Exception $ex) { return pong(0, _t('opp'), 500); } return pong(1, _t('saved_info')); } }
echo basename(__FILE__) . "::framework/class.unix.inc\n"; } include_once dirname(__FILE__) . '/framework/class.unix.inc'; if ($GLOBALS["DEBUG_INCLUDES"]) { echo basename(__FILE__) . "::frame.class.inc\n"; } include_once dirname(__FILE__) . '/framework/frame.class.inc'; include_once dirname(__FILE__) . '/ressources/class.mysql.inc'; include_once dirname(__FILE__) . '/ressources/class.squid.acls.inc'; include_once dirname(__FILE__) . '/ressources/class.squid.bandwith.inc'; if ($argv[1] == "--emergency") { emergency_remove(); exit; } if ($argv[1] == "--remove") { remove_rules(); exit; } if ($argv[1] == "--frame") { $GLOBALS["RSQUID"] = 1; } Paranoid(); function build_progress_paranoid($text, $pourc) { $echotext = $text; $echotext = str_replace("{reconfigure}", "Reconfigure", $echotext); echo "Starting......: " . date("H:i:s") . " {$pourc}% {$echotext}\n"; $cachefile = "/usr/share/artica-postfix/ressources/logs/squid.paranoid.progress"; $array["POURC"] = $pourc; $array["TEXT"] = $text; @file_put_contents($cachefile, serialize($array));