Page 1 of 1

User allowed to set desired start page

Posted: 2019-06-09 07:51
by bruceholt
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 '';
	}

Re: User allowed to set desired start page

Posted: 2019-06-09 08:20
by pbottcher
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");
}

Re: User allowed to set desired start page

Posted: 2019-06-09 22:15
by bruceholt
Thanks for the reply.

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

Re: User allowed to set desired start page

Posted: 2019-06-10 09:33
by pbottcher
Hi,

the question is, how would you let the user decide which page to start with.

Re: User allowed to set desired start page

Posted: 2019-06-11 08:02
by bruceholt
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?

Re: User allowed to set desired start page

Posted: 2019-06-13 05:57
by onoehring
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

Re: User allowed to set desired start page

Posted: 2019-06-13 06:38
by pbottcher
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.

Re: User allowed to set desired start page

Posted: 2019-06-13 07:02
by onoehring
Hi pbötcher,

thanks for the code.
Olaf

Re: User allowed to set desired start page

Posted: 2019-06-13 08:24
by onoehring
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

Re: User allowed to set desired start page

Posted: 2019-06-13 09:19
by bruceholt
Hi pbötcher and Olaf,

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

Re: User allowed to set desired start page

Posted: 2019-06-16 03:34
by bruceholt
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

Re: User allowed to set desired start page

Posted: 2019-06-16 06:35
by onoehring
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

Re: User allowed to set desired start page

Posted: 2019-06-16 06:52
by onoehring
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

Re: User allowed to set desired start page

Posted: 2019-06-16 07:39
by bruceholt
Thanks very much Olaf, I really appreciate your help. I'll keep playing around and see how I go with it.