Page 1 of 1

Login directly to Table View

Posted: 2020-07-03 18:24
by Moh Youba
Hello team how are you doing here, I hope you all are doing great.

Please I need a help.

I have a project with table *registration*, how can I set my app that when users login the table *registration* open in *table view*

Thank you

Re: Login directly to Table View

Posted: 2020-07-03 18:56
by pbottcher
Hi,

you can use the hooks/__global.php -> login_ok function. just return the correct url.

See https://bigprof.com/appgini/help/advanc ... obal-hooks

Re: Login directly to Table View

Posted: 2020-07-03 19:33
by Moh Youba
Hi sir

Thank you for your help. Working fine.

Best regards

Re: Login directly to Table View

Posted: 2020-07-08 23:57
by ronwill
I have used this method
pböttcher wrote:
2020-07-03 18:56
Hi,

you can use the hooks/__global.php -> login_ok function. just return the correct url.

See https://bigprof.com/appgini/help/advanc ... obal-hooks
With following code:

Code: Select all

	function login_ok($memberInfo, &$args){

        if($memberInfo['group']=="clients")
	return 'clients_view.php?SelectedID=#ID#';
        else
        return "";
It works fine, however can it be made more 'clever' so that if, as in my scenario a new user gets redirected to a registration form to complete. Then once a 'record' exists for that user, then the next time user logs in the default redirect (to index.php) is applied and not the redirect?
If no record exists (i.e. user did not save one on last login/visit) then the redirect still applies.

It's not a must have but would be nice if possible!
Cheers, Ron

Re: Login directly to Table View

Posted: 2020-07-09 05:23
by pbottcher
Hi,

I assume you save the registration form in the database. So just add a check to see if there is an existing entry in the membership_userrecords for that user and that table you store the registration form in.
If a record exists, no need to do something, otherwise forward to the registration form.

Re: Login directly to Table View

Posted: 2020-07-09 10:11
by ronwill
Yes the record is saved in the database but I'm ot sure how to write the conditional check for this.

Re: Login directly to Table View

Posted: 2020-07-09 11:03
by ronwill
I've been trying with this, but not getting it to work yet:

Code: Select all

	function login_ok($memberInfo, &$args){

   if($memberInfo['group']=="clients") 
	   $getrecordcount = sqlValue("select COUNT(customers) FROM membership_userrecords WHERE tableName = 'customers' AND memberID = '$memberid1' ");
if ($getrecordcount > 0) return 'index.php';
		else
		return "customers_view.php?SelectedID=#ID#";

Re: Login directly to Table View

Posted: 2020-07-09 12:16
by jsetzer

Code: Select all

// ...
$tableName = 'customers';
$sql = "SELECT COUNT(*) 
  FROM `membership_userrecords` WHERE `tableName` = '{$tableName}' 
  AND `memberID` = '{$memberInfo["username"]}'";
$getrecordcount = sqlValue($sql);
// ...

Re: Login directly to Table View

Posted: 2020-07-09 13:19
by ronwill
Thanks Jan,

As always your help and assistance is greatly appreciated, I've used your solution and my code looks like this now and all working perfectly.

Code: Select all

	function login_ok($memberInfo, &$args){
		
   if($memberInfo['group']=="clients") 
$tableName = 'customers';
$sql = "SELECT COUNT(*) 
  FROM `membership_userrecords` WHERE `tableName` = '{$tableName}' 
  AND `memberID` = '{$memberInfo["username"]}'";
$getrecordcount = sqlValue($sql);
if ($getrecordcount == 0) return 'customers_view.php?SelectedID=#ID#';
		else
if ($getrecordcount > 0) return "index.php";
It's a very good addition to my project as clients would become frustrated always ending up on the registration form (customers) when they have already completed one.

Many thanks once again,
Ron

Re: Login directly to Table View

Posted: 2020-07-09 14:34
by ronwill
Sorry I pasted wrong code solution in above (It works but not in all user cases as members of other groups also get sent to the redirect page even when they have already registered, code now covers all logins/groups with a redirect only when no registration has been completed - admin also have to register to avoid redirect).

This is now correct/working (for me) code:

Code: Select all

	function login_ok($memberInfo, &$args){
		
$tableName = 'customers';
$sql = "SELECT COUNT(*) 
  FROM `membership_userrecords` WHERE `tableName` = '{$tableName}' 
  AND `memberID` = '{$memberInfo["username"]}'";
$getrecordcount = sqlValue($sql);
if ($getrecordcount < 1) return 'customers_view.php?SelectedID=#ID#';
		else
return "";