public function __construct() { parent::__construct(); if (!BEUsersHelper::isAdmin()) { Redirect::to('/'); } }
public static function isCurrentUser($id) { if (BEUsersHelper::isLogged()) { if ($id == Session::get('current_user')) { return true; } else { return false; } } else { return false; } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { // if (BEUsersHelper::validateUser()) { $user = User::find($id); $name = Input::get('name'); $address = Input::get('address'); $phone = Input::get('phone'); $is_admin = Input::get('is_admin'); $user->name = $name; $user->address = $address; $user->phone = $phone; $user->is_admin = $is_admin; $user->save(); Session::flash('status', true); return Redirect::route('admin.user.index'); } else { Session::flash('status', false); return Redirect::route('admin.user.edit', $id)->withInput(); } }
*/ Route::filter('guest', function () { if (Auth::check()) { return Redirect::to('/'); } }); /* |-------------------------------------------------------------------------- | CSRF Protection Filter |-------------------------------------------------------------------------- | | The CSRF filter is responsible for protecting your application against | cross-site request forgery attacks. If this special token in a user | session does not match the one given in this request, we'll bail. | */ Route::filter('csrf', function () { if (Session::token() !== Input::get('_token')) { throw new Illuminate\Session\TokenMismatchException(); } }); Route::filter('checkAdmin', function () { if (!BEUsersHelper::isAdmin()) { $messages = array(); $status = false; $messages[] = "Bạn không có quyền vào trang này"; Session::flash('status', $status); Session::flash('messages', $messages); return Redirect::to('/'); } });
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $user = User::find($id); if (BEUsersHelper::isCurrentUser($id)) { Session::flush('current_user'); } foreach ($user->albums as $album) { $album->delete(); } foreach ($user->images as $image) { $image->delete(); } foreach ($user->blogs as $blog) { $blog->delete(); } foreach ($user->entries as $entry) { $entry->delete(); } foreach ($user->posts as $post) { $post->delete(); } foreach ($user->follows as $follow) { $follow->delete(); } $user->delete(); Session::flash('status', true); Session::flash('messages', array('Đã xóa user')); return Redirect::route('admin.user.index'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $user = User::find($id); if (BEUsersHelper::isCurrentUser($id)) { Session::flush('current_user'); } foreach ($user->albums as $album) { $album->delete(); } $user->delete(); Session::flash('status', true); Session::flash('messages', array('Đã xóa user')); return Redirect::route('admin.user.index'); }