User allowed to set desired start page

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

User allowed to set desired start page

Post by bruceholt » 2019-06-09 07:51

I am wanting to allow users select their own start page after signing in.

Instead of redirecting to index.php, they can select from a list of pages in a table and save their preference so that when they log in, they are automatically redirected to that page.

I am wondering if the _global.php hooks file could be utilized and modify this code with if statements.

Code: Select all

	function login_ok($memberInfo, &$args){

		if($memberInfo['username'] || $mi['username'])
   return 'index.php';
        else
		return '';
	}

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

Re: User allowed to set desired start page

Post by pbottcher » 2019-06-09 08:20

Hi,

yes you can use something like this pseudocode.

function login_ok($memberInfo, &$args){

catch USERPAGE for $memberInfo['username'] // maybe via an sql query from a config table.
redirect("USERPAGE");
}
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.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: User allowed to set desired start page

Post by bruceholt » 2019-06-09 22:15

Thanks for the reply.

I'm a bit of a hack and not an expert. Any ideas on how to implement this?

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

Re: User allowed to set desired start page

Post by pbottcher » 2019-06-10 09:33

Hi,

the question is, how would you let the user decide which page to start with.
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.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: User allowed to set desired start page

Post by bruceholt » 2019-06-11 08:02

Hi,

I was thinking of creating a table which the user can select from a drop down list of the main table view tables. I might be making things more difficult than they need to be?

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

Re: User allowed to set desired start page

Post by onoehring » 2019-06-13 05:57

Hi bruce,

I would think it's a good idea (creating a table to choose from). That should be able to handle all future changes on your application.

Olaf

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

Re: User allowed to set desired start page

Post by pbottcher » 2019-06-13 06:38

Hi,

so fi you have your table (lets assume it is called "USERHOME" and within this table you have a field called "HOMEPAGE" and you user the
memeberID as matching key.

You could do:

Code: Select all

function login_ok($memberInfo, &$args){

$userpage = sqlvalue("SELECT HOMEPAGE from USERHOME where memberID = '".$memberInfo['memberID']."'");
if (isset($userpage) && $userpage != '') redirect($userpage);
}
HOMEPAGE needs to be set to the url you want the user to be redirected to.
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.


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

Re: User allowed to set desired start page

Post by onoehring » 2019-06-13 08:24

Hi pbötcher,
little bug(s) in your code. Probably should be ...

Code: Select all

$userpage = sqlValue(""SELECT HOMEPAGE from USERHOME where memberID = '".$memberInfo['username']."'");

if (isset($userpage) && $userpage != '') 
{
	return $userpage;
 }
 	else
	{
		return '';
	}
Actually it seems wise to have one table for usersettings and another for possible startpages. In this case - of course, the SQL would be different, something like this:

Code: Select all

$userpage = sqlValue("Select tbl_Startpages.StartpageURL From tbl_Startpages Inner Join tbl_Usersettings On tbl_Usersettings.ID_StartpageTxt = tbl_Startpages.ID_StartpageTxt Where tbl_Usersettings.ID_Usersettings = '".$memberInfo['username']."'");
Olaf

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: User allowed to set desired start page

Post by bruceholt » 2019-06-13 09:19

Hi pbötcher and Olaf,

I will try this out, hopefully on the weekend, and let you both know how I went.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: User allowed to set desired start page

Post by bruceholt » 2019-06-16 03:34

Hi Olaf,

I have set up the tables (as per your second suggestion) as shown in the attached image, but I am confused where I go from here. How do I allow each user to select just one page to be redirected to?

Image

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

Re: User allowed to set desired start page

Post by onoehring » 2019-06-16 06:35

Hi bruceholt,

actually, at this time the regular "user" can not access this table, only admins can. If you want the user to be able to change this, I suggest that ID_Usersettings (which holds the memberID = loginname of the user) is set to readonly and autofill with username.

The problem in my setting is, that ID_Usersettings is a textfield, not a dropdown (which reads all usernames from the member_users table). Unfortunately it seems to be impossible to use AG internal tools to receive a memberlist from there and easily fill it into something else. There is probably a possibility, but not a very easy one I believe.

The ID_StpageTxt pulls a 2nd column from the startpage table which contains a "cleartext" name of the page to go to "Main", "Tools" ... and, to finally answer your question: Of course each user can have only one page to be forwarded to after login. Either "Main" or "Tools" or ...

More questions? Shoot.
Olaf

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

Re: User allowed to set desired start page

Post by onoehring » 2019-06-16 06:52

Hi,
forgot. In AG it seem "impossible" to create 1:1 relations between tables (I myself had a question about this a couple days ago).
If you create this table and give users access to it, maybe prepare it for each user (using some SQL somewhere else to fill in default values). Then, you give edit right to the users only for their own records (where you need to make sure, that each record is being connected to it's use, again by SQL somewhere automatically).
You could also try pbötchers suggestion ( viewtopic.php?f=6&t=3059&p=10176#p10172 ) and transform this to startpage (in the thread it's about user specific language. By now I added a language field to my Usersettings table. I can have as many user specific settings as I want to this way).

Olaf

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: User allowed to set desired start page

Post by bruceholt » 2019-06-16 07:39

Thanks very much Olaf, I really appreciate your help. I'll keep playing around and see how I go with it.

Post Reply