confirmKey.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\models;
  3. use lithium\util\String;
  4. use lithium\util\Validator;
  5. class confirmKey extends \lithium\data\Model {
  6. //Comfirmation Key "salt"
  7. public $secret = "marshmellows"; //I don't know why either?
  8. //To bypass mongo bug
  9. //protected $_meta = array('key' => '_id');
  10. //array('isValidKey', 'message' => 'Key does not exist');
  11. public static function __init()
  12. {
  13. //Make sure the class we extend inits.
  14. parent::__init();
  15. //Checks if the key is valid (in the database);
  16. Validator::add('isValidKey', function($key) {
  17. //If one key is found that matches the input key, then it's legit
  18. return confirmKey::count(array('conditions' => compact('key'))) == 1;
  19. });
  20. }
  21. //For now, this will remain, but eventually it should just filter the save
  22. //Method since the confirmation key doesn't really need to be returned to the controller.
  23. public function generate($email)
  24. {
  25. //Doesn't need to be ultra secure since they just need to click the generated link
  26. return String::hash($email.$this->secret, array('type' => 'crc32'));
  27. }
  28. /*
  29. * Old Validates function
  30. public function isValidKey($key)
  31. {
  32. //If they key is valid, it should be found in the database
  33. //If there is 1 key that matches the input key,
  34. return confirmKey::count(array('conditions' => compact('key'))) == 1;
  35. }
  36. */
  37. }
  38. ?>