Updated 024 How to integrate the Create User Helper Method in your Components (markdown)

Amigo 2019-07-16 15:12:25 +02:00
parent 04a834a061
commit 0de2d64287

@ -1,18 +1,25 @@
# HOW TO INTEGRATE THE CREATE USER HELPER METHOD IN YOUR COMPONENTS
[00:00:00](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
What is the User Creation function? [00:00:18](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m18s) It is basically a part of code's helper function that gets added to the Helper class.
What is the User Creation function? It is basically a part of code's helper function that gets added to the Helper class.
### Helper Class
[00:00:32](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m32s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m55s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m28s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m11s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m44s) 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'.
### Create User
[00:03:00](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m00s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m26s) '$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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m00s) 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.
### Expert Field
[00:04:30](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m30s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m55s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m26s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m05s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m40s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m24s)
@ -22,6 +29,8 @@ If this closed, open a 'New client'. The same values can be seen. [00:08:44](htt
### Make Use Of The Ajax Concept
[00:09:30](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m30s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m26s)
Return to the Expert view.
@ -32,19 +41,24 @@ It uses the Joomla's default filtering method in a way that it gets values that
### Global Helper Class
[00:13:17](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m17s)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:17](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m17s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m55s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m17s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m45s)
### Get User Field
[00:14:53](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m53s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15rm16s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m51s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m24s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m54s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m23s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m56s)
### Use Tokens
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m28s) 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 variable name can be changed as well. [00:19:03](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m03s) 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.
[00:18:01](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m01s)
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m28s) 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 variable[00:13:17](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m17s) name can be changed as well. [00:19:03](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m03s) 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.