소스 검색

materio expo added email validation, file without email redirect to form

bach 2 년 전
부모
커밋
2ffda1e0b2

+ 12 - 4
web/modules/custom/materio_expo/src/Controller/QRController.php

@@ -24,6 +24,7 @@ class QRController extends ControllerBase {
     $session = \Drupal::request()->getSession();
     $alreadysetemail = $session->get('materio_expo_email');
     if($alreadysetemail){
+
       //* get node from ref
       $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
       $query = $entity_storage->getQuery()
@@ -39,12 +40,19 @@ class QRController extends ControllerBase {
 
       //* redirect to file
       return new RedirectResponse($file->createFileUrl());
+      // return [
+      //   '#type' => 'markup',
+      //   '#markup' => $this->t("Error, email not provided"),
+      // ];
+
 
     } else {
-      return [
-        '#type' => 'markup',
-        '#markup' => $this->t("Error, email not provided"),
-      ];
+      // return [
+      //   '#type' => 'markup',
+      //   '#markup' => $this->t("Error, email not provided"),
+      // ];
+      $url = Url::fromRoute('materio_expo.get_email', ['ref'=>$ref]);
+      return new RedirectResponse($url->toString());
     }
   }
 

+ 34 - 0
web/modules/custom/materio_expo/src/Form/GetEmail.php

@@ -7,12 +7,38 @@ use Drupal\Core\Form\FormStateInterface;
 // use Symfony\Component\HttpFoundation\Cookie;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Drupal\Core\Url;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Egulias\EmailValidator\EmailValidator;
 
 /**
  * Class GetEmail.
  */
 class GetEmail extends FormBase {
 
+ /**
+   * The email validator.
+   *
+   * @var \Egulias\EmailValidator\EmailValidator
+   */
+  protected $emailValidator;
+
+  /**
+   * Constructs 
+   *
+   * @param \Egulias\EmailValidator\EmailValidator $email_validator
+   *   The email validator.
+   */
+  public function __construct(EmailValidator $email_validator) {
+    $this->emailValidator = $email_validator;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static($container->get('email.validator'));
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -80,6 +106,14 @@ class GetEmail extends FormBase {
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
     parent::validateForm($form, $form_state);
+    $values = $form_state->getValues();
+    if (!$this->emailValidator->isValid($values['email'])) {
+      $form_state->setErrorByName('email',
+        $this->t('%email is an invalid email address.', [
+          '%email' => $values['email'],
+        ])
+      );
+    }
   }
 
   /**

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.css


BIN
web/themes/custom/materiotheme/assets/dist/main.css.gz


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 1
web/themes/custom/materiotheme/assets/dist/report.html


+ 4 - 0
web/themes/custom/materiotheme/assets/styles/main.scss

@@ -3002,3 +3002,7 @@ img.lazy{
     // background-color: red;
   }
 }
+
+#better-messages-default{
+  max-width: 90%;
+}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.