.

FormValidations Class Reference
[Model]

Stores form tokens. More...

List of all members.

Static Public Member Functions

static  create_or_reuse_token ($name)
  Create a token for form of given name or reuse if it was created for this request.
static  create_or_reuse_token_across_requests ($name)
  Create a token for form of given name or reuse if it was created for this request.
static  create_token ($name)
  Create a token for form of given name.
static  remove_expired ()
  Removes expired cache entries.
static  validate_token ($name, $token)
  Validate a given token for form of given name.

Detailed Description

Stores form tokens.

Author:
Gerd Riesselmann

Definition at line 8 of file formvalidations.facade.php.


Member Function Documentation

static FormValidations::create_or_reuse_token ( name  )  [static]

Create a token for form of given name or reuse if it was created for this request.

Definition at line 26 of file formvalidations.facade.php.

00026                                                             {
00027                 $token = RuntimeCache::get(array('reusedtokens', $name));
00028                 if (!$token) {
00029                         $token = self::create_token($name);
00030                         RuntimeCache::set(array('reusedtokens', $name), $token);
00031                 }
00032                 return $token;
00033         }
static FormValidations::create_or_reuse_token_across_requests ( name  )  [static]

Create a token for form of given name or reuse if it was created for this request.

Definition at line 38 of file formvalidations.facade.php.

00038                                                                             {
00039                 $ret = '';
00040 
00041                 $validations = new DAOFormvalidations();
00042                 $validations->name = $name;
00043                 $validations->sessionid = Session::get_session_id();
00044                 if ($validations->find(IDataObject::AUTOFETCH)) {
00045                         if ($validations->is_valid_for_at_least(10)) {
00046                                 $ret = $validations->token;
00047                         }
00048                 }
00049                 if ($ret) {
00050                         return $ret;
00051                 } else {
00052                         return self::create_token($name);
00053                 }
00054         }
static FormValidations::create_token ( name  )  [static]

Create a token for form of given name.

Definition at line 12 of file formvalidations.facade.php.

00012                                                    {
00013                 self::remove_expired();
00014                 
00015                 $token = Common::create_token();
00016                 $validations = self::create_token_instance($name, $token);
00017                 $validations->expirationdate = time() + Config::get_value(Config::FORMVALIDATION_EXPIRATION_TIME) * GyroDate::ONE_MINUTE; // 
00018                 $validations->insert();
00019                 
00020                 return $token;
00021         }
static FormValidations::remove_expired (  )  [static]

Removes expired cache entries.

Definition at line 93 of file formvalidations.facade.php.

00093                                                 {
00094                 $dao = new DAOFormvalidations();
00095                 $dao->add_where('expirationdate', '<', DBFieldDateTime::NOW);
00096                 $dao->delete(DAOFormvalidations::WHERE_ONLY);
00097         }
static FormValidations::validate_token ( name,
token  
) [static]

Validate a given token for form of given name.

Returns:
Boolean

Definition at line 61 of file formvalidations.facade.php.

00061                                                              {
00062                 $ret = false;
00063 
00064                 $validations = self::create_token_instance($name, $token);
00065                 if ($validations->find(IDataObject::AUTOFETCH)) {
00066                         $ret = ($validations->expirationdate > time());
00067                         $validations->delete();
00068                 }
00069                 
00070                 return $ret;
00071         }

The documentation for this class was generated from the following file: