confirmKey.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. return confirmKey::count(array('conditions' => compact('key'))) == 1;
  18. });
  19. }
  20. //For now, this will remain, but eventually it should just filter the save
  21. //Method since the confirmation key doesn't really need to be returned to the controller.
  22. public function generate($email)
  23. {
  24. //Doesn't need to be ultra secure since they just need to click the generated link
  25. return String::hash($email.$this->secret, array('type' => 'crc32'));
  26. }
  27. /*
  28. * Old Validates function
  29. public function isValidKey($key)
  30. {
  31. //If they key is valid, it should be found in the database
  32. //If there is 1 key that matches the input key,
  33. return confirmKey::count(array('conditions' => compact('key'))) == 1;
  34. }
  35. */
  36. }
  37. ?>