summaryrefslogtreecommitdiffstats
path: root/models/confirmKey.php
blob: 6047d2559915942370631f781ce174d36a5b964b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace app\models;


use lithium\util\String;
use lithium\util\Validator;

class confirmKey extends \lithium\data\Model {
	//Comfirmation Key "salt"
	public $secret = "marshmellows"; //I don't know why either?
	
	//To bypass mongo bug
	//protected $_meta = array('key' => '_id');
	//array('isValidKey', 'message' => 'Key does not exist');

	public static function __init()
	{
		//Make sure the class we extend inits.
		parent::__init();                                                                                                      

		//Checks if the key is valid (in the database);
		Validator::add('isValidKey', function($key) {
			//If one key is found that matches the input key, then it's legit
			return confirmKey::count(array('conditions' => compact('key'))) == 1;
		});
	}
	
	//For now, this will remain, but eventually it should just filter the save
	//Method since the confirmation key doesn't really need to be returned to the controller. 
	public function generate($email)
	{
		//Doesn't need to be ultra secure since they just need to click the generated link
		return String::hash($email.$this->secret, array('type' => 'crc32'));
	}

	/*
     * Old Validates function
	public function isValidKey($key)
	{
		//If they key is valid, it should be found in the database
		//If there is 1 key that matches the input key,
		return confirmKey::count(array('conditions' => compact('key'))) == 1;
	}	
	*/	
}
?>