3 Ryzom Core Web-Based Translation Tool
4 Copyright (C) 2011 Piotr Kaczmarek <p.kaczmarek@openlink.pl>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 class UsersController
extends AppController
{
25 var $components = array('Email');
28 $this->User
->recursive
= 0;
29 $this->set('users', $this->paginate());
32 function view($id = null) {
34 $this->Session
->setFlash(__('Invalid user', true));
35 $this->redirect(array('action' => 'index'));
37 $this->set('user', $this->User
->read(null, $id));
40 function admin_index() {
41 $this->User
->recursive
= 0;
42 $this->set('users', $this->paginate());
45 function admin_view($id = null) {
47 $this->Session
->setFlash(__('Invalid user', true));
48 $this->redirect(array('action' => 'index'));
50 $this->set('user', $this->User
->read(null, $id));
53 function admin_add() {
54 if (!empty($this->data
)) {
55 $this->User
->create();
56 if ($this->User
->save($this->data
)) {
57 $this->Session
->setFlash(__('The user has been saved', true));
58 $this->redirect(array('action' => 'index'));
60 $this->Session
->setFlash(__('The user could not be saved. Please, try again.', true));
65 function admin_edit($id = null) {
66 if (!$id && empty($this->data
)) {
67 $this->Session
->setFlash(__('Invalid user', true));
68 $this->redirect(array('action' => 'index'));
70 if (!empty($this->data
)) {
71 if ($this->User
->save($this->data
)) {
72 $this->Session
->setFlash(__('The user has been saved', true));
73 $this->redirect(array('action' => 'index'));
75 $this->Session
->setFlash(__('The user could not be saved. Please, try again.', true));
78 $this->set('user', $user_data = $this->User
->read(null, $id));
79 if (empty($this->data
)) {
80 $this->data
= $user_data;
84 function admin_delete($id = null) {
86 $this->Session
->setFlash(__('Invalid id for user', true));
87 $this->redirect(array('action'=>'index'));
89 if ($this->User
->delete($id)) {
90 $this->Session
->setFlash(__('User deleted', true));
91 $this->redirect(array('action'=>'index'));
93 $this->Session
->setFlash(__('User was not deleted', true));
94 $this->redirect(array('action' => 'index'));
98 if (!empty($this->data
))
100 $user = $this->User
->find('first', array('conditions' => array('User.username' => $this->data
['User']['username'])));
102 if ($user['User']['confirm_hash'])
104 $this->Session
->delete('Message.auth');
105 $this->Session
->setFlash('This account is not yet confirmed. Please use confirmation link from email to finalize registration.');
106 $this->redirect($this->referer());
108 if (!$user['User']['activated'])
110 $this->Session
->delete('Message.auth');
111 $this->Session
->setFlash('This account is not yet activated. Please wait until administrator activates your account.');
112 $this->redirect($this->referer());
116 if (!(empty($this->data
)) && $this->Auth
->user())
119 $this->User
->id
= $this->Auth
->user('id');
120 $this->User
->saveField('last_login', date('Y-m-d H:i:s'));
121 $this->redirect($this->Auth
->redirect());
127 $this->redirect($this->Auth
->logout());
130 function beforeFilter() {
131 parent
::beforeFilter();
132 $this->Auth
->allow(array('register', 'login', 'logout', 'confirm'));
135 function register() {
136 if(!empty($this->data
)) {
137 $this->User
->create();
138 $this->data
['User']['password'] = $this->Auth
->password($this->data
['User']['passwd']);
139 $this->data
['User']['confirm_hash'] = $this->Auth
->password($this->data
['User']['name'] . time());
140 if($user = $this->User
->save($this->data
)) {
141 // send signup email containing password to the user
142 $this->Email
->from
= 'webtt-noreply@openlink.pl';
143 $this->Email
->to
= $user['User']['email'];
144 $this->Email
->subject
= 'WebTT registration';
145 $this->Email
->sendAs
= 'text';
146 $this->Email
->template
= 'registration';
147 $this->set('user', $this->data
);
148 $this->set('serverName', $_SERVER['SERVER_NAME']);
149 $this->params
['url']['ext'] = 'no_debug';
150 unset($this->helpers
['DebugKit.Toolbar']);
151 $this->Email
->send();
152 $this->Session
->setFlash('Thank you for registrating. Please use confirmation link from email to finalize registration.');
153 $this->redirect('/');
158 function confirm($confirm_hash)
160 $user = $this->User
->find('first', array('conditions' => array('User.confirm_hash' => $confirm_hash)));
163 $this->Session
->setFlash('No user found. Please register again.');
164 $this->redirect('/');
166 $this->User
->id
= $user['User']['id'];
167 $this->User
->save(array('confirm_hash' => null));
168 $this->Session
->setFlash('Thank you for registrating. You will be able to log in after your account is activated by administrator.');
169 $this->redirect('/');