1: <?php
2:
3: class UsersController extends AppController {
4:
5: public $scaffold;
6:
7: public $components = array(
8: 'ExtendedScaffold.ScaffoldUtil' => array(
9: 'indexUnsetFields' => array(
10: 'id',
11: 'password',
12: 'modified',
13: ),
14: 'viewUnsetFields' => array(
15: 'id',
16: 'password',
17: ),
18: 'editUnsetFields,addUnsetFields' => array(
19: 'password',
20: )
21: ),
22: );
23:
24:
25: public function beforeFilter() {
26: parent::beforeFilter();
27:
28: if (!$this->Components->loaded('Authentication.Authentication')) {
29: $this->Authentication = $this->Components->load(
30: 'Authentication.Authentication'
31: , array(
32: 'userModel' => 'UserAccounts.User',
33: 'usernameField' => 'email',
34: 'emailField' => 'email',
35: 'activeField' => 'active'
36: )
37: );
38: $this->Authentication->initialize($this);
39: }
40:
41: if ($this->request->action == 'add' && $this->request->isPost()) {
42: $this->currentPassword = $this->Authentication->generateRandomPassword();
43: $this->request->data['User']['password'] = $this->currentPassword;
44: }
45: }
46:
47: public function beforeRender() {
48: parent::beforeRender();
49:
50: if (!isset($this->request->data['User']['active'])) {
51: $this->request->data['User']['active'] = true;
52: }
53: }
54:
55: public function afterScaffoldSave($method) {
56: if (!parent::afterScaffoldSave($method)) {
57: return false;
58: }
59:
60: if ($method == 'add' && $this->Components->enabled('Auth')) {
61: $this->Authentication->sendSelfUserCreationNotification(
62: $this->User->id, $this->currentPassword
63: );
64: }
65:
66: return true;
67: }
68:
69: }
70:
71: ?>
72: