public function update(Request $request, Response $response, array $args) { /** @var Users $users */ $users = $this->data(Users::class); $saltPass = $this->settings->get('salt_pwd'); $password = $request->getParsedBodyParam('password'); $validator = $this->validator->rule('required', ['oldpassword', 'password', 'repassword']); $validator->addRule('check_oldpassword', function ($field, $value, array $params) use($users, $saltPass) { $password = md5($saltPass . $value); $countPass = $users->count(function ($query) use($password) { $query->where('user_id', '=', $this->session->get('user_id'))->where('password', '=', $password); }); return $countPass > 0; }, 'Wrong! Please remember your old password'); $validator->rules(['check_oldpassword' => 'oldpassword', 'equals' => [['repassword', 'password']], 'lengthMin' => [['password', 6]]]); if (!$validator->validate()) { $this->addFormAlert('warning', 'Some of mandatory fields is empty!', $validator->errors()); return $response->withRedirect($this->router->pathFor('membership-account-password-edit')); } $users->update(['password' => $this->salt($password)], $this->session->get('user_id')); $this->addFormAlert('success', 'Password anda berhasil diubah! Selamat!'); return $response->withRedirect($this->router->pathFor('membership-account')); }
/** * Parses the POST request and creates the Product object * @param Request $request * @return Product */ protected function productFromCreateEditForm(Request $request) { $product = new Product(); $product->setId(intval($request->getParsedBodyParam('id', 0)))->setName($request->getParsedBodyParam('name', ''))->setDescription($request->getParsedBodyParam('description', '')); $tags = explode(',', $request->getParsedBodyParam('tags', '')); foreach ($tags as $tag) { $tag = trim($tag); // empty tag if (!$tag) { continue; } $product->addTag($tag); } return $product; }