/** * Validate data * * @param array $data * @return array */ public function validate(array $data) { $this->validator->validate($data); return $this->validator->errors; }
public function registerPost(Request $request, Response $response, $args) { $email = Input::post('email'); $username = Input::post('username'); $password = Input::post('password'); $passwordConfirm = Input::post('password_confirm'); $v = new Validator(new User()); $v->validate(['email' => [$email, 'required|email|uniqueEmail'], 'username' => [$username, 'required|alnumDash|max(20)|uniqueUsername'], 'password' => [$password, 'required|min(6)'], 'password_confirm' => [$passwordConfirm, 'required|matches(password)']]); if ($v->passes()) { $user = new User(); $user->email = $email; $user->username = $username; $user->password = $this->hash->password($password); $user->group_id = 3; $user->save(); $flash = "You have been registered."; } else { $flash = "registration failed."; } $this->view->render($response, 'register.twig', ['errors' => $v->errors(), 'flash' => $flash, 'request' => $request]); return $response; }