handeled login or register from a modal, YES git status

This commit is contained in:
Bachir Soussi Chiadmi 2019-10-07 15:54:03 +02:00
parent 8b3c31c0f5
commit d5a6194727
25 changed files with 398 additions and 58 deletions

View File

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

64
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "bee8de31ae3bb4fa7aa201097983403f", "content-hash": "e30f4a9dd3ad6f9179b3b52f60f7791b",
"packages": [ "packages": [
{ {
"name": "alchemy/zippy", "name": "alchemy/zippy",
@ -6495,6 +6495,66 @@
"source": "https://git.drupalcode.org/project/field_group" "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", "name": "drupal/file_mdm",
"version": "1.1.0", "version": "1.1.0",
@ -15831,7 +15891,7 @@
"version": "8.3.5", "version": "8.3.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.drupal.org/project/coder.git", "url": "https://git.drupalcode.org/project/coder.git",
"reference": "35277fc8675b6a2cbb194f8880145a9c85c845c4" "reference": "35277fc8675b6a2cbb194f8880145a9c85c845c4"
}, },
"require": { "require": {

View File

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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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() * implements hook_block_view_BASE_BLOCK_ID_alter()
* *
@ -55,3 +116,8 @@ function _materio_user_user_login_block_pre_render(array $build){
)); ));
return $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');
}

View File

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

View File

@ -40,6 +40,19 @@ div.description[data-v-7bb795f8] {
display: none; 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] { fieldset[data-v-340aa566] {
padding: 0; padding: 0;

File diff suppressed because one or more lines are too long

View File

@ -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>

View File

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

View File

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

View File

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