/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(SaveTopicRequest $request) { $originalContent = trim($request->input('content')); $data = array('uid' => Sentinel::getUser()->id, 'title' => trim($request->input('title')), 'original_content' => $originalContent, 'content' => (new Parser())->makeHtml($originalContent), 'active_at' => time()); $topic = Topic::create($data); if ($topic && isset($topic->id)) { return $this->response()->item($topic, new TopicTransformer()); } else { throw new StoreResourceFailedException('保存失败,请重新尝试'); } }
/** * Display a listing of roles. * * @return \Illuminate\View\View */ public function index() { $adminRoles = $this->roles->findById(1); $managerRoles = $this->roles->findById(2); $roles = $this->roles->paginate(); $user = Sentinel::getUser(); return view('admin.roles.index', compact('roles', 'user', 'adminRoles', 'managerRoles')); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $user = Sentinel::getUser(); $admin = Sentinel::findRoleByName('Administradores'); if (!$user->inRole($admin)) { return redirect('login'); } return $next($request); }
/** * Throws 403 unauthorized error if the user is * not allowed to access the specified route. * * @param Request $request * @param Closure $next * * @return Request * * @throws \Symfony\Component\HttpKernel\Exception\HttpException * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function handle(Request $request, Closure $next) { $user = Sentinel::getUser(); if ($user && $user instanceof User) { if ($user->hasAccess($request->route()->getName())) { return $next($request); } } // Return forbidden error. abort(403); }
/** * Constructor. * * @return void */ public function __construct() { $this->beforeFilter('csrf', ['on' => 'post', 'except' => $this->csrfWhitelist]); // Set the active theme area $this->setActiveThemeArea(); // Set the fallback theme area $this->setFallbackThemeArea(); $this->alerts = app('alerts'); $this->currentUser = Sentinel::getUser(); View::share(['currentUser' => $this->currentUser]); }
protected function dashboard() { // Se Sentinel::guest() = true => usuário entrou com Auth (Autentic. Social) // Caso contrário => usuário entrou com Sentinel (Autentic. Local) if (Sentinel::guest()) { // USUÁRIO AUTENTICANDO COM REDE SOCIAL $user = ["name" => Auth::user()->name, "email" => Auth::user()->email]; } else { // USUÁRIO AUTENTICANDO LOCALMENTE $user = ["name" => Sentinel::getUser()->first_name, "email" => Sentinel::getUser()->email]; } return view("user.dashboard", ["user" => $user]); }
/** * Redirects users to the main dashboard page if they're * already logged in and trying to access a login / register route. * * @param Request $request * @param Closure $next * * @return Request|\Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next) { $user = Sentinel::getUser(); if ($user) { $route = 'maintenance.work-requests.index'; if (!$user->hasAccess($route)) { $route = 'maintenance.client.work-requests.index'; } return redirect()->route($route); } else { return $next($request); } }
/** * Boot the creation trait for a model. * * @return void */ public static function bootCreation() { // create a event to happen on deleting static::deleting(function ($table) { if (class_exists('Cartalyst\\Sentinel\\Laravel\\Facades\\Sentinel')) { $table->deleted_by = Sentinel::getUser()->id; } else { $table->deleted_by = Auth::user()->id; } $table->update(['deleted_by' => $table->deleted_by]); }); // create a event to happen on saving static::saving(function ($table) { if (class_exists('Cartalyst\\Sentinel\\Laravel\\Facades\\Sentinel')) { if (Sentinel::check()) { $table->modified_by = Sentinel::getUser()->id; } if (Sentinel::check() && ($table->created_by == null || !($table->created_by > 0))) { $table->created_by = Sentinel::getUser()->id; } } else { if (!Auth::guest()) { $table->modified_by = Auth::user()->id; } if (!Auth::guest() && ($table->created_by == null || !($table->created_by > 0))) { $table->created_by = Auth::user()->id; } } }); }
public function __construct() { $this->page = new \stdClass(); // Заголовок страницы $this->page->title = ''; // Описание страницы $this->page->desc = ''; $this->page->base_url = 'http://' . request()->server('HTTP_HOST') . '/'; // Данные пользователя if (!Sentinel::check()) { $this->user = false; } else { $this->user = Sentinel::getUser(); } }
/** * 登陆后,获取当前账号信息 * * @return array|\Illuminate\Http\RedirectResponse */ public function account_info() { $return_data = array(); if (Sentinel::check()) { $account_info = Sentinel::getUser(); $return_data['email'] = $account_info['email']; $return_data['permissions'] = $account_info['permissions']; $return_data['last_name'] = $account_info['last_name']; $return_data['first_name'] = $account_info['first_name']; $return_data['created_at'] = $account_info['created_at']; } $num = $this->num_active_unactive(); $return_data['num_active'] = $num['active_num']; $return_data['num_unactive'] = $num['unactive_num']; return $return_data; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Sentinel::guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('auth/login'); } } if (!Sentinel::getUser()->inRole('admin')) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { abort(401); } } return $next($request); }
/** * BaseController constructor. * * @param Request $request */ public function __construct(Request $request) { //Get current request $this->request = $request; //Set active theme Theme::setActive('administration'); //Check user is logged in if (Sentinel::guest()) { if (!in_array($request->getPathInfo(), $this->routes)) { return Redirect::to('/admin/auth/login')->send(); } } else { $this->user = Sentinel::getUser(); if (self::isAdmin() == 1) { $this->globalViewData(); } else { Redirect::to('/404')->send(); } } }
/** * BaseController constructor. * * @param Request $request */ public function __construct(Request $request) { //Get current request $this->request = $request; //Set active theme Theme::setActive('dressplace'); //Check user is logged in if (Sentinel::guest()) { if (!in_array($request->getPathInfo(), $this->routes)) { // return Redirect::to('/admin/auth/login')->send(); } } else { $this->user = Sentinel::getUser(); self::getActiveUser(); } //Init system $this->systemInit(); //Load navigation $this->getNavPages(); $this->getCategories(); }
/** * 获取当前用户列表 * * @param int $flage 默认0,获取所有用户;1,获取已激活用户;2,获取未激活用户; * * @return mixed */ public function list_logic($flage = 0) { $users = User::get(); $current_user = Sentinel::getUser(); $current_user_id = $current_user->id; //已激活用户 $active_user = array(); //未激活用户 $unactive_user = array(); //计数 $active_num = 0; $unactive_num = 0; foreach ($users as $k => $kValue) { //dump($kValue); $email = $kValue->email; $role = $this->role_by_user($kValue); // dump($role); if (!$role) { $users[$k]['role'] = null; } else { $users[$k]['role'] = $role->slug; } $credentials0 = ["email" => $email]; $temp_user_info = Sentinel::findByCredentials($credentials0); if (Activation::completed($temp_user_info)) { $users[$k]['active'] = 1; $active_user[] = $users[$k]; ++$active_num; //当前账号 if ($current_user_id == $temp_user_info['id']) { $users[$k]['active'] = 2; } } else { $users[$k]['active'] = 0; $unactive_user[] = $users[$k]; ++$unactive_num; } } if ($flage == 1) { $users = $active_user; } if ($flage == 2) { $users = $unactive_user; } return $users; }
public static function puedeAcceder($permiso) { return Sentinel::getUser()->hasAccess($permiso); }
public function getEmail() { $user = Sentinel::getUser(); return view('user.email', compact('user')); }
/** * Returns the current users work order notifications. * * @return object */ public function getUserNotifications() { $record = $this->notifiableUsers()->where('user_id', Sentinel::getUser()->id)->first(); return $record; }
/** * group operation alias method * * @param \Illuminate\Database\Eloquent\Model $model * @param string $subBase * @return boolean */ protected function groupAlias($model, $subBase = 'Events') { $namespace = getBaseName($model, $subBase); $events = []; switch ($this->request->action) { case 'activate': $events['activationSuccess'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateSuccess::class; $events['activationFail'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateFail::class; break; case 'not_activate': $events['activationRemove'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateRemove::class; $events['activationFail'] = \ErenMustafaOzdal\LaravelUserModule\Events\Auth\ActivateFail::class; break; case 'publish': $events['success'] = "{$namespace}\\PublishSuccess"; $events['fail'] = "{$namespace}\\PublishFail"; break; case 'not_publish': $events['success'] = "{$namespace}\\NotPublishSuccess"; $events['fail'] = "{$namespace}\\NotPublishFail"; break; case 'destroy': if ($model == 'App\\User' && in_array(Sentinel::getUser()->id, $this->request->get('id'))) { abort(403); } break; } $this->setEvents($events); $action = camel_case($this->request->action) . 'GroupAction'; return $this->{$action}($model); }
/** * @param $template * * @return mixed */ protected function setupView($template) { $user = Sentinel::getUser(); $user->setDisabledActions($this->disabledActions); $this->formModifier->render(); $this->beforeRender($this); return $this->app['view']->make("{$this->viewNamespace}::{$template}", array_merge($this->data, ['form' => $this->formModifier, 'attributes' => $this->repo->setAttributeValues($this->mode, $this->formModifier->getAllAttributes(), $this->model), 'orderBy' => $this->orderby, 'cancel' => $this->generateCancelLink(), 'disabledActions' => $this->disabledActions, 'disableDeleting' => $this->disableDeleting, 'disableEditing' => $this->disableEditing, 'model' => $this->model, 'lastVisibleAttribute' => $this->getLastVisibleAttribute(), 'singular' => $this->singular, 'plural' => $this->plural, 'paginate' => $this->paginate, 'mode' => $this->mode, 'controller' => get_class($this), 'parent' => $this->parent, 'filters' => $this->filter])); }
/** * Remove the specified resource from storage. * * @param $categoryId * @param $threadId * @return Response */ public function destroy($categoryId, $threadId) { $thread = Thread::with(['category' => function ($query) use($categoryId) { $query->where('id', $categoryId); }, 'posts' => function ($query) { $query->orderBy('created_at', 'asc'); }])->findOrFail($threadId); if (Sentinel::getUser()->id == $thread->posts->first()->user->id && !Sentinel::getUser()->hasAccess(['threads.own.destroy']) || Sentinel::getUser()->id != $thread->posts->first()->user->id && !Sentinel::getUser()->hasAccess(['threads.others.destroy'])) { abort(401); } $thread->posts()->delete(); $thread->delete(); return redirect()->route('categories.threads.index', [$thread->category->id]); }
public function __construct() { $this->user = Sentinel::getUser(); }
/** * @return User */ public function model() { return Sentinel::getUser(); }
/** * {@inheritDoc} */ public function getActiveUser() { return Sentinel::getUser(); }
function getAuthUser() { return Sentinel::getUser(); }
/** * @param bool|false $pim * @return string * @author Bertrand Kintanar */ protected static function profileLinks($pim = false) { $user = Sentinel::getUser(); $nav = '<div class="col-lg-12 top-nav-b"><div class="btn-group top-nav-li"><ul>'; $navigations = self::whereParentId(-1)->get(); foreach ($navigations as $navigation) { $format = self::formatHref($navigation, $pim); if (!$user->hasAccess($format['link'] . '.view')) { continue; } $nav .= '<li'; if (self::isURLActive($format['href'])) { $nav .= ' class="active">'; } else { $nav .= '>'; } $nav .= '<a href="/' . $format['href'] . '">'; $nav .= '<i class="fa ' . $navigation->icon . ' m-right-a"></i>'; $nav .= $navigation->name; $nav .= '</a></li>'; } $nav .= '</ul></div></div>'; return $nav; }
public function __construct() { $this->beforeFilter('auth'); $this->users = Sentinel::getRoleRepository(); $this->user = Sentinel::getUser(); }
return Redirect::to('account/'); }); Route::group(['prefix' => 'account'], function () { Route::get('/', function () { $user = Sentinel::getUser(); $persistence = Sentinel::getPersistenceRepository(); return view('account.home', compact('user', 'persistence')); }); Route::resource('profile', 'Accounts\\AccountsController', ['only' => ['show', 'edit', 'update']]); Route::get('kill', function () { $user = Sentinel::getUser(); Sentinel::getPersistenceRepository()->flush($user); return Redirect::back(); }); Route::get('kill-all', function () { $user = Sentinel::getUser(); Sentinel::getPersistenceRepository()->flush($user, false); return Redirect::back(); }); Route::get('kill/{code}', function ($code) { Sentinel::getPersistenceRepository()->remove($code); return Redirect::back(); }); }); }); /******************************************************* * //User login and active routes ******************************************************/ Route::get('login', ['as' => 'login', 'middleware' => 'guest', 'uses' => 'Auth\\AuthController@login']); Route::post('login', 'Auth\\AuthController@processLogin'); Route::get('logout', 'Auth\\AuthController@logout');
/** * Returns the revision user ID. * * @return int */ public function revisionUserId() { return Sentinel::getUser()->id; }
/** * Remove the specified resource from storage. * * @param $categoryId * @param $threadId * @param $postId * @return Response */ public function destroy($categoryId, $threadId, $postId) { $post = Post::with(['thread' => function ($query) use($threadId) { $query->where('id', $threadId); }, 'thread.category' => function ($query) use($categoryId) { $query->where('id', $categoryId); }])->findOrFail($postId); // don't allow deleting threads here if ($post->id == $post->thread->posts->first()->id) { abort(401); } if (Sentinel::getUser()->id == $post->user->id && !Sentinel::getUser()->hasAccess(['posts.own.destroy']) || Sentinel::getUser()->id != $post->user->id && !Sentinel::getUser()->hasAccess(['posts.others.destroy'])) { abort(401); } $post->delete(); return redirect()->route('categories.threads.posts.index', [$post->thread->category->id, $post->thread->id]); }
/** * Архив заказов * * @return \Illuminate\View\View */ public function getArchive() { $this->page->title = 'Заказы такси'; $this->page->desc = 'Архив заказов'; // АДМИНИСТРАТОР Текущие заказы if (Sentinel::inRole('admin')) { $this->data['orders'] = Order::whereRaw('order_status = 3 AND payment_status = 1 AND (departure_time < now() and arrivals_time < now())')->orderBy('created_at', 'DESC')->get(); } else { $this->data['orders'] = Order::whereRaw('order_status = 3 AND payment_status = 1 AND (departure_time < now() and arrivals_time < now())')->where('user_id', Sentinel::getUser())->orderBy('created_at', 'DESC')->get(); } // АДМИНИСТРАТОР отображение return $this->render('order.list-archive'); }