Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
#CakePHP Sign Me Up Plugin
2
 
3
Sign Me Up is a CakePHP plugin that takes out 99% of the work needed to develop a user registration, activation & forgotten passwords system. The plugin is easily installed and settings/methods can be easily overwritten to provide custom validation etc.
4
 
5
##Installation
6
Install the plugin:
7
 
8
	cd myapp/app/Plugin/
9
	git clone git@github.com:voidet/sign_me_up.git sign_me_up
10
 
11
##Load the Plugin
12
Next up open up app/Config/bootstrap.php
13
Uncomment/Add the line:
14
 
15
	CakePlugin::loadAll(); // Loads all plugins at once
16
		Or 
17
	CakePlugin::load('SignMeUp'); //Loads a single plugin
18
 
19
##Attaching
20
 
21
To attach the plugin to a particular model (User/Member/Pimp) simply add in the plugin's component in your chosen controller & model:
22
 
23
	class UsersController extends AppController {
24
 
25
		public $components = array('SignMeUp.SignMeUp');
26
 
27
		public function beforeFilter() {
28
			$this->Auth->allow(array('login', 'forgotten_password', 'register', 'activate'));
29
			parent::beforeFilter();
30
		}
31
 
32
And in the User model app/Model/User.php
33
 
34
	class User extends AppModel {
35
 
36
		public $actsAs = array('SignMeUp.SignMeUp');
37
 
38
Next up create the register, activate & forgotten password methods in your controller via:
39
 
40
	public function register() {
41
		$this->SignMeUp->register();
42
	}
43
 
44
	public function activate() {
45
		$this->SignMeUp->activate();
46
	}
47
 
48
	public function forgotten_password() {
49
		$this->SignMeUp->forgottenPassword();
50
	}
51
 
52
Sign Me Up also comes with 3 elements for your views, which don't have to be used. However in your views feel free to use the elements to create the Registration, Activation and Forgotten Password forms as:
53
 
54
	app/View/Users/register.ctp
55
		<?php echo $this->element('register', array(), array('plugin' => 'SignMeUp')); ?>
56
 
57
	app/View/Users/activate.ctp
58
		<?php echo $this->element('activate', array(), array('plugin' => 'SignMeUp')); ?>
59
 
60
	app/View/Users/forgotten_password_.ctp
61
		<?php echo $this->element('forgotten_password', array(), array('plugin' => 'SignMeUp')); ?>
62
 
63
Currently Forgotten Passwords are based on the user's email address entered into the form. If there is any request for this to be based on another field I will review.
64
 
65
Next up the plugin requires that you have a config file in 'app/Config/email.php'. SignMeUp configuration allows you to overwrite all default CakePHP email parameters by simply specifying the elements in the SignMeUp configuration array i.e change email sending to HTML format via setting the sendAs to HTML or change the email layout with 'layout' => 'myLayout'. The only thing that you would need to diverge from the Email Component settings with is the welcome and activate templates. You can set them with welcome_template and activation_template elements. SignMeUp 2.0 uses CakeEmail, so you will need to add in your email settings into app/Config/email.php under the $signMeUp config:
66
 
67
	public $signMeUp = array(
68
		'activation_field' => 'activation_code',
69
		'useractive_field' => 'active',
70
		'login_after_activation' => false,
71
		'welcome_subject' => 'Welcome',
72
		'activation_subject' => 'Please Activate Your Account',
73
		'password_reset_field' => 'password_reset',
74
		'username_field' => 'username',
75
		'email_field' => 'email',
76
		'email_layout' => 'default',
77
 		'password_field' => 'password',
78
		'from' => 'MyDomain.com <admin@exampledomain.com>',
79
		'layout' => 'default',
80
		'welcome_subject' => 'Welcome to MyDomain.com %username%!',
81
		'activation_subject' => 'Activate Your MyDomain.com Account %username%!',
82
		'sendAs' => 'html',
83
		'activation_template' => 'activate',
84
		'welcome_template' => 'welcome',
85
		'password_reset_template' => 'forgotten_password',
86
		'password_reset_subject' => 'Password Reset Request',
87
		'new_password_template' => 'recovered_password',
88
		'new_password_subject' => 'Your new Password'
89
	);
90
 
91
Also note you can include fields in the subject line from your user model. Simply specify the field name you want placed in the subject line with %field_name%. Apart from that the only other things required is that you set up the email layout & views, examples being:
92
 
93
app/views/layouts/email/text/default.ctp
94
 
95
	<?php echo $content_for_layout; ?>
96
 
97
app/views/elements/email/text/activate.ctp
98
 
99
	Welcome <?php echo $user['username']; ?>,
100
 
101
	In order to get started please click on the following link to activate your account:
102
 
103
	<?php echo Router::url(array('action' => 'activate', 'activation_code' => $user['activation_code']), true)."\n"; ?>
104
 
105
	We look forward to seeing you!
106
	Regards,
107
	MyDomain.com Staff
108
 
109
app/views/elements/email/text/welcome.ctp
110
 
111
	Welcome <?php echo $user['username']; ?>,
112
 
113
	Thanks for registering! See you inside :)
114
 
115
	We look forward to seeing you!
116
	Regards,
117
	MyDomain.com Staff
118
 
119
app/views/elements/email/text/forgotten_password.ctp
120
 
121
	Hi <?php echo $user['username']; ?>,
122
 
123
	Someone (hopefully you) has requested a password reset on your account. In order to reset your password please click on the link below:
124
 
125
	<?php echo $this->Html->link('Reset your password', Router::url(array('action' => 'forgotten_password', 'password_reset' => $user['password_reset']), true)); ?>
126
 
127
	Regards,
128
	MyDomain.com Staff
129
 
130
app/views/element/email/text/new_password.ctp
131
 
132
	Hello <?php echo $user['username']; ?>,
133
 
134
	A new password has been generated hopefully by you on the MyDomain.com website. Your new password, which you should change immediately is:
135
 
136
	<?php echo $password; ?>
137
 
138
	We look forward to seeing you!
139
	Regards,
140
	MyDomain.com Staff
141
 
142
##The Schema
143
 
144
In order to set up your users table for activation, registration, or forgotten passwords, please refer to the configuration above. For example if you want to have the forgotten password functionality, you need to have a field in your DB called password_reset, or whatever you choose in your configuration. Both password reset fields, or activation fields should be varchar with a length of 40.
145
 
146
##Example Routes
147
 
148
	Router::connect('/register', array('controller' => 'users', 'action' => 'register'));
149
	Router::connect('/activate', array('controller' => 'users', 'action' => 'activate'));
150
	Router::connect('/activate/:activation_code', array('controller' => 'users', 'action' => 'activate'), array('pass' => 'activation_code'));
151
	Router::connect('/forgotten_password, array('controller' => 'users', 'action' => 'forgotten_password'));
152
	Router::connect('/forgotten_password/:password_reset', array('controller' => 'users', 'action' => 'forgotten_password'), array('pass' => 'password_reset_code'));
153
	Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
154
	Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));
155
 
156
##Note
157
 
158
Any extra validations in your model will be used instead of the ones included in Sign Me Up. So if you don't like the validations that come with the plugin, simply create your own in the model.