Browse Source

handeled login or register from a modal, YES git status

Bachir Soussi Chiadmi 4 years ago
parent
commit
d5a6194727

+ 1 - 0
composer.json

@@ -37,6 +37,7 @@
         "drupal/core": "^8.7.1",
         "drupal/entity_clone": "^1.0",
         "drupal/error_log": "^1.0",
+        "drupal/field_permissions": "^1.0",
         "drupal/genpass": "1.x-dev",
         "drupal/image_delta_formatter": "1.x-dev",
         "drupal/jsonapi_extras": "^3.7",

+ 62 - 2
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "bee8de31ae3bb4fa7aa201097983403f",
+    "content-hash": "e30f4a9dd3ad6f9179b3b52f60f7791b",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -6495,6 +6495,66 @@
                 "source": "https://git.drupalcode.org/project/field_group"
             }
         },
+        {
+            "name": "drupal/field_permissions",
+            "version": "1.0.0-rc2",
+            "source": {
+                "type": "git",
+                "url": "https://git.drupalcode.org/project/field_permissions.git",
+                "reference": "8.x-1.0-rc2"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://ftp.drupal.org/files/projects/field_permissions-8.x-1.0-rc2.zip",
+                "reference": "8.x-1.0-rc2",
+                "shasum": "bbc0d4215b24f2613a02a365a22f2039ebcea421"
+            },
+            "require": {
+                "drupal/core": "~8.0"
+            },
+            "type": "drupal-module",
+            "extra": {
+                "branch-alias": {
+                    "dev-1.x": "1.x-dev"
+                },
+                "drupal": {
+                    "version": "8.x-1.0-rc2",
+                    "datestamp": "1545332280",
+                    "security-coverage": {
+                        "status": "not-covered",
+                        "message": "RC releases are not covered by Drupal security advisories."
+                    }
+                }
+            },
+            "notification-url": "https://packages.drupal.org/8/downloads",
+            "license": [
+                "GPL-2.0+"
+            ],
+            "authors": [
+                {
+                    "name": "RobLoach",
+                    "homepage": "https://www.drupal.org/user/61114"
+                },
+                {
+                    "name": "jhedstrom",
+                    "homepage": "https://www.drupal.org/user/208732"
+                },
+                {
+                    "name": "mariacha1",
+                    "homepage": "https://www.drupal.org/user/2210776"
+                },
+                {
+                    "name": "markus_petrux",
+                    "homepage": "https://www.drupal.org/user/39593"
+                }
+            ],
+            "description": "The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.",
+            "homepage": "https://www.drupal.org/project/field_permissions",
+            "support": {
+                "source": "https://git.drupalcode.org/project/field_permissions",
+                "issues": "https://www.drupal.org/project/issues/field_permissions"
+            }
+        },
         {
             "name": "drupal/file_mdm",
             "version": "1.1.0",
@@ -15831,7 +15891,7 @@
             "version": "8.3.5",
             "source": {
                 "type": "git",
-                "url": "https://git.drupal.org/project/coder.git",
+                "url": "https://git.drupalcode.org/project/coder.git",
                 "reference": "35277fc8675b6a2cbb194f8880145a9c85c845c4"
             },
             "require": {

+ 1 - 1
config/sync/contact.settings.yml

@@ -2,6 +2,6 @@ default_form: feedback
 flood:
   limit: 5
   interval: 3600
-user_default_enabled: true
+user_default_enabled: false
 _core:
   default_config_hash: U69DBeuvXuNVOC15rVNaBjDPK2fWFbo9v4takdYSSO8

+ 7 - 8
config/sync/core.entity_form_display.user.user.default.yml

@@ -20,11 +20,6 @@ content:
     region: content
     settings: {  }
     third_party_settings: {  }
-  contact:
-    weight: 8
-    region: content
-    settings: {  }
-    third_party_settings: {  }
   field_company:
     weight: 1
     settings:
@@ -58,12 +53,12 @@ content:
     type: entity_reference_autocomplete
     region: content
   language:
-    weight: 5
+    weight: 6
     region: content
     settings: {  }
     third_party_settings: {  }
   matomo:
-    weight: 6
+    weight: 7
     region: content
     settings: {  }
     third_party_settings: {  }
@@ -75,9 +70,13 @@ content:
     third_party_settings: {  }
   simplenews:
     weight: 5
+    region: content
     settings: {  }
     third_party_settings: {  }
-    region: content
 hidden:
   commerce_remote_id: true
+  contact: true
+  contact_company_profiles: true
+  customer_profiles: true
   langcode: true
+  member_profiles: true

+ 43 - 0
config/sync/core.entity_form_display.user.user.modal.yml

@@ -0,0 +1,43 @@
+uuid: 752dc176-50c8-47d0-8a20-c66e6210e8c9
+langcode: en
+status: true
+dependencies:
+  config:
+    - core.entity_form_mode.user.modal
+    - field.field.user.user.commerce_remote_id
+    - field.field.user.user.field_company
+    - field.field.user.user.field_member_type
+    - field.field.user.user.field_memo
+    - field.field.user.user.field_showroom
+  module:
+    - user
+id: user.user.modal
+targetEntityType: user
+bundle: user
+mode: modal
+content:
+  account:
+    weight: 0
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+  path:
+    type: path
+    weight: 7
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+hidden:
+  commerce_remote_id: true
+  contact: true
+  contact_company_profiles: true
+  customer_profiles: true
+  field_company: true
+  field_member_type: true
+  field_memo: true
+  field_showroom: true
+  langcode: true
+  language: true
+  matomo: true
+  member_profiles: true
+  simplenews: true

+ 83 - 0
config/sync/core.entity_form_display.user.user.register.yml

@@ -0,0 +1,83 @@
+uuid: 260badeb-b09e-4f68-8fae-2a64784dae59
+langcode: en
+status: true
+dependencies:
+  config:
+    - core.entity_form_mode.user.register
+    - field.field.user.user.commerce_remote_id
+    - field.field.user.user.field_company
+    - field.field.user.user.field_member_type
+    - field.field.user.user.field_memo
+    - field.field.user.user.field_showroom
+  module:
+    - user
+id: user.user.register
+targetEntityType: user
+bundle: user
+mode: register
+content:
+  account:
+    weight: 0
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+  field_company:
+    weight: 1
+    settings:
+      match_operator: CONTAINS
+      size: 60
+      placeholder: ''
+    third_party_settings: {  }
+    type: entity_reference_autocomplete
+    region: content
+  field_member_type:
+    weight: 4
+    settings: {  }
+    third_party_settings: {  }
+    type: options_select
+    region: content
+  field_memo:
+    weight: 3
+    settings:
+      rows: 5
+      placeholder: ''
+    third_party_settings: {  }
+    type: string_textarea
+    region: content
+  field_showroom:
+    weight: 2
+    settings:
+      match_operator: CONTAINS
+      size: 60
+      placeholder: ''
+    third_party_settings: {  }
+    type: entity_reference_autocomplete
+    region: content
+  language:
+    weight: 6
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+  matomo:
+    weight: 7
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+  path:
+    type: path
+    weight: 7
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+  simplenews:
+    weight: 5
+    region: content
+    settings: {  }
+    third_party_settings: {  }
+hidden:
+  commerce_remote_id: true
+  contact: true
+  contact_company_profiles: true
+  customer_profiles: true
+  langcode: true
+  member_profiles: true

+ 10 - 0
config/sync/core.entity_form_mode.user.modal.yml

@@ -0,0 +1,10 @@
+uuid: b87de49b-2838-4fdc-b361-2d2b8cb9b52c
+langcode: en
+status: true
+dependencies:
+  module:
+    - user
+id: user.modal
+label: Modal
+targetEntityType: user
+cache: true

+ 1 - 0
config/sync/core.extension.yml

@@ -68,6 +68,7 @@ module:
   error_log: 0
   field: 0
   field_group: 0
+  field_permissions: 0
   field_ui: 0
   file: 0
   filter: 0

+ 4 - 0
config/sync/field.storage.user.field_company.yml

@@ -3,8 +3,12 @@ langcode: en
 status: true
 dependencies:
   module:
+    - field_permissions
     - taxonomy
     - user
+third_party_settings:
+  field_permissions:
+    permission_type: custom
 id: user.field_company
 field_name: field_company
 entity_type: user

+ 4 - 0
config/sync/field.storage.user.field_member_type.yml

@@ -3,8 +3,12 @@ langcode: en
 status: true
 dependencies:
   module:
+    - field_permissions
     - options
     - user
+third_party_settings:
+  field_permissions:
+    permission_type: custom
 id: user.field_member_type
 field_name: field_member_type
 entity_type: user

+ 4 - 0
config/sync/field.storage.user.field_memo.yml

@@ -3,7 +3,11 @@ langcode: en
 status: true
 dependencies:
   module:
+    - field_permissions
     - user
+third_party_settings:
+  field_permissions:
+    permission_type: custom
 id: user.field_memo
 field_name: field_memo
 entity_type: user

+ 4 - 0
config/sync/field.storage.user.field_showroom.yml

@@ -3,8 +3,12 @@ langcode: en
 status: true
 dependencies:
   module:
+    - field_permissions
     - taxonomy
     - user
+third_party_settings:
+  field_permissions:
+    permission_type: custom
 id: user.field_showroom
 field_name: field_showroom
 entity_type: user

+ 1 - 1
config/sync/genpass.settings.yml

@@ -1,7 +1,7 @@
 genpass_length: 12
 genpass_algorithm: user
 genpass_entropy: 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!#$%&*+-.?@^_'
-genpass_mode: 1
+genpass_mode: 2
 genpass_display: 3
 _core:
   default_config_hash: HNSTwPQM5lvXFeH4cVlcB2gZFJ5S--Nbmfj7651HK24

+ 4 - 0
config/sync/user.role.adherent.yml

@@ -9,6 +9,10 @@ is_admin: null
 permissions:
   - 'access materio search'
   - 'create member profile'
+  - 'update own commerce_license'
   - 'update own member profile'
   - 'use jsonrpc services'
+  - 'view materio_order_type commerce_order'
+  - 'view own commerce_license'
   - 'view own member profile'
+  - 'view recurring commerce_order'

+ 14 - 0
config/sync/user.role.admin.yml

@@ -37,6 +37,10 @@ permissions:
   - 'create default workflow_transition'
   - 'create enregistrement content'
   - 'create evenement content'
+  - 'create field_company'
+  - 'create field_member_type'
+  - 'create field_memo'
+  - 'create field_showroom'
   - 'create generique workflow_transition'
   - 'create materiau content'
   - 'create materio_order_type commerce_order'
@@ -75,6 +79,10 @@ permissions:
   - 'edit any simplenews_issue content'
   - 'edit any static content'
   - 'edit any thematique content'
+  - 'edit field_company'
+  - 'edit field_member_type'
+  - 'edit field_memo'
+  - 'edit field_showroom'
   - 'edit own enregistrement content'
   - 'edit terms in collectionneurs'
   - 'edit terms in company'
@@ -136,14 +144,20 @@ permissions:
   - 'update materio_order_type commerce_order'
   - 'use jsonrpc services'
   - 'use text format wysiwyg'
+  - 'view all login histories'
   - 'view any commerce_license'
   - 'view any contact_company profile'
   - 'view any member profile'
   - 'view article revisions'
   - 'view autre_son revisions'
+  - 'view commerce_promotion'
   - 'view contact_company profile'
   - 'view enregistrement revisions'
   - 'view evenement revisions'
+  - 'view field_company'
+  - 'view field_member_type'
+  - 'view field_memo'
+  - 'view field_showroom'
   - 'view frontpage revisions'
   - 'view materiau revisions'
   - 'view materio_order_type commerce_order'

+ 2 - 0
config/sync/user.role.anonymous.yml

@@ -14,6 +14,7 @@ permissions:
   - 'access devel information'
   - 'access kint'
   - 'access synonyms entity autocomplete'
+  - 'access webprofiler'
   - 'create corpus_documents workflow_transition'
   - 'create defalut workflow_transition'
   - 'create default workflow_transition'
@@ -28,3 +29,4 @@ permissions:
   - 'view commerce_product'
   - 'view published fil entities'
   - 'view search api pages'
+  - 'view webprofiler toolbar'

+ 2 - 0
config/sync/user.role.authenticated.yml

@@ -15,6 +15,7 @@ permissions:
   - 'access kint'
   - 'access synonyms entity autocomplete'
   - 'access user profiles'
+  - 'access webprofiler'
   - 'add composition entities'
   - 'add fil entities'
   - 'create corpus_documents workflow_transition'
@@ -44,3 +45,4 @@ permissions:
   - 'view published composition entities'
   - 'view published fil entities'
   - 'view search api pages'
+  - 'view webprofiler toolbar'

+ 66 - 0
web/modules/custom/materio_user/materio_user.module

@@ -30,6 +30,67 @@ function materio_user_form_user_login_form_alter(&$form, FormStateInterface $for
 
 }
 
+function materio_user_form_user_modal_form_alter(&$form, FormStateInterface $form_state, $form_id) {
+  // Drupal::logger('materio_user')->notice(print_r($form['mail'], true));
+  // ksm($form);
+  $form['account']['mail']['#attributes'] = array(
+    "v-model" => "mail",
+    "@keyup.enter" => "register",
+    "placeholder" => $form['account']['mail']['#title'],
+    "title" => $form['account']['mail']['#description']
+  );
+
+  // https://drupal.stackexchange.com/a/217112
+  // Get default process function array:
+  $element_info = element_info('password_confirm');
+  $process = $element_info['#process'];
+  // Add our process function to the array:
+  $process[] = '_materio_user_process_password_confirm';
+  $form['account']['pass']['#process'] = $process;
+
+  $form['actions']['submit']['#attributes'] = array(
+    "@click.prevent" => "register",
+    "@keyup.enter" => "register"
+  );
+
+}
+
+function _materio_user_process_password_confirm($element){
+  // ksm($element);
+  $element['pass1']['#attributes'] += array(
+    "v-model" => "pass1",
+    "placeholder" => $element['pass1']['#title']
+  );
+  $element['pass2']['#attributes'] += array(
+    "v-model" => "pass2",
+    "placeholder" => $element['pass2']['#title']
+
+  );
+  return $element;
+}
+/**
+ * Returns HTML for a form element.
+ * Prepares variables for form element templates.
+ *
+ * Default template: form-element.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - element: An associative array containing the properties of the element.
+ *     Properties used: #title, #title_display, #description, #id, #required,
+ *     #children, #type, #name, #label_for.
+ */
+// function materio_user_preprocess_form_element(&$vars) {
+//   $element = $vars['element'];
+//   if($element['#type'] == 'password' && $element['#array_parents'][0] == 'account'){
+//     ksm($vars);
+//     // $vars['attributes']['placeholder'] = $element['#title'];
+//     $vars['element']['#attributes']['placeholder'] = $element['#title'];
+//   }
+// }
+
+
+
 /**
  * implements hook_block_view_BASE_BLOCK_ID_alter()
  *
@@ -55,3 +116,8 @@ function _materio_user_user_login_block_pre_render(array $build){
   ));
   return $build;
 }
+
+function materio_user_entity_type_build(array &$entity_types) {
+  // https://drupal.stackexchange.com/a/230547
+  $entity_types['user']->setFormClass('modal', 'Drupal\user\RegisterForm');
+}

+ 6 - 5
web/modules/custom/materio_user/src/Controller/AjaxRegisterForm.php

@@ -44,12 +44,13 @@ class AjaxRegisterForm extends ControllerBase {
   }
 
   private function getFormDefinition(){
-    // $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
-    // \Drupal::logger('materio_user')->notice($language);
-    // $this->form_builded = $this->formBuilder->getForm('Drupal\user\Form\UserLoginForm');
-    $entity = \Drupal::entityTypeManager()->getStorage('user')->create(array());
+    // http://web-tricks.org/content/how-render-user-login-form-and-user-register-form-drupal-8
+    $entity = \Drupal::entityTypeManager()
+      ->getStorage('user')
+      ->create(array());
+    // to use modal form display see materio_user_entity_type_build()
     $formObject = \Drupal::entityTypeManager()
-      ->getFormObject('user', 'register')
+      ->getFormObject('user', 'modal')
       ->setEntity($entity);
     $this->form_builded = $this->formBuilder()->getForm($formObject);
   }

+ 13 - 0
web/themes/custom/materiotheme/assets/dist/main.css

@@ -40,6 +40,19 @@ div.description[data-v-7bb795f8] {
   display: none;
 }
 
+.form-type-email[data-v-2acc57a0],
+.form-type-password-confirm[data-v-2acc57a0] {
+  max-width: 30%;
+  margin: 0;
+}
+input[data-v-2acc57a0] {
+  box-sizing: content-box;
+  max-width: 100%;
+}
+label[data-v-2acc57a0],
+div.description[data-v-2acc57a0] {
+  display: none;
+}
 
 fieldset[data-v-340aa566] {
   padding: 0;

File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


+ 15 - 0
web/themes/custom/materiotheme/templates/form/form.html.twig

@@ -0,0 +1,15 @@
+{#
+/**
+ * @file
+ * Theme override for a 'form' element.
+ *
+ * Available variables
+ * - attributes: A list of HTML attributes for the wrapper element.
+ * - children: The child elements of the form.
+ *
+ * @see template_preprocess_form()
+ */
+#}
+<form{{ attributes }}>
+  {{ children }}
+</form>

+ 2 - 2
web/themes/custom/materiotheme/vuejs/components/Form/LoginForm.vue

@@ -16,8 +16,8 @@ export default {
       userLogin: 'User/userLogin'
     }),
     getLoginForm(){
-      // Form through ajax is provided by materio_user custom module
-      // vuejs attributes a inserted by template in theme level
+      // Form through ajax is provided by materio_user drupal custom module
+      // vuejs attributes a inserted by form alter in same module
       MA.get(`/materio_user/login_form`)
         .then(({data}) => {
           console.log("getLoginForm data");

+ 42 - 35
web/themes/custom/materiotheme/vuejs/components/Form/RegisterForm.vue

@@ -7,20 +7,21 @@ import { MA } from 'vuejs/api/ma-axios'
 export default {
   name: "RegisterForm",
   data: () => ({
-    form:null,
-    mail:null,
-    password:null
+    form: null,
+    mail: null,
+    pass1: null,
+    pass2: null
   }),
   methods: {
     ...mapActions({
       userRegister: 'User/userRegister'
     }),
     getRegisterForm(){
-      // Form through ajax is provided by materio_user custom module
-      // vuejs attributes a inserted by template in theme level
+      // Form through ajax is provided by materio_user drupal custom module
+      // vuejs attributes a inserted by form alter in same module
       MA.get(`/materio_user/register_form`)
         .then(({data}) => {
-          console.log("getRegisterForm data");
+          console.log("getRegisterForm data", data);
           this.form = Vue.compile(data.rendered)
           this.$options.staticRenderFns = [];
           this._staticTrees = [];
@@ -30,19 +31,27 @@ export default {
           console.warn('Issue with getRegisterForm', error)
         })
     },
-    // login () {
-    //   this.userLogin({
-    //     mail: this.mail,
-    //     pass: this.password
-    //   }).then( () => {
-    //       console.log('logedin from login component');
-    //       this.$emit('onLogedIn')
-    //     }
-    //   ).catch(( error ) => {
-    //     console.warn('Issue with login from login component', error)
-    //     Promise.reject(error)
-    //   })
-    // }
+    register () {
+      console.log('register', this.mail, this.pass1, this.pass2);
+      // TODO: check for identical password
+      // TODO: check for valide email
+      // TODO: check for unique email
+      if(this.pass1 === this.pass2){
+          this.userRegister({
+            name: this.mail,
+            mail: this.mail,
+            pass: this.pass1
+          }).then( () => {
+              console.log('registered from register component');
+              this.$emit('onRegistered')
+            }
+          ).catch(( error ) => {
+            console.warn('Issue with register from registerform component', error)
+            Promise.reject(error)
+          })
+
+      }
+    }
   },
   beforeMount () {
     if(!this.form){
@@ -67,20 +76,18 @@ export default {
 </script>
 
 <style lang="scss" scoped>
-  // .form-item,
-  // .form-actions{
-  //   display:inline-block;
-  //   max-width:30%;
-  //   margin:0;
-  // }
-  // input{
-  //   box-sizing:content-box;
-  //   max-width:100%;
-  // }
-  // div.description{
-  //   display:none;
-  // }
-  // .form-item-persistent-login{
-  //   display:none;
-  // }
+  .form-type-email,
+  .form-type-password-confirm{
+    // display:inline-block;
+    max-width:30%;
+    margin:0;
+  }
+  input{
+    box-sizing:content-box;
+    max-width:100%;
+  }
+  label,
+  div.description{
+    display:none;
+  }
 </style>

+ 4 - 1
web/themes/custom/materiotheme/vuejs/store/modules/user.js

@@ -81,7 +81,10 @@ export default {
         REST.post('/user/register?_format=json', credentials)
           .then(({ data }) => {
             console.log('user REST registered', data);
-            resolve()
+            dispatch('userLogin', credentials)
+              .then(() => {
+                resolve()
+              })
           })
           .catch(( error ) => {
             console.warn('Issue with register', error)

Some files were not shown because too many files changed in this diff