Frontend Users not expiring

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Frontend Users not expiring

Post by Dee »

There's a difference between the DBTimeStamp functions of full ADOdb and Lite and some other issues with the datetime data field. See this thread for some more info.
I might implement the same solutions in FEUsers in the coming days (and look at the other issues that were brought up in this thread).

Regards,
D
mahjong

Re: Frontend Users not expiring

Post by mahjong »

I rewrote the SQL query to bypass completely this issue :

Code: Select all

     
    $q = "SELECT * FROM ".cms_db_prefix()."module_feusers_users WHERE id = ? AND expires > NOW()";
    $dbresult = $db->Execute( $q, array( $uid ) );
Should execute 0.0001s faster. (^_^)
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Frontend Users not expiring

Post by Dee »

Dee wrote: There's a difference between the DBTimeStamp functions of full ADOdb and Lite
More exactly: the ADOdb field type DT only exists in the adodb_lite datadict, not in full/original adodb.
ADOdb uses T for datetime, ADOdb T for time and DT for datetime.

Also, in cmsmadesimple-0.13 an altered ADOdb Lite was used which didn't surround the return value of DBTimeStamp with quotes.
Last edited by Anonymous on Sun Dec 10, 2006 7:19 pm, edited 1 time in total.
mahjong

Re: Frontend Users not expiring

Post by mahjong »

Now I understand the origin of all the bugs. I think everything is solved. I'll post in a few minutes the corrections that need to be added in SVN.
mahjong

Re: Frontend Users not expiring

Post by mahjong »

FrontEndUser.api.php

Code: Select all

  // userid api function
  // returns array
  function AddUser( $name, $password, $expires )
  {
    $db =& $this->GetDb();
    
    // see if it exists already or not (by name)
    $q = "SELECT * FROM ".cms_db_prefix().
      "module_feusers_users WHERE username = ?";
    $dbresult = $db->Execute( $q, array( $name ) );
    if( !$dbresult )
      {
	return array(FALSE,$db->ErrorMsg());
      }
    $row = $dbresult->FetchRow();
    if( $row )
      {
	$module =& $this->GetModule();
	return array(FALSE,$module->Lang('error_username_exists'));
      }
    
    // generate the sequence
    $uid = 
      $db->GenID( cms_db_prefix()."module_feusers_users_seq" );

    // insert the record
    $q = "INSERT INTO ".cms_db_prefix().
      "module_feusers_users VALUES (?,?,?,?,?)";
    $dbresult = $db->Execute( $q, array( 
			$uid, 
			$name, 
			md5($password), 
			trim( $db->DBTimeStamp(   time()   ) , "'") ,
			trim( $db->DBTimeStamp( $expires ) , "'")
		)
	);
    if( !$dbresult )
      {
	return array(FALSE,$db->ErrorMsg());
      }
    return array(TRUE,$uid);
  }

Code: Select all

  function IsAccountExpired( $uid )
  {
    $db =& $this->GetDb();
    
    $q = "SELECT * FROM ".cms_db_prefix()."module_feusers_users WHERE id = ? AND expires > NOW()";
    $dbresult = $db->Execute( $q, array( $uid ) );

    if( $dbresult && $dbresult->RecordCount() )
      {
	return false;
      }

    return true;
  }
mahjong

Re: Frontend Users not expiring

Post by mahjong »

Everything is fine now.

The bugs were caused by missing "trim"s around the "DBTimeStamp"s. See the corrections I've posted.
Last edited by mahjong on Sat Dec 09, 2006 7:30 pm, edited 1 time in total.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Frontend Users not expiring

Post by jmcgin51 »

Ok, so Mahjong, are you saying that the latest SVN version of FrontEndUsers.api.php contains all your updates and is ready to be used?
mahjong

Re: Frontend Users not expiring

Post by mahjong »

No, I'm not authorised to make changes in SVN.

Cut and paste the corrections yourself.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Frontend Users not expiring

Post by jmcgin51 »

ok.  I'll admit I'm a bit confused by all the edits, so I'm going to wait for Dee or one of the other developers to post the changes, and then I'll get the latest version.  My system is working OK now (crossing fingers), so I'll leave it alone for the moment.  Thanks for all your work on this, Mahjong!
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Frontend Users not expiring

Post by jmcgin51 »

oh, dear...

I was incorrect earlier, Mahjong, when I said my system was working properly.  I failed to notice that the user I was testing with was assigned to a group that did not have access to the content.  So it was not the expiration date that prevented him from seeing the content, it was the fact that he was not a member of an authorized group.

To recap, I just created a user TEST, assigned him as a member of all groups, so that he would have access to all content, and set his expire date as 12/1/06 at 17:00:00.  The date shows correctly in the admin panel, but TEST can still log in and view all content, though he should be expired.

Maybe I'll have to look at making the FEU api changes now instead of waiting until they're incorporated into the SVN code...

I feel like such a dunce.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Frontend Users not expiring

Post by jmcgin51 »

I added Mahjong's changes to my FEU api file, and my expired user now cannot log in ("account is expired").

well done, Mahjong!

Calguy - 2 thumbs up for originally writing this module, CustomContent and SelfReg...
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Frontend Users not expiring

Post by Dee »

Added the changes posted by mahjong to SVN.
In the IsAccountExpired method, instead of using the MySQL function NOW(), I also used trim( $db->DBTimeStamp(time()) , "'") so it will also work on other databases like Postgres.

mahjong: thanks again!
mahjong

Re: Frontend Users not expiring

Post by mahjong »

Added the changes posted by mahjong to SVN.
And a few days later, inexplicably, calguy1000 overwrote the fixes in FrontEndUsers.api.php with rev.107  >:(

Please update your working copy before committing changes...
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Frontend Users not expiring

Post by tsw »

shouldn't svn give error about conflicts?

of course one can force the commit...
Post Reply

Return to “CMSMS Core”