-
-
Notifications
You must be signed in to change notification settings - Fork 178
024 How to integrate the Create User Helper Method in your Components
What is the User Creation function? It is basically a part of code's helper function that gets added to the Helper class.
If the repository is opened you will find Joomla Install, go to administrator. There is a Helper class for the front end of every component as well as for the back end. Looking in a back end, in component there is 'com_expertdatabase'. and under it 'expertdatabase.php'. 00:00:55 Go to Helpers, that file(See video), is the Helper class. If it is opened the abstract 'expertdatabaseHelper' may be seen. That Helper class gets included into the component on every page. If the main back end file with that one 'expertdatabase' is opened, which get loaded by Joomla first. It includes that Helper file in every page. 00:01:28 It means that everything in that class is available everywhere in the component. Returning to the interface, Component Builder Dashboard, and then go to components and to 'expertdatabase'. There can Library & Helpers be seen . The switch 'add create user helper method', is in the 'yes' position. 00:02:11 That is the switch that should be used, by which Component Builder is commanded that the Helper class that creates Users should be added to the Helper class of the front and back end of the component. 00:02:44 If this area is closed and you return to the code and a simple search for User is done, quite a few users can be seen as well as 'Create User'.
This is a public static function. It may be called with that class name 'expertdatabasehelper' then 'colon' 'colon' and the name of the function, which is Create User. It is set to '$new'. 00:03:26 '$new' has in it a few variables, it is an array. In this class it may be noticed that it has a password: 'password2'. It has a user name, it has a name, as well as a e-mail. Then it creates the user, that's what this class does. It calls in the Joomla component users. 00:04:00 It calls in it's registration model and it uses that model to create a user. That's what that switch does, it adds this class to the component. The it may be used it in the component. It doesn't just sets everything else in place, It is still required of the developer to add the correct code as everything else is not automatically sets in place.
There is a admin view called 'Experts'. For example: If there is a need in this view like the option for someone to create a User. To demonstrate how it works. Go to 'expertdatabase' and click on 'Expert' and click on 'New'. 00:04:55 A field called 'Expert' may be seen in which you can select users within a specific group. Underneath is the button Create User. It has a pop-up where a user name may be entered . For instance 'Testing123' may be used for the name as well as the username, and 'Testing123 @vdm.io' as e-mail and as the password. 00:05:26 If 'Create' is clicked, it creates it, setting it up, sending out the email. Once it's done it informs you that the user was created successfully and the login details had been e-mailed to the user. 00:06:05 Then it indicates that it is ready to be selected and 'testing123' which has been created from the user list in the above field may now be selected. Click on the blue user icon and type in that 'testing123' and click 'Search'. As the user is now created, 'enter' may be clicked . A very strange conversion may be noticed, it converted the username's numbers to letters. 00:06:40 This application doesn't allow any numbers in the user name, but anyhow this integrated user has been connected to an 'Expert'. If you were to click there again, it may still be selected, but once it is selected, you can not create a new 'Expert' and select that user again. Thus it is one profile connecting to one user to set up a 'Expert'. 00:07:24
A lot of JavaScript may be noticed on this page and here(See video) has this job tracking extension been written. If for example a new job order needs to be created, then it can be indicated whether it is a new client or a existing one. If it is an existing, simply select from the list. 00:08:04 If it's new, click 'A new Client'. All the details of the user can be entered and when 'save' is clicked, it creates the user, stores the data in the user table, but not in the job order table and deletes all these values (the job order table never stores any user values in the relation of this job order).
If this closed, open a 'New client'. The same values can be seen. 00:08:44 This is another way to integrate this whole user integration.
In previous tutorials it had been explained how to make use of the Ajax concept within Component Builder. Here is a quick overview for those that would like to understand what happens at code level. How does the code look which had been used for a Ajax? 00:09:26
Return to the Expert view.
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 'Ajax'. 00:10:04 Open the model and the controller. As may be seen the controller gives the register commands within the construct method and adds the tasks to a switch, and makes an attempt to run the task. 00:10:31 In the model it gets the model Ajax, and then runs the method that corresponds to the task.
It uses the Joomla's default filtering method in a way that it gets values that has been posted and validates if those values are actually there. The values are then transfered to the model. 00:11:05 That is looking at it from a code perspective. Various methods are displayed in the model and some of them are protected, and some of them are public. Those 'getcreateuserfields' are usually the ones that gets called from the controller once the Ajax gets the verification level and it is verified. Here is the 'createUser' class. 00:11:31 First check whether this user, (it is custom script, Component Builder does not write this) so then in returning to the user interface(Editing the Admin view) and scroll down to 'Create user fields, then there is 'Create user'. What has been written here, gets placed into the model. 00:12:07 That is the Ajax method. In the Ajax input specific tasks are notated, the task name, and specific variables, and again the method name. Method Names may be different from the Task Names. Select what should be validated(In the 'Select a Filter' area), whether it should be a integer, float etc. and if there's no value(In the 'Default' area), get the default value. This is where the controllers information is set up. 00:12:39 In this area (php Custom Method) may the custom script be done. Create user gets data and determines from what view it is, then validates whether this current login user has the permission to the Experts area. Then it converts the data because it's a Json set of datasets that is transferred and checks whether it's an array and does some other checks.
Here is that Global Helper class and methods being used.(See video) A number of Custom Methods may be seen which are available in that class. It has been added as freebies and should not necessarily always be used. If anyone can improve on those methods, please make a pull request and changes can be done. Once the required data had been collected(See video), and getting that same 'method', a 'Create User' is done. 00:13:55 Then get a result('$returned'), and if it's not the correct result it should be dealt with accordingly. If it is the correct user it may be added to the user group. That is something that Create User does not do. There is a user group setup in the component. 00:14:17 The user group needs to be set into the correct user group. The return message will indicate if it has been an error or a success. Lower down can the error message be seen. 00:14:45
Here is 'getUser' when the page loads initially. The ID and the data are collected, get packed into some HTML and gets send off. This is a PHP site where this 'Create user' is being done. 00:15:16 Then there is a Ajax site in Javascript. As the page loads in the JavaScript, you would get 'User' with the 'User ID' and the User ID from the field and then the data gets loaded. It shows the data which is loaded and that data can be edited except over here(Username). 00:15:51 Numbers can not be added in the username but this(see video) may be done and it will update it and will indicate that it is updated. If there is a error with the email already used it will also show an error. This is how JavaScript had been set up. Javascript has been added to the View file. Here is 'getUser', and the function is displayed. 00:16:24 Usually two functions are used in this case, one that are on standby and eventually setting up the data into the view. This is how the call structure would usually look in index.php?option=your components name, and the task which must go to the Ajax controller. This 'getUser' is the task. 00:16:54 Here can be stipulated in what format you would like the result set returned in. If the result set needs to be returned 'raw', which is sometimes the case, there is a 'raw' variable. 00:17:23 The 'raw' variable may be set to true and it will give the results set just like that without braces around them, or a call back or anything. You will notice that when calls are made from JavaScript, it usually wants this call back to be added. If calls is made from other JavaScript libraries, you might just want the braces around it. But if it is wanted 'raw' which also is often the case, just add the variable 'raw' to the URL = true and then end up passing it back with 'json_encode'.
NB.The format should remain 'json'. 00:17:56
Always use a token. Have the token on the page. This token is necessary to prevent cross site scripting . It is recommended to add the token to the page, through PHP. 00:18:28 If work is done in a back end in the admin area, it is not necessary to add the token as it gets added to the page dynamically, since the JavaScript areas had been parsed . If it shows 'token' then 'token' needs to be there and the token gets added. Whereas in the front end, 'token' should be added manually. For various reasons it had not been automated in the front-end so that the variable00:13:17 name can be changed as well. 00:19:03 Whereas now it is just token, its back end is more secure. Always add a token to the request and check whether the token is there, if it is not, that it would not make a request at all. That is simply how a user is created and how the user concept is integrated within this component.
If you are not fully capable to do programming in JavaScript, jQuery or in PHP, this might not completely resolve your questions. This has not been meant to be a very user friendly component as such but rather a powerful tool to use.
00:19:41 At least this 'Class' had been added by which a user can be created. 00:20:20 If my implementation needs some improvement, Component Builder may be forked on GitHub and copied to your repository and the necessary changes be done to it before pushing it back again. 00:20:47 The place in Component Builder where this 'Class' is constructed, is within the compilers files. Compiler have quite a few files and a search need to be done. Go to Component Builder, go to Helper, and then use the compiler. Here is all its files. A search can be done in there for the function 'Create user'. 00:21:09 As it is dynamically added, it is in that area where the adaption and the changes needs to be done. It can't be edited right in the script, it needs to be edited in the function where it is added. Just search those functions. 00:21:38 That's how to create users and connect them to components.
- 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