-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.php
216 lines (191 loc) · 6.36 KB
/
routes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
*
*Password reset example
* http://forums.laravel.com/viewtopic.php?id=1533
*/
/**
* Guest filter
* If is a guest send to login
*/
Route::filter('guests', function() {
if (Auth::guest())
return Redirect::to_route('auth_login');
});
/**
* User filter, filters users out
* If is a user send to seetings
*/
Route::filter('users', function() {
if (Auth::check()) {
return Redirect::to_route('auth_settings');
}
});
/**
* Lobby
**/
Route::get('(:bundle)', array('as' => 'auth_lobby', function() {
return View::make('layout') -> with('title', 'User Lobby') -> nest(Config::get('authvel::content'), 'authvel::lobby');
}));
/**
* Login
*/
Route::get('(:bundle)/login', array('as' => 'auth_login', 'before' => 'users', 'do' => function() {
return View::make('layout') -> with('title', 'Login') -> nest(Config::get('authvel::content'), 'authvel::login'); ;
}));
Route::post('(:bundle)/login', array('as' => 'auth_login_post', 'before' => 'users', 'do' => function() {
$credentials = array('username' => Input::get('username'), 'password' => Input::get('password'));
if (Auth::attempt($credentials)) {
// auth success
return Redirect::to_route('auth_settings');
} else {
// auth failed
return Redirect::to_route('auth_login') -> with('messages', array('No match'));
}
}));
/**
* Signup
*/
Route::get('(:bundle)/signup', array('as' => 'auth_signup', 'before' => 'users', 'do' => function() {
return View::make('layout') -> with('title', 'Signup') -> nest(Config::get('authvel::content'), 'authvel::signup'); ;
}));
Route::post('(:bundle)/signup', array('as' => 'auth_signup_post', 'before' => 'users', 'do' => function() {
$rules = array('email' => 'required|email|unique:users,email');
$validation = Validator::make(Input::all(), $rules);
if ($validation -> fails()) {
return Redirect::to_route('auth_signup') -> with_errors($validation);
} else {
$email = Input::get('email');
$username = strstr($email, '@', TRUE) . rand(1000, 9999);
$password = randString(6, TRUE);
$user = new User;
$user -> fill(array('username' => $username, 'password' => $password, 'email' => $email, 'access' => 0));
$user -> save();
Auth::login($user -> id);
return Redirect::to_route('auth_lobby');
}
}));
/**
* Logout
*/
Route::get('(:bundle)/logout', array('as' => 'auth_logout', 'before' => 'guests', 'do' => function() {
Auth::logout();
return Redirect::to_route('auth_lobby');
}));
/**
* Settings
*/
Route::get('(:bundle)/settings', array('as' => 'auth_settings', 'before' => 'guests', 'do' => function() {
Session::put('username', Auth::user() -> username);
return View::make('layout') -> with('title', 'Settings') -> nest(Config::get('authvel::content'), 'authvel::settings');
}));
Route::post('(:bundle)/settings', array('as' => 'auth_settings_post', 'before' => 'guest', 'do' => function() {
$input = Input::all();
if (isset($input['username'])) {
$rules = array('username' => 'between:3,20|alpha_num|unique:users,username');
$validation = Validator::make(Input::all(), $rules);
}
/**
* Change Password
*/
if (isset($input['password'])) {
$rules = array('password' => 'between:5,20|alpha_num|confirmed');
$validation = Validator::make(Input::all(), $rules);
}
$validation = Validator::make(Input::all(), $rules);
if ($validation -> fails()) {
return Redirect::to_route('auth_settings') -> with_errors($validation);
} else {
$user = User::find(Auth::user() -> id);
if (isset($input['username'])) {
$user -> username = $input['username'];
$m = 'Your username has been changed';
}
if (isset($input['password'])) {
$user -> password = $input['password'];
$m = 'Your password has been changed';
}
if($user -> save()){
Session::flash('info', $m);
}else{
Session::flash('error', 'Please try again');
}
return Redirect::to_route('auth_settings');
}
}));
/**
* Error
*/
Route::any('(:bundle)/error', function() {
return View::make('layout') -> with('title', 'Error') -> nest(Config::get('authvel::content'), 'authvel::error');
});
/**
* Readable param is good for captcha for example
*
* randString(rand(10,15));
*
* @category RoboTamer
* @author Dennis T Kaplan
* @copyright Copyright (c) 2011, Dennis T Kaplan
* @license http://www.RoboTamer.com/license.php
* @link http://www.RoboTamer.com
*
* @version 1.3
* @param string $length
* @param bool $readable
* @return string
*/
function randString($length = 6, $readable = FALSE) {
if ($readable == FALSE) {
$char = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
} else {
$char = '23479ABCDEFHJLMNQRTUVWXYZabcefghijkmnopqrtuvwxyz';
}
$c = '';
for ($i = 1; $i <= $length; $i++) {
$c .= $char;
}
return substr(str_shuffle($c), 0, $length);
}
/**
* Check if a user has access to the asset
*
* @param $lock string This is the lock on the asset. A comma seperated list
* @param $keys array This are the keys / roles available to the user
* @return boolern TRUE or FALSE
*/
function CA($lock, $keys) {
$check = FALSE;
$lock = explode(',', str_replace(' ', '', $lock));
$lock[] = 101;
Log::write('debug', "Login Control 1");
# Admin has always access
if ($keys !== FALSE) {
$keys = explode(',', str_replace(' ', '', $keys));
} else {
Log::write('debug', "Login Control 45");
$check = FALSE;
redirect('/control_panel/login/', 'location');
}
foreach ($lock as $k => $v) {
if (in_array($v, $keys)) {
$check = TRUE;
}
if ($v == 100) {
if (!in_array(100, $keys)) {
Log::write('debug', "Login Control 50");
redirect('/control_panel/login/', 'location');
$check = FALSE;
}
Log::write('debug', "Login Control 60");
$lock[$k] = FALSE;
}
}
if ($check === TRUE) {
return TRUE;
} else {
Log::write('debug', "You don't have access to this area.");
Session::flash('error', "You don't have access to this area.");
}
}
?>