Subversion Repositories SmartDukaan

Rev

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

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