Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 151 lines (98 sloc) 6.322 kb
2f7b89d @voidet Added in documentation
authored
1 #CakePHP Sign Me Up Plugin
2
0645dc4 @voidet Updated documentation for password resets
authored
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.
2f7b89d @voidet Added in documentation
authored
4
5 ##Installation
6 Install the plugin:
7
1be90bf @voidet Updated readme
authored
8 cd myapp/app/Plugin/
465a569 @voidet Change to cloning in docs
authored
9 git clone git@github.com:voidet/sign_me_up.git sign_me_up
2f7b89d @voidet Added in documentation
authored
10
1be90bf @voidet Updated readme
authored
11 ##Load the Plugin
12 Next up open up app/Config/bootstrap.php
13 Uncomment/Add the line:
14
3c1a2e8 @voidet Code readme
authored
15 CakePlugin::loadAll(); // Loads all plugins at once
16 Or
17 CakePlugin::load('SignMeUp'); //Loads a single plugin
1be90bf @voidet Updated readme
authored
18
19 ##Attaching
20
d244b88 @voidet Documentation to include behaviour
authored
21 To attach the plugin to a particular model (User/Member/Pimp) simply add in the plugin's component in your chosen controller & model:
2f7b89d @voidet Added in documentation
authored
22
23 class UsersController extends AppController {
24
25 public $components = array('SignMeUp.SignMeUp');
26
0645dc4 @voidet Updated documentation for password resets
authored
27 public function beforeFilter() {
28 $this->Auth->allow(array('login', 'forgotten_password', 'register', 'activate'));
29 parent::beforeFilter();
30 }
31
1be90bf @voidet Updated readme
authored
32 And in the User model app/Model/User.php
d244b88 @voidet Documentation to include behaviour
authored
33
34 class User extends AppModel {
35
36 public $actsAs = array('SignMeUp.SignMeUp');
37
0645dc4 @voidet Updated documentation for password resets
authored
38 Next up create the register, activate & forgotten password methods in your controller via:
2f7b89d @voidet Added in documentation
authored
39
40 public function register() {
41 $this->SignMeUp->register();
42 }
43
44 public function activate() {
45 $this->SignMeUp->activate();
46 }
47
0645dc4 @voidet Updated documentation for password resets
authored
48 public function forgotten_password() {
49 $this->SignMeUp->forgottenPassword();
50 }
51
323e159 @voidet Added in forgotten password functionality as per request.
authored
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:
2f7b89d @voidet Added in documentation
authored
53
1be90bf @voidet Updated readme
authored
54 app/View/Users/register.ctp
55 <?php echo $this->element('register', array(), array('plugin' => 'SignMeUp')); ?>
2f7b89d @voidet Added in documentation
authored
56
1be90bf @voidet Updated readme
authored
57 app/View/Users/activate.ctp
58 <?php echo $this->element('activate', array(), array('plugin' => 'SignMeUp')); ?>
323e159 @voidet Added in forgotten password functionality as per request.
authored
59
1be90bf @voidet Updated readme
authored
60 app/View/Users/forgotten_password_.ctp
61 <?php echo $this->element('forgotten_password', array(), array('plugin' => 'SignMeUp')); ?>
2f7b89d @voidet Added in documentation
authored
62
0645dc4 @voidet Updated documentation for password resets
authored
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
1be90bf @voidet Updated readme
authored
65 Next up the plugin requires that you have a config file in 'app/Config/sign_me_up.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:
2f7b89d @voidet Added in documentation
authored
66
67 <?php
68
69 $config['SignMeUp'] = array(
1be90bf @voidet Updated readme
authored
70 'from' => 'MyDomain.com <admin@exampledomain.com>',
9e021a6 @voidet Added in more documentation for changes made to include Email Component ...
authored
71 'layout' => 'default',
1be90bf @voidet Updated readme
authored
72 'welcome_subject' => 'Welcome to MyDomain.com %username%!',
73 'activation_subject' => 'Activate Your MyDomain.com Account %username%!',
74 'sendAs' => 'html',
9e021a6 @voidet Added in more documentation for changes made to include Email Component ...
authored
75 'activation_template' => 'activate',
76 'welcome_template' => 'welcome',
0645dc4 @voidet Updated documentation for password resets
authored
77 'password_reset_field' => 'password_reset',
323e159 @voidet Added in forgotten password functionality as per request.
authored
78 'password_reset_template' => 'forgotten_password',
79 'password_reset_subject' => 'Password reset from MyDomain.com',
80 'new_password_template' => 'new_password',
81 'new_password_subject' => 'Your new password from MyDomain.com',
1be90bf @voidet Updated readme
authored
82 'xMailer' => 'MyDomain.com Email-bot',
2f7b89d @voidet Added in documentation
authored
83 );
84
9e021a6 @voidet Added in more documentation for changes made to include Email Component ...
authored
85 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:
2f7b89d @voidet Added in documentation
authored
86
87 app/views/layouts/email/text/default.ctp
323e159 @voidet Added in forgotten password functionality as per request.
authored
88
2f7b89d @voidet Added in documentation
authored
89 <?php echo $content_for_layout; ?>
90
1be90bf @voidet Updated readme
authored
91 app/views/elements/email/text/activate.ctp
323e159 @voidet Added in forgotten password functionality as per request.
authored
92
2f7b89d @voidet Added in documentation
authored
93 Welcome <?php echo $user['username']; ?>,
94
95 In order to get started please click on the following link to activate your account:
96
97 <?php echo Router::url(array('action' => 'activate', 'activation_code' => $user['activation_code']), true)."\n"; ?>
98
99 We look forward to seeing you!
1be90bf @voidet Updated readme
authored
100 Regards,
101 MyDomain.com Staff
102
103 app/views/elements/email/text/welcome.ctp
104
105 Welcome <?php echo $user['username']; ?>,
106
107 Thanks for registering! See you inside :)
108
109 We look forward to seeing you!
2f7b89d @voidet Added in documentation
authored
110 Regards,
111 MyDomain.com Staff
112
0645dc4 @voidet Updated documentation for password resets
authored
113 app/views/elements/email/text/forgotten_password.ctp
114
115 Hi <?php echo $user['username']; ?>,
116
117 Someone (hopefully you) has requested a password reset on your account. In order to reset your password please click on the link below:
118
119 <?php echo $this->Html->link('Reset your password', Router::url(array('action' => 'forgotten_password', 'password_reset' => $user['password_reset']), true)); ?>
120
121 Regards,
122 MyDomain.com Staff
123
124 app/views/element/email/text/new_password.ctp
2f7b89d @voidet Added in documentation
authored
125
0645dc4 @voidet Updated documentation for password resets
authored
126 Hello <?php echo $user['username']; ?>,
127
128 A new password has been generated hopefully by you on the MyDomain.com website. Your new password, which you should change immediately is:
129
130 <?php echo $password; ?>
131
132 We look forward to seeing you!
133 Regards,
134 MyDomain.com Staff
135
136 ##The Schema
137
138 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.
139
140 ##Example Routes
141
142 Router::connect('/register', array('controller' => 'users', 'action' => 'register'));
143 Router::connect('/activate', array('controller' => 'users', 'action' => 'activate'));
144 Router::connect('/activate/:activation_code', array('controller' => 'users', 'action' => 'activate'), array('pass' => 'activation_code'));
145 Router::connect('/forgotten_password/:password_reset', array('controller' => 'users', 'action' => 'forgotten_password'), array('pass' => 'password_reset_code'));
146 Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
147 Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));
148
149 ##Note
2f7b89d @voidet Added in documentation
authored
150
0645dc4 @voidet Updated documentation for password resets
authored
151 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.
Something went wrong with that request. Please try again.