-
-
Notifications
You must be signed in to change notification settings - Fork 178
024 How to integrate the Create User Helper Method in your Components
Hi I would like to give you a quick tutorial or demonstration on how to use user creation method or function In your component What is the user Creation function 00:00:18 It is basically a part of code's helper function actually That gets added to the helper class If you don't know where the helper class is let me quickly show you now if you go to your repository where you Find basically your Joomla install you would go to administrator Now there is a helper class for the front end of every component as well as for the back end so looking in a backend We go to component 00:00:55 Expert Database Helpers And it's basically that file there that is the helper Class if we open it we See that it's the abstract expert database helper Now that helper class gets included Into your component on every page so if you to open the main backend file with that one Which get loaded by Joomla first you'll see that it actually includes that helper file in every page 00:01:28 So that means everything inside of that Class is available to you everywhere in your component When we actually go back to our Interface And we go to components and the Expert Database You would see that there is a libs or actually stand for library and helpers and you see We have to switch Ticked yes add create user helper method Set to yes That is the 00:02:11 The switch that you need to trip So that component builder and knows that you actually want the helper class that Creates users to be Added to the helper class of your front and backend of your component I'm gonna close out here I am going to go back to the code And then I am going to do a Simple search for user 00:02:44 . Here is quite a few users there it is Create user As you can see this is a public static function So you would basically call it with that class name Then colon colon and the name of the function, right which is create user And you see that it is set to new 00:03:26 Now New has in it A few variables is basically an array So you can go through this class and you'd see that it has a password one or is just password or password two, it has a user name it has a name aswell as a e-mail And it then creates the user That's what this class does so it calls in the Joomla Component users 00:04:00 It calles in it's registration model And then it basically uses that model to create a user so that's what that switch does it adds this class to your component you can then use it in your component it doesn't automatically just sets everything else in place you still required to do as a developer to add to correct code I'll show you what I have done and how I am using it There is a admin View called experts it's in this view that I would actually like Option for someone to create a user now let me first demonstrate how it works So I would go to expert data base and click on experts Let's click on new So you would see there is a 00:04:55 field called Expert With which you can select Users within a specific group I will also explain some of that more later But underneath there is this button create user If you Click on it it basically has a pop-up where in you enter a user name I am just gonna say Testing 123 Use that as the username 00:05:26 And as the password There we go, got the user name So everything is testing 123 And if I click create it basically has this nice effect where it is busy creating it Setting it up, sending out the email doing all of that for you And once it's done It lets you know that user was created successfully and the login details was e-mailed to the user And then it says here ready to select 00:06:05 You can now select testing 123 that you just created from the user list In the above field simply click on the blue user icon Click here and you can type in that testing 123 click Search And there is the user created and we click enter You see that it basically used a very strange conversion here Basically converting the username away from the numbers now you can you can fix that By clicking edit 00:06:40 And then changing it to 123 and say save the update Does not want to allow that. So clearly my little application doesn't wanna allow you to use actually any numbers in the user name,.That's not the point The point is that we have this integrated user now that is connected to an expert And if you were to click there again You can still selected ok but once you select it once you can't create a new expert And select that user again So it's basically one profile connecting to one user To set up a expert 00:07:24 So that's the feature I'm using it for there is different ways that I have implemented this let me show you another one Obviously you realise I'm using a lot of JavaScript on this page I will show you some of that JavaScript but That yourself Ok let me just get out of here for Example over here I wrote this job tracking Extension And let's say we want to create a new job order then I can say whether it's a new client or a existing if it is an existing I Simply select from this list 00:08:04 If it's new I click here I can enter all the details of the user and when I click save It Creates the user Stores the data in the user table not in the job order table deletes all these values So did the job order table never stores any user values in the relation of this job order of course And so that's another way that I have implemented so if we were to close this out And where to open a client A new one You would see it's basically it's the same values And 00:08:44 Everything is the same So that's another way that we integrated this whole User integration So there are really many different ways to this The way I have done it I've just listen to my clients expectation What I really would like to see and how they would like it to work And then simply Make It Happen that way I personally I prefer the Ajax Way much more It's it's just seems to me easier So let me illustrate some of or let me show you some of the code that I used to do that 00:09:26 Ok so we back in The Experts View As I've done before I previously in other tutorials explained how to make use of the Ajax concept Within Component Builder Now for those of you that like to understand what's going on let me give you a quick runover At the code level Within every component that makes use of Ajax A model and a controller is created The controller is named Ajax.json.php and the model is named 00:10:04 Ajax Ok let me open the model And also let me open The controller As you can see the controller basic fires off The register tasks within the construct method And then it adds the tasks Into a switch And tries to run the task basically Also in 00:10:31 The model it It Gets the model Ajax And then runs the method that basically corresponds to the task And so that is how It runs It uses the Joomlas default Filtering Method in the way that it gets values that are being posted And then value dates that those values actually are there Then sends the values over to the model 00:11:05 Now that's looking at it from a code side so if you look at the model It simply shows you Various methods Some of them are protected And some of them are public and those are usually the ones That gets called from the controller once the Ajax gets the Verification level and it's Verified So here is the create user class 00:11:31 Basically We first check Whether this user now this is custom script I mean this I wrote custom component build does not write this so Basically when you go back to the user interface You see that If I scroll down here create user fields And then there's great user You see that I wrote this right here And that basically gets placed into the model 00:12:07 So that's the Ajax method here I simply in that Ajax input I annotate the specific tasks The task name And specific variables And again the method name You could have different method names from task names and What should be validated whether it's integer, float or whatever And if there's no value What is the value by Default So this is where you set up there basically the controllers information 00:12:39 And then here your customised these write your script so basically create user gets data and seems from what view is it then validates with this current login user has the permission To actually The Experts area Then it Converts the data because it's a json set of datasets that I'm sending across So that we can see if it's an array does some other checks So you can see I'm still here I'm using that 00:13:17 Global helper Class and methods Here are number of custom methods obviously that That is available in that class to go through it we just added in there as freebies and And you wanna always see the Need of them but I'm using them often And even if you have with Improvements on those methods please make a pull request and we'll make those changes Then you over here once we've Become very sure that we've got enough data on the right data We basically get that same method and we need to create user 00:13:55 Get result And if it's not the correct result we deal with it accordingly And if it is the correct result we create Add the user to the user group That's something that the user does not that you create user does not do So we Then have a user group setup 00:14:17 And Basically in the component And we get that user group Set into the correct User Group This is a return message If it's an error or whether it's a Success So down here is the error message So if it's if it's successful this is what we do if it's unsuccessful this is what we do 00:14:45 And so that's just a quick look I mean obviously we can pause this video and Look at What I have done And then here is getUser when the page loads initially we get the id get the data packs it into some html And sends it off So This is the PHP side obviously We we do this create user and then there is a ajax 00:15:16 Site right in Javascript So In the JavaScript when the page loads Would you get user with the user ID We get the user ID from the field And then it loads that data that you saw If you if you looked no this is the wrong place Basically shows you that is the data it loads And that data can be edited Except over here 00:15:51 You cannot add numbers in the username but you can do that and it will update it as you see and will say that is updated it Obviously if there is a Error with the email already used or something it will also give you an error And this is all part of how we basically have setup the JavaScript Ok we can scroll down to So I've just added to Javascript to the view file And here is get user the server side and there is the the function 00:16:24 I have two functions usually one that sort of deals with Waiting and then eventually setting up the data into the The View And here's one making the call so this is how you call structure would usually look In index. php ?option = your components name And the task which Must go to the Ajax controller And then this is the task 00:16:54 And you then here can stipulate what format you would like the result set returned in if you Want the result set returned the raw which in sometime sometimes is the case There is if you look here There is a raw Variable You can just set the raw variable to true Then it will give you the results set just Like that without Braces around them 00:17:23 Or a call back or anything You see when you make calls from JavaScript It usually Wants this call back to be added If you make calls from other JavaScript libraries you might just want the braces around it But if you want it raw which also is often the case you just add the variable raw to the URL = true and then end up passing it back to you with this So that's a little heads up on Ajax function so 00:17:56 the format must json that's Important Ok and always use a token Have the token on the page this token is necessary To prevent cross site scripting of course I usually add the token to the page Through the Java oh sorry php So there is a place down here if you scroll down where is it I just remembered remembered 00:18:28 If you are working in a backend The backend the backend and the admin area you don't need to have the token its get added to the page dynamically Since we Basically parsed the JavaScript Areas And if we see token we actually know oh token is to be there and we add the token for you Where is the front end you must actually literally add the token There was just too many reasons for us Not to do the Automation in the front end so but you could literally change to the variable name as well 00:19:03 To something of your choice Where is now it's just token it's backend it's more secure ok so You need to always add a token To the request and check whether the token is there if it's not that it wouldn't make a request at all Ok so I was looking at another function there Ok so that's simply how we create a user And integrate the user concept within this component I hope that was helpful I realize if you not that fluent in programming in JavaScript Or in jQuery 00:19:41 As well as in PHP This might not fully resolved your questions Like I said where the beginning of these tutorials I wasn't planning on making a component that is Very easy to use but rather a Component that is very powerful to use And leaving it up to you to decide how to implement This user integration Is really the most powerful way of doing it At least we are adding the the class with which you can create the user And again even there you can go look at that class 00:20:20 If you feel my implementation is a little you know needs some Inprovement You can either shoot me a mail or you could Take For this component Builder on GitHub Pull down to your own repository Make the changes push it back And The place inside Of component builder where this class is constructed 00:20:47 is obviously Within The compilers files. Now the compiler Has Has quite a few files and you need to do do a search So you basically go to component Builder go to helper and then Use the compiler And here is all its files So do a search in here 00:21:09 For the function Create user you could you know just search for that and I'm sure you're fine it and it is in that area where you need to make the adaptation and the changes because it's dynamically added It is not it can't be edited like right in the script it needs to be edit in the function where we add it Just go search those functions 00:21:38 Thank you for watching That's how you create users and connect them to your components Obviously there is much more to say but I'm afraid this will get way too long like most of my tutorials get to long I want to keep it this this way and trying to make it shorter hope you enjoyed that
- Home
- Beta Testing
- Custom Code
- PHP Settings
- Demo Component
-
Tutorials
- Hello World JCB
- Intro JCB Guide
- JCB Installation Steps
- Planning Components
- Field Type Overview
- Basic Fields Creation
- Admin View Management
- Advanced Field Usage
- Admin Component Integration
- Component Setting Customization
- Scripting Components
- Component FTP Options
- Dynamic Get Method
- Site View DynamicGet
- Site View Templates
- Template Setup Guide
- Layout Configuration Steps
- Custom Admin Management
- Adding Site Views
- Custom Admin Integration
- MySQL Demo Tweaking
- Global JCB Settings
- Custom Time Field
- User Helper Integration
- Email Helper Usage
- Message Store Email
- List View Unescape
- Export Import Customization
- Overwrite Custom Fields
- List Field Filtering
- Automatic Code Import
- Manual Code Implementation
- Component Export Import
- Custom Admin Buttons
- Translation Management
- Site View Permissions
- Component SQL Updates
- Site Edit Configuration
- JCB Backup System
- Helper Structure Integration
- JCB v2.5 Upgrade
- Tab Setup Guide
- JCB v2.6 Release
- Extended HelloWorld
- Field Rule Validation
- Community Snippets Intro
- Snippet Forking Tutorial
- Pull Request Snippets
- Library Manager Area
- Excel-based Translation
- Dynamic Router Details
- Database Auto Updates
- Subform Quick Demo
- VDM Package Import
- Dynamic File Inclusion
- File Field Upload
- Drag-n-Drop Upload
- Quick HelloWorld JCB
- Non-database Fields
- Dashboard Customization
- Menu Prefix Toggle
- Community JCB Packages
- Collaborative JCB Workflow
- JCB Package Install
- JCB JAB18 Event
- Convenient New Fields
- Component Language Strings
- Library Functionality Anticipation
- Join Field Relations
- License Template Change
- Code Reusability
- Local Dev Environment
- Extended Field Types
- Joomla Custom Fields
- Custom Field Expansion
- Site View Listing
- Run Expansion Method
- Form Site View
- Field URL Update
- Additional Helper Methods
- Field Validation Rules
- New Placeholder Feature
- Component Config Params
- Per-field Default Values