Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
 
3
class SignMeUpBehavior extends ModelBehavior {
4
 
5
	public $validate = array(
6
		'username' => array(
7
			'pattern' => array(
8
				// 'rule' => array('custom','/[a-zA-Z0-9\_\-]{4,30}$/i'),
9
				'rule' => array('email',true),
10
				'message'=> 'Usernames must be 4 characters or longer with no spaces.'
11
			),
12
			'usernameExists' => array(
13
				'rule' => 'isUnique',
14
				'message' => 'Sorry, this username already exists'
15
			),
16
		),
17
		'email' => array(
18
			'validEmail' => array(
19
				'rule' => array('email', true),
20
				'message' => 'Please supply a valid & active email address'
21
			),
22
			'emailExists' => array(
23
				'rule' => 'isUnique',
24
				'message' => 'Sorry, this email address is already in use'
25
			),
26
		),
27
		'password1' => array(
28
			'minRequirements' => array(
29
				'rule' => array('minLength', 6),
30
				'message' => 'Passwords need to be at least 6 characters long'
31
			),
32
			'match' => array(
33
				'rule' => array('confirmPassword', 'password1', 'password2'),
34
				'message' => 'Passwords do not match'
35
			),
36
		),
37
	);
38
 
39
	public function beforeValidate(&$Model) {
40
		$this->model = $Model;
41
		$this->model->validate = array_merge($this->validate, $this->model->validate);
42
		return true;
43
	}
44
 
45
	public function confirmPassword($field, $password1, $password2) {
46
		if ($this->model->data[$this->model->alias]['password1'] == $this->model->data[$this->model->alias]['password2']) {
47
			$this->model->data[$this->model->alias]['password'] = Security::hash($this->model->data[$this->model->alias]['password1'], null, true);
48
			return true;
49
		}
50
	}
51
 
52
	public function generateActivationCode($data) {
53
		return Security::hash(serialize($data).microtime().rand(1,100), null, true);
54
	}
55
 
56
}
57
 
58
?>