public function postEdit($id, $name) { $validator = new Validation(); $validator->setRule('required', $name, null, 'Name'); if (!$validator->validate()) { Session::setError($validator->getErrors()); Redirect::back(); } $this->city->edit($id, $name); Session::setMessage('The city is edited'); Redirect::to(''); }
public function post($id, $content) { $validator = new Validation(); $validator->setRule('required', $content); if (!$validator->validate()) { Session::setError($validator->getErrors()); Redirect::back(); } if ($this->comment->add(Auth::getUserId(), $id, $content) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('Done'); Redirect::to('/product/' . $id); }
public function postAdd(PromotionModel $promotion) { $validator = new Validation(); $validator->setRule('required', $promotion->discount, null, 'discount'); $validator->setRule('required', $promotion->date, null, 'date'); $validator->setRule('date', $promotion->date, null, 'date'); if (!$validator->validate()) { Session::setError($validator->getErrors()[0]); Redirect::back(); } if ($this->promotion->add($promotion->discount, $promotion->date, $promotion->category_id == 0 ? null : $promotion->category_id, $promotion->product_id == 0 ? null : $promotion->product_id) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('done'); Redirect::to(''); }
public function editProfile(UserModel $user, $new_password) { $validator = new Validation(); $validator->setRule('required', $user->email); $validator->setRule('required', $user->password); $validator->setRule('email', $user->email); if (!$validator->validate()) { Redirect::back(); } if ($this->user->editUser(Auth::getUserId(), $user->email, $new_password, $user->password) !== 1) { Redirect::back(); } Redirect::to(''); }
public function postEdit($id, ProductModel $product) { $validator = new Validation(); $validator->setRule('required', $product->name, null, 'name'); $validator->setRule('required', $product->description, null, 'description'); $validator->setRule('required', $product->price, null, 'price'); $validator->setRule('required', $product->quantity, null, 'quantity'); $validator->setRule('required', $product->category_id, null, 'category'); $validator->setRule('numeric', $product->quantity, null, 'quantity'); $validator->setRule('numeric', $product->price, null, 'price'); if (!$validator->validate()) { Session::setError($validator->getErrors()[0]); Redirect::back(); } if ($this->product->edit($id, $product->name, $product->description, $product->price, $product->quantity, $product->category_id) !== 1) { Session::setError('something went wrong'); Redirect::back(); } Session::setMessage('done'); Redirect::to(''); }
public function editProfile(UserModel $user, $new_password) { $validator = new Validation(); $validator->setRule('required', $user->email, null, 'Email'); $validator->setRule('required', $user->password, null, 'Current Password'); $validator->setRule('email', $user->email, null, 'Email'); if (!$validator->validate()) { Session::setError($validator->getErrors()); Redirect::back(); } /* @var $user \Models\UserModel */ $userFromDb = $this->user->getUser(Auth::getUserId()); if (!Common::verifyPassword($user->password, $userFromDb->password)) { Session::setError('Current password is not correct'); Redirect::back(); } if ($this->user->editUser(Auth::getUserId(), $user->email, Common::hashPassword($new_password)) !== 1) { Session::setError('Something is wrong. Try again.'); Redirect::back(); } Session::setMessage('The profile is edited'); Redirect::to(''); }