/** * @param static $form * @param mixed $data */ protected function handleSuccess($form, $data) { $user = $this->getUser(); $user->setExpiration('2 weeks'); if (!$data->remember) { $user->setExpiration('1 hour', $user::BROWSER_CLOSED); } try { $user->login($data->email, $data->password); } catch (AuthenticationException $e) { return $form->addError($e->getMessage()); } catch (\Exception $e) { return $form->addError('app.general.error'); } }
/** * @param static $form Form instance * @param mixed $data Submited data */ protected function handleSuccess($form, $data) { $user = new User($data->email, ...explode(' ', $data->name)); $user->changePassword($data->password); try { $this->entityManager->persist($user)->flush($user); } catch (UniqueConstraintViolationException $e) { return $form['email']->addError('user.auth.email-taken'); } catch (\Exception $e) { return $form->addError('app.general.error'); } }
/** * Convenience function to create a resource instance with error messages. * * @param $errors array * * @return static */ protected static function errorInit($version, $errors) { $obj = new static($version); foreach ($errors as $error) { $obj->addError($error); } return $obj; }
public static function throwException($error) { $self = new static(); $self->addError($error); throw $self; }
/** * Factory method for failed validation * * @param string $message * @param mixed ...$args Arguments to insert into the message * @return static */ public static function error($message, ...$args) { $validation = new static(); $validation->addError($message, ...$args); return $validation; }