Modifying login page

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Modifying login page

Post by dlee » 2020-04-22 16:19

I need to add an additional field to the login page. What I have so far is I manually added the html code, for the additional field, to login.php then made the login.php file readonly.

My two questions are:
1 - Is it acceptable to make a file readonly in order to keep Appgini from overwritting it?

2- Is there a more appropriate way to add the html code rather than the way I did it?

Thanks,
TD

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Modifying login page

Post by pbottcher » 2020-04-22 18:40

Hi,

1, the danger by making the file read-only for AppGini to not overwrite it is, that with an updated version and "necessary" modification to that file, you will miss it.

2, You can use the hooks/header-extra.php file to do your changes.
- check if you are on the login page
- apply your modification.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Modifying login page

Post by dlee » 2020-04-23 01:44

Thanks for helping. Can you direct me to an example of what the code would look like to prepend html code to exisiting login page code?

TD


dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Modifying login page

Post by dlee » 2020-04-23 14:51

Thank you for helping. I am not sure what the final difference this approach provides over just making the customized files read-only. I am told by support that you can use header-extras.php and footer-extras.php to modify the html on pages but I so far haven't found an example to help me get started. Perhaps I haven't looked enough so far but as I keep looking if anyone knows of such examples please share them.

Thanks again for trying to help,
TD

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1160
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Modifying login page

Post by onoehring » 2020-04-23 15:34

Hi,

just try. Add something (like: AAAAAAAAAAA) to header-extras.php and reload your page, see what happens.
header-extras is read by php when the page will be created. The contents will be added to (all) your pages.

Olaf

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Modifying login page

Post by dlee » 2020-04-23 15:43

I'll take a shot at it but I need to limit the changes to a particular page. Somewhere I saw code that allowed you to identity the page you wanted the code to be applied to, can you direct me to that code? I never could find it again.

Thanks again,
TD

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1160
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Modifying login page

Post by onoehring » 2020-04-23 16:14

Hi,

look in the /hooks/tablename.php -> _init function. There you can change the header for that table and for tableview, detailview etc. It's already in the function, you just need to add your own code to the specific switch-statement.
Please note, the comment to this, that is: If you add your header code there, header-extras is not used EXECPT you include it also with %header%

Olaf

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Modifying login page

Post by dlee » 2020-04-23 16:25

Thank you, I'll go look there now. BTW, are the files in the hocks folder ever overwritten by Appgini?

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Modifying login page

Post by dlee » 2020-04-23 20:46

Finally got it, thanks to the help I received here and watching the "Customizing the Appearance of the login page" video at Udemy.com.

Here is the code:

/hooks/footer-extras.php:

Code: Select all

<?php 
    $Script_name = basename($_SERVER['PHP_SELF']);
    if ($Script_name == 'index.php' && isset($_GET['signIn'])) {
?>
    <script>
	var deptId_fld = '<div class="form-group">';
	deptId_fld += '<label class="control-label" for="dept_id"><?php echo 'Department ID'; ?></label>';
	deptId_fld += '<input class="form-control" name="dept_id" id="dept_id" type="text" placeholder="<?php echo 'Department ID'; ?>" required>';
	deptId_fld += "</div>";
	$j('form').prepend(deptId_fld);		
	$j("#dept_id").focus();
    </script>
<?php
    }
?>
Notice that I am prepending my code to the html FORM tag using JQuery. If this page had had more than one form on it then this would not have worked.

/hooks/_global.php

Code: Select all

<?php
    function login_ok($memberInfo, &$args) {
        $_SESSION['dept_id'] = $_POST['dept_id'];
	return '';
    }
?>
This code stores the dept_id in a session variable so it is available throughout the app.

/hooks/apparatus.php

Code: Select all

<?php
    function apparatus_init(&$options, $memberInfo, &$args) {
        $dept_id = $_SESSION['dept_id'];
	$options->QueryWhere = 'WHERE `apparatus`.`dept_id` = '.$dept_id;
	return TRUE;
	}
?>
This code needs to be applied to every table in the app as it limits the records shown the user to just his dept_id. Be sure to change the table name and session variable name as needed.

Image

Hope this helps someone else,
TD

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1160
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Modifying login page

Post by onoehring » 2020-04-24 07:39

Hi,

thanks for sharing.

Just a thought:
But: Why do you want the department id? This should be tied to the user in an internal table, so you can always look it up after the user has logged in.
Or: Simply use usergroupd and let people see only records from their group (e.g. department).

Olaf

Post Reply