Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 31)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

CB ajax login

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
1 year 8 months ago #333715 by activha
CB ajax login was created by activha
Hello
Arriving to my final steps :-)
Now that I have a web component made with CB auto actions, I'd like my users to be able to log in on this web component while it's other domains.
So I was thinking at an ajax log in that would return a simple json string ok or not
Is this possible with CB Login and/or CB Auto actions ?
Do you have an idea how to start this ?
Thanks a lot

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
1 year 8 months ago #333716 by krileon
Replied by krileon on topic CB ajax login
With their username and password? I guess you could use the Login / Logout action, but I don't see how it's going to be of much use as authentication cookies are not cross origin in Joomla. If you want to make external API calls on a users behalf you need a proper modern authentication flow. Usually that's a token exchange of some kind. Joomla 4 has token authentication built in now so maybe explore using that.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
1 year 8 months ago #333717 by activha
Replied by activha on topic CB ajax login
Yes I was thinking also as a Login/Logout action. I only need it to return a yes/no json to allow the user
As I use a webcomponent and not an iframe I'm able to access the cookies on the external domains with our own domain cookies. So I imagined that asking a login via ajax, then getting back the main domain cookies would be enough to allow the user to use the web component.

Thinking at joomla 4 token, I have seen this but cannot really imagine how to use them. The process has to be really simple for a user : just login with its username/pass anywhere when the web component is available and then access its content.

Do you know how I could access the autoaction to try ? with a simple form to send user/pass ?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
1 year 8 months ago #333718 by krileon
Replied by krileon on topic CB ajax login

Yes I was thinking also as a Login/Logout action. I only need it to return a yes/no json to allow the user
As I use a webcomponent and not an iframe I'm able to access the cookies on the external domains with our own domain cookies. So I imagined that asking a login via ajax, then getting back the main domain cookies would be enough to allow the user to use the web component.

Using the Ouput parameters you can have your auto action return whatever you want. Basically check if they've a user id after doing the login action and if they do they're logged in. If they don't they aren't. So you could return true/false, JSON, etc.. as you please based off that.

The only issue I could see is currently the Login / Logout requires a redirect, which would disrupt the Output behavior. Have added a feature ticket to make the redirection optional. Will get to that sometime next week as currently am updating CB Connect.

forge.joomlapolis.com/issues/9167

Thinking at joomla 4 token, I have seen this but cannot really imagine how to use them. The process has to be really simple for a user : just login with its username/pass anywhere when the web component is available and then access its content.

Token authentication won't work here then.

Do you know how I could access the autoaction to try ? with a simple form to send user/pass 

Just post to your auto action url (leave Triggers as None for direct access support). It's a component endpoint like any extension. You can access your POST data using substitutions (e.g. [post_username]).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
1 year 7 months ago #333721 by activha
Replied by activha on topic CB ajax login
Thanks, that should do it provided that I could have a return

The function that I wrote for the web component is something like this :
Code:
    loginUserAjax() {       const username = this.shadowRoot.getElementById('username').value;       const password = this.shadowRoot.getElementById('password').value;       const formData = new FormData();       formData.append('username', username);       formData.append('password', password); //       formData.append('option', 'com_ajax'); //       formData.append('plugin', 'userloginajax'); //       formData.append('format', 'json');       const requestOptions = {         method: 'POST',         body: formData,       };       fetch('https://devel.cercle.business/index.php?option=com_comprofiler&view=pluginclass&plugin=cbautoactions&action=action&actions=327&Itemid=9343', requestOptions)         .then(response => response.json())         .then(data => {           if (data.success) {             // Connexion réussie, mettez à jour l'interface utilisateur en conséquence             console.log('Connexion réussie');                      // Mettez à jour l'état et l'interface utilisateur de votre web component             updateWebComponentState(true);           } else {             // Échec de la connexion, affichez un message d'erreur             console.log('Échec de la connexion');             alert('Échec de la connexion. Veuillez vérifier votre nom d\'utilisateur et votre mot de passe.');           }         })         .catch(error => {           console.error('Error:', error);           alert('Une erreur s\'est produite lors de la connexion. Veuillez réessayer.');         });     }

and would return a login state so that I could update the content with something like 
Code:
    updateWebComponentState(isLoggedIn) {       // Mettez à jour l'état de votre web component et l'interface utilisateur en fonction de la valeur de 'isLoggedIn'          // Par exemple, vous pouvez cacher le formulaire de connexion et afficher un message de bienvenue       if (isLoggedIn) {         this.shadowRoot.getElementById('ajaxLoginForm').style.display = 'none';         this.shadowRoot.getElementById('welcomeMessage').style.display = 'block';       } else {         this.shadowRoot.getElementById('ajaxLoginForm').style.display = 'block';         this.shadowRoot.getElementById('welcomeMessage').style.display = 'none';       }     }

I was wondering whether it would be possible to request the url by ajax ?

Also as you are updating CB Connect, could we imagine linking to it so that the users could log in with their social networks data ?

Have a good weekend :-)

Please Log in or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
1 year 7 months ago - 1 year 7 months ago #333722 by activha
Replied by activha on topic CB ajax login
Of course the best thing would be to have an ajax login/logout and an ajax registration form that I could use in the web component ;-)

BTW using the above autoaction, how do I get the user from the url with [post_username] and [post_password] ? Is it enough to input these in the action tab and leave the user on automatic ? or should I code the user with these and how ?
Last edit: 1 year 7 months ago by activha.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum