Browse Source

ajax login fix #451

Bachir Soussi Chiadmi 4 years ago
parent
commit
b645a5e3ee

+ 5 - 0
composer.json

@@ -52,6 +52,7 @@
         "drupal/filter_perms": "1.x-dev",
         "drupal/honeypot": "1.29.0",
         "drupal/linkit": "^5.0",
+        "drupal/login_emailusername": "^1.1",
         "drupal/maillog": "1.x-dev",
         "drupal/matomo": "1.9.0",
         "drupal/menu_admin_per_menu": "1.0.0",
@@ -63,6 +64,7 @@
         "drupal/profile": "^1.0",
         "drupal/redirect": "^1.3",
         "drupal/redis": "^1.1",
+        "drupal/restui": "^1.17",
         "drupal/search_api": "^1.12",
         "drupal/simple_sitemap": "^3.1",
         "drupal/synonyms": "1.x-dev",
@@ -126,6 +128,9 @@
         "patches": {
             "drupal/domain_site_settings": {
               "Circular Error or Conflict with Language_Manager" : "https://www.drupal.org/files/issues/2018-10-09/2930391-21.patch"
+            },
+            "drupal/login_emailusername": {
+              "rest login email or user name https://www.drupal.org/project/login_emailusername/issues/2910511#comment-12564801" : "https://www.drupal.org/files/issues/2018-04-10/allow-rest-login-with-email-2910511-9.patch"
             }
         },
         "drupal-scaffold": {

+ 108 - 1
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": "afac9754e49e7dbd6c3cfd14393471ff",
+    "content-hash": "9092399791e0168d53586b646fb13c3b",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -1385,6 +1385,7 @@
             ],
             "description": "Promoting the interoperability of container objects (DIC, SL, etc.)",
             "homepage": "https://github.com/container-interop/container-interop",
+            "abandoned": "psr/container",
             "time": "2017-02-14T19:40:03+00:00"
         },
         {
@@ -4598,6 +4599,53 @@
                 "issues": "http://drupal.org/project/linkit"
             }
         },
+        {
+            "name": "drupal/login_emailusername",
+            "version": "1.1.0",
+            "source": {
+                "type": "git",
+                "url": "https://git.drupalcode.org/project/login_emailusername.git",
+                "reference": "8.x-1.1"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://ftp.drupal.org/files/projects/login_emailusername-8.x-1.1.zip",
+                "reference": "8.x-1.1",
+                "shasum": "f484b76b538f4dbbae5a75b49577f4ddf576809e"
+            },
+            "require": {
+                "drupal/core": "~8.0"
+            },
+            "type": "drupal-module",
+            "extra": {
+                "branch-alias": {
+                    "dev-1.x": "1.x-dev"
+                },
+                "drupal": {
+                    "version": "8.x-1.1",
+                    "datestamp": "1483456142",
+                    "security-coverage": {
+                        "status": "covered",
+                        "message": "Covered by Drupal's security advisory policy"
+                    }
+                }
+            },
+            "notification-url": "https://packages.drupal.org/8/downloads",
+            "license": [
+                "GPL-2.0-or-later"
+            ],
+            "authors": [
+                {
+                    "name": "rjjakes",
+                    "homepage": "https://www.drupal.org/user/3457245"
+                }
+            ],
+            "description": "Allow users to log in with either their username OR email address using the same input box on the login form.",
+            "homepage": "https://www.drupal.org/project/login_emailusername",
+            "support": {
+                "source": "https://git.drupalcode.org/project/login_emailusername"
+            }
+        },
         {
             "name": "drupal/maillog",
             "version": "dev-1.x",
@@ -5313,6 +5361,65 @@
                 "source": "https://git.drupalcode.org/project/redis"
             }
         },
+        {
+            "name": "drupal/restui",
+            "version": "1.17.0",
+            "source": {
+                "type": "git",
+                "url": "https://git.drupalcode.org/project/restui.git",
+                "reference": "8.x-1.17"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://ftp.drupal.org/files/projects/restui-8.x-1.17.zip",
+                "reference": "8.x-1.17",
+                "shasum": "2fff1b74759d5e490884d002330ad04d1bf241ba"
+            },
+            "require": {
+                "drupal/core": "^8.2.0"
+            },
+            "type": "drupal-module",
+            "extra": {
+                "branch-alias": {
+                    "dev-1.x": "1.x-dev"
+                },
+                "drupal": {
+                    "version": "8.x-1.17",
+                    "datestamp": "1557845581",
+                    "security-coverage": {
+                        "status": "covered",
+                        "message": "Covered by Drupal's security advisory policy"
+                    }
+                }
+            },
+            "notification-url": "https://packages.drupal.org/8/downloads",
+            "license": [
+                "GPL-2.0-or-later"
+            ],
+            "authors": [
+                {
+                    "name": "-enzo-",
+                    "homepage": "https://www.drupal.org/user/294937"
+                },
+                {
+                    "name": "clemens.tolboom",
+                    "homepage": "https://www.drupal.org/user/125814"
+                },
+                {
+                    "name": "juampynr",
+                    "homepage": "https://www.drupal.org/user/682736"
+                },
+                {
+                    "name": "klausi",
+                    "homepage": "https://www.drupal.org/user/262198"
+                }
+            ],
+            "description": "Provides a user interface to manage REST resources.",
+            "homepage": "https://www.drupal.org/project/restui",
+            "support": {
+                "source": "https://git.drupalcode.org/project/restui"
+            }
+        },
         {
             "name": "drupal/search_api",
             "version": "1.15.0",

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

@@ -1,4 +1,4 @@
-timeout: 1800
+timeout: 7200
 max_timeout: 172800
 padding: 20
 role_logout: false

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

@@ -67,6 +67,7 @@ module:
   link: 0
   linkit: 0
   locale: 0
+  login_emailusername: 0
   maillog: 0
   menu_ui: 0
   metatag: 0
@@ -84,8 +85,11 @@ module:
   redirect: 0
   redis: 0
   responsive_image: 0
+  rest: 0
+  restui: 0
   search_api: 0
   search_api_db: 0
+  serialization: 0
   simple_sitemap: 0
   synonyms: 0
   system: 0

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

@@ -1,4 +1,4 @@
-login_with_username: false
+login_with_username: true
 _core:
   default_config_hash: 6cFmNHjhs_glkuywBEhzcUQ8aiHXcFe6hZfW7PLN-qg
 langcode: fr

+ 1 - 1
config/sync/language/en/addtoany.settings.yml

@@ -1 +1 @@
-additional_html: "<a class=\"a2a_button_facebook\"></a>\r\n<a class=\"a2a_button_twitter\"></a>\r\n<a class=\"a2a_button_reddit\"></a>\r\n<a class=\"a2a_button_email\"></a>"
+additional_html: "<a class=\"a2a_button_facebook\"></a>\n<a class=\"a2a_button_twitter\"></a>\n<a class=\"a2a_button_google_plus\"></a>\n"

+ 18 - 0
config/sync/rest.resource.entity.user.yml

@@ -0,0 +1,18 @@
+uuid: 76f64e4d-009d-4e41-958b-8fd3f5aa0a68
+langcode: fr
+status: true
+dependencies:
+  module:
+    - serialization
+    - user
+id: entity.user
+plugin_id: 'entity:user'
+granularity: resource
+configuration:
+  methods:
+    - GET
+    - POST
+  formats:
+    - json
+  authentication:
+    - cookie

+ 17 - 0
config/sync/rest.resource.user_registration.yml

@@ -0,0 +1,17 @@
+uuid: af90996e-898d-4bb5-a7ae-ca4a9e26714f
+langcode: fr
+status: true
+dependencies:
+  module:
+    - serialization
+    - user
+id: user_registration
+plugin_id: user_registration
+granularity: resource
+configuration:
+  methods:
+    - POST
+  formats:
+    - json
+  authentication:
+    - cookie

+ 4 - 0
config/sync/rest.settings.yml

@@ -0,0 +1,4 @@
+bc_entity_resource_permissions: false
+_core:
+  default_config_hash: Jg3_yqsTIZ51KOKp3OV2KDVVrlx3N3OCEfniEse09KE
+langcode: fr

+ 5 - 0
config/sync/serialization.settings.yml

@@ -0,0 +1,5 @@
+bc_primitives_as_strings: false
+bc_timestamp_normalizer_unix: false
+_core:
+  default_config_hash: 6A1rmsmNf4SJrwCEt_aZyO_kPYuFnIOPC2n5lJiIftA
+langcode: fr

File diff suppressed because it is too large
+ 0 - 0
config/sync/user.mail.yml


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

@@ -15,6 +15,7 @@ permissions:
   - 'access synonyms entity autocomplete'
   - 'create corpus_documents workflow_transition'
   - 'create generique workflow_transition'
+  - 'restful post user_registration'
   - 'use text format wysiwyg'
   - 'view published fil entities'
   - 'view search api pages'

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

@@ -23,6 +23,7 @@ permissions:
   - 'edit own composition entities'
   - 'edit own fil entities'
   - 'opt-in or out of matomo tracking'
+  - 'restful post user_registration'
   - 'use chutier'
   - 'use text format wysiwyg'
   - 'view own unpublished chutier entities'

+ 1 - 1
config/sync/views.view.profiles.yml

@@ -1,5 +1,5 @@
 uuid: ecb1909a-9cc2-4579-bfd3-7e0c8b38ea40
-langcode: en
+langcode: fr
 status: true
 dependencies:
   module:

+ 4 - 0
web/modules/custom/edlp_ajax/src/Controller/EdlpAjaxController.php

@@ -319,6 +319,10 @@ class EdlpAjaxController extends ControllerBase {
         'tags' => [
           'edlp-ajax-blocks-cache',
           // $this->entity_type.':'.$this->id // not necessary as we add $renderable as CacheableMetadata to the response
+        ],
+        'contexts' => [
+          'languages:language_content',
+          'user'
         ]
       ]
     ];

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


File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/edlptheme/assets/dist/styles/app.min.css


+ 80 - 15
web/themes/custom/edlptheme/assets/scripts/main.js

@@ -1,6 +1,8 @@
 (function($, Drupal, drupalSettings) {
 
   EdlpTheme = function(){
+    var _origin = window.location.origin;
+    var _base_url = drupalSettings.path.baseUrl;
     var _ajax_settings = drupalSettings.edlp_ajax;
     var _$body = $('body');
     // var _is_front = drupalSettings.path.isFront;
@@ -17,6 +19,9 @@
     };
     var _corpus_promise;
     var _is_mobile =  edlp_mobile.device_is_mobile;
+    var _is_loggedin = drupalSettings.user.uid === 0 ? false : true;
+    var _$log_form;
+    var _user_tokens;
 
     //  ___      _ _
     // |_ _|_ _ (_) |_
@@ -25,9 +30,9 @@
     function init(){
       console.log("EdlpTheme init()");
 
-
-      // if(!drupalSettings.path.isFront)
-      //   return;
+      if (!_is_loggedin) {
+        initLogForm();
+      }
 
       if(_is_mobile){
         initMobile();
@@ -40,11 +45,8 @@
       initAjaxLinks();
       initHistory();
 
-
       if(!_is_mobile){
-
         checkLayout();
-
         initAudioLinksHover();
       }
 
@@ -55,13 +57,76 @@
         _$body.attr('booted', 'booted');
       }
 
+    };
 
-      // if(!drupalSettings.path.isFront)
-      //   return;
-      //
-      // initEvents();
+
+    //  _                ___
+    // | |   ___  __ _  | __|__ _ _ _ __
+    // | |__/ _ \/ _` | | _/ _ \ '_| '  \
+    // |____\___/\__, | |_|\___/_| |_|_|_|
+    //           |___/
+    function initLogForm(){
+      console.log('initLogForm');
+      _$log_form = $('#user-login-form:not(ajax-enebled)')
+        .on('submit', onSubmitLogForm)
+        .addClass('ajax-enabled');
+    };
+
+    function onSubmitLogForm(e){
+      e.preventDefault();
+      // console.log('onSubmitLogForm', e);
+      var args = {
+        name : $('input#edit-name[type="text"]', this).val(),
+        pass : $('input#edit-pass[type="password"]', this).val()
+      };
+      // console.log(args);
+      logIn(args).then(getStudioLinkBlock);
+      return false;
     };
 
+    function logIn(args){
+      console.log('logIn', args);
+      _$log_form.addClass('ajax-loading');
+      _$body.addClass('ajax-loading');
+
+      return $.ajax({
+        type: 'POST',
+        headers: {'Content-Type': 'application/json'},
+        xhrFields: {
+          withCredentials: true
+        },
+        // accessToken : 'tokenvaluehere',
+        url: _origin+_base_url+"user/login?_format=json",
+        data: JSON.stringify(args),
+        // name: args.mail,
+        // pass: args.pass,
+        success: function(response){
+          // console.log('sucess', response);
+          _user_tokens = response;
+        },
+        error: function (xhr, ajaxOptions, thrownError){
+          console.log(xhr.status);
+          console.log(thrownError);
+        }
+      });
+    };
+
+    function getStudioLinkBlock(){
+      var path = _origin+_base_url+'edlp/ajax/blocks/json/';
+      $.getJSON(path+"studiolinkblock", {})
+        .done(onStudioLinkBlockLoaded)
+        .fail(function(jqxhr, textStatus, error){
+          console.warn('Studio ink block load failed', jqxhr.responseText);
+        });
+    };
+
+    function onStudioLinkBlockLoaded(data){
+      console.log('onStudioLinkBlockLoaded', data);
+      $('#block-studiouserlogin').replaceWith(data.blocks.studiolinkblock.rendered);
+      initAjaxLinks();
+      _$log_form.removeClass('ajax-loading');
+      _$body.removeClass('ajax-loading');
+    }
 
     //  __  __     _    _ _
     // |  \/  |___| |__(_) |___
@@ -271,7 +336,7 @@
       console.log('ajaxLoadContent : state', state);
       _$body.addClass('ajax-loading');
       _ajax_timing.start = performance.now();
-      var path = window.location.origin + Drupal.url(state.ajax_path);
+      var path = _origin + Drupal.url(state.ajax_path);
       $.getJSON(path, {})
         .done(function(data){
           onAjaxLoaded(data, state);
@@ -552,7 +617,7 @@
     //      |__/
     // NOT USED (YET)
     // function refreshAllBlocks(){
-    //   var path = window.location.origin + Drupal.url(_ajax_settings.blocksjson_path);
+    //   var path = _origin + Drupal.url(_ajax_settings.blocksjson_path);
     //   $.getJSON(path, {})
     //     .done(function(data){
     //       onAjaxBlockLoaded(data);
@@ -1228,7 +1293,7 @@
         this.$cartel.addClass('loading');
         var vm = 'player_cartel';
         var ajax_path = _ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;
-        var path = window.location.origin + Drupal.url(ajax_path);
+        var path = _origin + Drupal.url(ajax_path);
         $.getJSON(path, {})
           .done(this.onNodeLoaded.bind(this))
           .fail(this.onNodeLoadFail.bind(this));
@@ -1366,7 +1431,7 @@
     function RandomPlayer(playlist){
       this.active = false;
       this.playlist = playlist;
-      this.path =  drupalSettings.path.baseUrl+drupalSettings.path.pathPrefix+'#random'
+      this.path =  _base_url+drupalSettings.path.pathPrefix+'#random'
       this.$btn = $('<a>')
         .html('Shuffle')
         .attr('href',this.path)
@@ -1942,7 +2007,7 @@
 
       if(typeof pop_state == "undefined" || !pop_state){
         console.log('backToFrontPage push state');
-        history.pushState({home:true}, null, drupalSettings.path.baseUrl+drupalSettings.path.currentLanguage);
+        history.pushState({home:true}, null, _base_url+drupalSettings.path.currentLanguage);
       }
     }
 

+ 11 - 4
web/themes/custom/edlptheme/assets/styles/app.scss

@@ -2405,15 +2405,22 @@ footer{
     }
     &:hover{
       .block-content{
-        height:200px;
+        height:300px;
         opacity: 1;
         pointer-events:auto;
         transition-delay: 0s;
       }
     }
-    &#block-studiouserlogin:hover{
-      .block-content{
-        height:300px;
+    // &#block-studiouserlogin:hover{
+    //   .block-content{
+    //     height:300px;
+    //   }
+    // }
+    #user-login-form{
+      transition: opacity 1s ease-out;
+      opacity:1;
+      &.ajax-loading{
+        opacity: 0.2;
       }
     }
   }

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