class LockrLoginForm in Lockr 8.2
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\lockr\Form\LockrLoginForm
Expanded class hierarchy of LockrLoginForm
1 string reference to 'LockrLoginForm'
1 service uses LockrLoginForm
File
- src/
Form/ LockrLoginForm.php, line 23 - Contains Drupal\lockr\Form\LockrLoginForm.
Namespace
Drupal\lockr\FormView source
class LockrLoginForm extends FormBase {
/**
* Constructs a new LockrLoginForm.
*/
public function __construct(ConfigFactoryInterface $config, ClientFactory $client_factory, RequestStack $requests, EmailValidator $emailValidator) {
$this->config = $config;
$this->clientFactory = $client_factory;
$this->requests = $requests;
$this->emailValidator = $emailValidator;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('lockr.client_factory'), $container
->get('request_stack'), $container
->get('email.validator'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'lockr_login_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$site_client = $this->clientFactory
->getSiteClient();
try {
$status = $site_client
->exists();
} catch (LockrServerException $e) {
watchdog_exception('lockr', $e);
drupal_set_message('The Lockr service has returned an error. Please try again.', 'error');
return $form;
}
$exists = $status['exists'];
if ($exists) {
$form['registered'] = [
'#title' => $this
->t("You're already registered"),
'#prefix' => '<p>',
'#markup' => $this
->t("This site is already registered with the Lockr Key Management Service. There's nothing left for you do to here, your keys entered in the key settings are already protected. If you registered with the wrong account, you can click <a href=\"https://lockr.io/user/login\" target=\"_blank\">here</a> to go to Lockr and manage your sites."),
'#suffix' => '</p>',
];
return $form;
}
$default_email = $this->requests
->getCurrentRequest()
->get('email');
$form['email'] = [
'#type' => 'textfield',
'#title' => $this
->t('Email'),
'#required' => TRUE,
'#default_value' => $default_email,
'#description' => $this
->t('Enter your Lockr email.'),
];
$form['pass'] = [
'#type' => 'password',
'#title' => $this
->t('Password'),
'#required' => TRUE,
'#description' => $this
->t('Enter the password that accompanies your email.'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Log in'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$email = $form_state
->getValue('email');
if (!$this->emailValidator
->isValid($email)) {
$form_state
->setErrorByName('email', $this
->t('Please enter a valid email address.'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$email = $form_state
->getValue('email');
$pass = $form_state
->getValue('pass');
$name = $this->config
->get('system.site')
->get('name');
$site_client = $this->clientFactory
->getSiteClient();
try {
$site_client
->register($email, $pass, $name);
} catch (LockrClientException $e) {
if ($e->title === 'Partner mismatch') {
$msg = $this
->t("We didn't recognize your certificate, please ensure the provide path is a valid Lockr certificate.");
}
elseif ($e->title === 'Site exists') {
$msg = $this
->t('This site is already registered. If you are experiencing issues, please contact support@lockr.io.');
}
elseif ($e->title === 'Credentials invalid') {
$msg = $this
->t('The username and password did not match, please try again.');
}
else {
$msg = $this
->t('An unknown error occurred, please try again later.');
}
drupal_set_message($msg, 'error');
return;
} catch (LockrException $e) {
$msg = $this
->t('An unknown error occurred, please try again later.');
drupal_set_message($msg, 'error');
return;
}
drupal_set_message($this
->t("That's it! You're signed up with Lockr; your keys are now safe."));
$form_state
->setRedirect('entity.key.collection');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LockrLoginForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LockrLoginForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
LockrLoginForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LockrLoginForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LockrLoginForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
LockrLoginForm:: |
public | function | Constructs a new LockrLoginForm. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |