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

Amigo 2019-07-01 11:53:11 +02:00
parent 8ca17d1dbe
commit a02dabca6a
1 changed files with 7 additions and 6 deletions

@ -28,20 +28,21 @@ In previous tutorials it had been explained how to make use of the Ajax concept
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m04s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m31s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m05s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m31s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m07s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m39s) Here 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.
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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m05s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m31s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m07s) 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m39s) 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.
### 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: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(see video) is the error message. [00:14:45](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m45s)<<<<<<<<<<<<<<<<<<<<<<<<<
[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
And then here is getUser when the page loads initially. We get the id, we get the data. Packs it into some html and sends it off. This is the php site obviously where we do this create user. Then there is a ajax [00:15:16](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15rm16s) site in Javascript. In the JavaScript when the page loads, you would get user with the user id, we get the user id from the field. And then it loads that data that you saw. Basically shows you that is the data it loads. 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) You cannot add numbers in the username but you can do that(see video) and it will update it as you see and will say that it is updated. 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. I've just added Javascript to the view file. Here is getuser on the server site, and there is the function. [00:16:24](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m24s) I have two functions usually one that deals with waiting and then eventually setting up the data into the view. Here is the one making the call. 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. And then this(getuser) is the task. [00:16:54](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m54s) And here you can stipulate what format you would like the result set returned in. If you want the result set returned raw, which in is sometimes 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](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m23s) 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. [00:17:56](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m56s) The format must stay json, that's important.
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. And then 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. The raw variable may be set to true.<<<<<<<<<<<<<<<
Then it will give you the results set just like that without braces around them, [00:17:23](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m23s) 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. [00:17:56](https://www.youtube.com/watch?v=ckFakaQ90JY&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m56s) The format must stay json, that's important.
### Use Tokens