public static function destroy($id) { $currentUser = Sentry::getUser(); if (Auth::check() && $id == $currentUser->id) { throw new Exception("You can not delete yourself"); } try { $user = Sentry::getUserProvider()->findById($id); $user->delete(); } catch (UserNotFoundException $e) { throw new Exception("User was not found."); } }
public function login() { try { $data = Input::all(); $credentials = array('email' => $data['email'], 'password' => $data['password']); $user = Sentry::authenticate($credentials, false); $groups = Sentry::getUser()->getGroups(); $is_admin = 0; foreach ($groups as $v) { if ($v->is_admin == 1) { $is_admin = 1; } } if ($is_admin == 0) { Sentry::logout(); return Response::json(['status' => false, 'error' => '账户非管理员']); } // Authenticate the user return Response::json(['status' => $user ? true : false]); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Response::json(['status' => false, 'error' => '请输入完整字段']); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Response::json(['status' => false, 'error' => '请输入密码']); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Response::json(['status' => false, 'error' => '密码错误,请重试']); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Response::json(['status' => false, 'error' => '用户不存在']); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Response::json(['status' => false, 'error' => '用户暂未激活']); } }
/** * Register the service provider. * * @return void */ public function register() { $this->app['router']->before(function ($request) { // First clear out all "old" visitors Visitor::clear(); $page = Request::path(); $ignore = Config::get('visitor-log::ignore'); if (is_array($ignore) && in_array($page, $ignore)) { //We ignore this site return; } $visitor = Visitor::getCurrent(); if (!$visitor) { //We need to add a new user $visitor = new Visitor(); $visitor->ip = Request::getClientIp(); $visitor->useragent = Request::server('HTTP_USER_AGENT'); $visitor->sid = str_random(25); } $user = null; $usermodel = strtolower(Config::get('visitor-log::usermodel')); if (($usermodel == "auth" || $usermodel == "laravel") && Auth::check()) { $user = Auth::user()->id; } if ($usermodel == "sentry" && class_exists('Cartalyst\\Sentry\\SentryServiceProvider') && Sentry::check()) { $user = Sentry::getUser()->id; } //Save/Update the rest $visitor->user = $user; $visitor->page = $page; $visitor->save(); }); }
public function getMyProfile() { // lay ID hien tai cua nguoi dang dang nhap $userID = Sentry::getUser()->id; // Lay profile $userProfile = $this->user->getUserProfile($userID); return \View::make("dashboard.users.userprofile")->with("title", "Profile")->with("data", $userProfile); }
public static function getUser($id = 0) { if ($id == 0) { return Sentry::getUser(); } else { return Sentry::findUserById($id); } }
/** * When an order is updated log it into database * * @param ModelOrder $order */ public function whenOrderHasBeenUpdated(ModelOrder $order) { try { $changer_id = Sentry::getUser()->id; $this->orderLogRepo->store($order, $changer_id, $order->creator_id); } catch (RepositoryException $e) { Log::info($e->getMessage()); } }
/** * Get side navigation view content * @return View */ public function sidenav() { $user = Sentry::getUser(); if ($user->is_administrator == 0) { $modules = $this->getUserModules($user, false); } else { $modules = array_merge($this->getSystemModules(), $this->getUserModules($user, true)); } return View::make("CoreCms::layouts.partial.navside")->with("systems", $modules); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $currentUser = null; if (Sentry::check()) { $tempUser = Sentry::getUser(); $currentUser = array("id" => $tempUser->id, "firstname" => $tempUser->first_name, "fullname" => $tempUser->first_name . " " . $tempUser->last_name); } view()->share('currentUser', $currentUser); return $next($request); }
/** * @param $route * @param $request * @param $value * @return mixed */ public function hasPermission($route, $request, $value) { if (!Sentry::check()) { return Redirect::to('aut/login'); } $user = Sentry::getUser(); if (!$user->hasAccess($value)) { return Redirect::to('dash')->with('error_message', 'شما دسترسی به صفحه مورد نظر را ندارید.'); } }
private function replaceData($data) { $data['ip'] = getIp(); $data['ratingspage_id'] = $data['id']; $data['ratingspage_type'] = str_replace("\\", "_", Crypt::decrypt($data['model'])); $data['rating'] = $data['value']; if (Sentry::check()) { $data['user_id'] = Sentry::getUser()->id; } return $data; }
/** * @return \Illuminate\Http\JsonResponse */ public function postStore() { $data = array_add(Input::all(), 'uid', Sentry::getUser()->id); $post = $this->post->create($data); //tag处理 $tags = Input::get('tag'); if (count($tags) > 0) { $post->tag($tags); } return Response::json(['status' => $post ? 1 : 0]); }
/** * Register the service provider. * * @return void */ public function register() { $this->app->bind('SaleBoss\\Services\\Leads\\Creator\\CreatorInterface', 'SaleBoss\\Services\\Leads\\Creator\\Creator'); $this->app->bind('SaleBoss\\Services\\Leads\\Importer\\FactoryInterface', 'SaleBoss\\Services\\Leads\\Importer\\ImporterFactory'); $this->app->bind('SaleBoss\\Services\\Leads\\Presenter\\DelegateManInterface', 'SaleBoss\\Services\\Leads\\Presenter\\DelegateMan'); $this->app->bindShared('lead_throttle', function ($app) { $throttle = App::make('SaleBoss\\Services\\Leads\\Presenter\\Throttle'); $throttle->setUser(Sentry::getUser()); return $throttle; }); }
public function editor($field) { $admin = Sentry::findGroupByName('admin'); if (Sentry::check() && Sentry::getUser()->inGroup($admin)) { $pageEditor = $this; $fieldEdit = "editor_init_" . get_class($pageEditor) . "_" . $field . "_" . $pageEditor->id; return View::make('builder::partials.editor_init', compact("pageEditor", "field", "fieldEdit")); } else { return $this->{$field}; } }
public function store($type = 'logo') { $this->init($type); $data = Input::all(); $status = 1; $data['user_id'] = Sentry::getUser()->id; $bool = $this->model->adddata($data); if ($bool) { return Redirect::route('member.publish.buyer.list', ['type' => $type, 'status' => $status]); } }
public function getLogin() { if (Sentry::check()) { $user = Sentry::getUser(); //Return if user is an admin if ($user->hasAccess('admin')) { Session::flash('info', 'Already logged in as ' . $user->email); return Redirect::to('admin'); } } return View::make('admin.login'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = Sentry::getUser(); $vault = new Vault(); $vault->salt = Request::input('salt'); $vault->ct = Request::input('ct'); $vault->iv = Request::input('iv'); $vault->description = Request::input('description'); $vault->user_id = $user->id; $vault->save(); return redirect()->route('home'); }
public function doAddComment() { parse_str(Input::get('data'), $data); if (isset($data['id_page'])) { $data['commentpage_type'] = Crypt::decrypt($data['commentable']); $data['commentpage_id'] = $data['id_page']; if (Sentry::check()) { $data['user_id'] = Sentry::getUser()->id; $data['name'] = Sentry::getUser()->getFullName(); } Comment::create($data); return $this->listCommetns($data['commentpage_type'], $data['id_page']); } }
public function update() { $user = Sentry::getUser(); $data['native_place'] = Input::get('native_place2') ? implode('-', Input::get('native_place2')) : ''; $data['hobby'] = Input::get('hobby2') ? implode(',', Input::get('hobby2')) : ''; $data['edu_time'] = Input::get('edu_time2') ? implode(',', Input::get('edu_time2')) : ''; $data['company_time'] = Input::get('company_time2') ? implode(',', Input::get('company_time2')) : ''; $data = array_merge($data, Input::all()); $user->nickname = Input::get('nickname'); $user->save(); $uinfo = $this->uinfo->where('uid', $user->id)->first(); $uinfo->fill($data)->save(); return Redirect::back()->withSuccess('信息更新成功!'); }
/** * Add Entry for the currently logged in user * @return Redirect */ public function addEntry() { //Get all data $data = \Input::all(); //Get the user id of the currently logged in user $userId = Sentry::getUser()->id; //Add Data $result = $this->timesheet->addEntry($data, $userId); //Redirect with appropriate message to the user if ($result == 'success') { return \Redirect::to('dashboard/timesheet')->with('status', 'success')->with('message', 'Entry Added'); } else { return \Redirect::to('dashboard/timesheet')->with('status', 'error')->with('message', 'Something Went Wrong. Please try again.'); } }
public function listIt() { $input = Input::all(); $input['shared'] = true; if (Sentry::getUser()->hasAnyAccess(['leads.view_all'])) { $input['shared'] = false; } if (!empty($input['my_created_leads'])) { $input['creator_id'] = Sentry::getUser()->id; $input['shared'] = false; } if (!empty($input['my_locked_leads'])) { $input['locker_id'] = Sentry::getUser()->id; } return $this->leadRepo->getPaginated(25, true, $input, Input::get('sort_by') ? Input::get('sort_by') : 'created_at', Input::get('asc')); }
/** * Listing Users Customers * * @return View */ public function myIndex() { $searches = Input::only("first_name", "last_name", "mobile", "tell", "description", "email", "id", "creator_id"); $title = 'لیست مشتریان من'; $description = 'لیست مشتریانی که من ایجاد کرده ام'; $myCustomers = $this->userRepo->getCustomers(Sentry::getUser(), 50, $searches); return $this->view('admin.pages.customer.my_index', compact('myCustomers', 'title', 'description')); }
public function profileUpdate() { return $this->creator->updateMe(Sentry::getUser(), Input::get("item"), $this); }
/** * Filter the incoming requests. */ public function filterRequests($route, $request) { if (!is_object(Sentry::getUser()) || !Sentry::getUser()->hasAccess('admin')) { return Redirect::guest('admin/login'); } }
public function getInProgressProjectsByUser() { return Project::where('status_id', '=', '2')->where('owner_id', '=', Sentry::getUser()->id)->get(); }
public function deleteUser(Request $request) { $outputMessage = array(); if ($request->has('id')) { $currentUser = Sentry::getUser(); if ($currentUser->hasAccess('admin')) { $user = User::find($request->get('id')); if ($user and $user->delete()) { $outputMessage[] = array("type" => "success", "msg" => "User deleted successfuly."); return redirect()->back()->with('messages', $outputMessage); } else { $outputMessage[] = array("type" => "alert", "msg" => "User not found."); return redirect()->back()->with('messages', $outputMessage); } } else { $outputMessage[] = array("type" => "alert", "msg" => "You have not permission to delete user."); return redirect()->back()->with('messages', $outputMessage); } } else { return redirect(\Config::get('app.settings.url.admin_dashboard') . '/users'); } }
public function getUser() { return Sentry::getUser(); }
public function isAdmin() { return Sentry::getUser()->hasAccess('admin'); }
/** * Project Report * @return View */ public function postProjectReport() { //Get the user id of the currently logged in user $userId = Sentry::getUser()->id; //Get the Project Id $projectId = \Input::get('projectid'); //Get Data $data = $this->report->generateProjectReport($projectId, $userId); return \View::make('dashboard.reports.projectreport')->with('project', $data); }
/** * Reply to specified ticket * POST /tickets/{id}/reply * * @param int $id * @return Response */ public function reply($id) { $input = Input::all(); $user_id = Sentry::getUser()->id; $rules = array('status_id' => 'required', 'priority_id' => 'required', 'content' => 'required'); $validator = Validator::make($input, $rules); if ($validator->fails()) { return Redirect::route('tickets.show', $id)->withErrors($validator)->withInput($input); } else { TicketReply::create(['ticket_id' => $id, 'user_id' => $user_id, 'content' => $input['content']]); $ticket = $this->ticket->find($id); $ticket->status_id = $input['status_id']; $ticket->priority_id = $input['priority_id']; $ticket->replies = $ticket->replies + 1; $ticket->save(); return Redirect::route('tickets.index')->with('message', ['class' => 'success', 'text' => 'Ticket Replied To.']); } }
/** * Handle logging in / logging out a user. * * @return Response */ public function login() { $status = 401; try { // Set login credentials $credentials = array('email' => Request::getUser(), 'password' => Request::getPassword()); // Try to authenticate the user $response = Sentry::authenticate($credentials, false); $status = 200; } catch (\Cartalyst\Sentry\Users\LoginRequiredException $e) { $response = array('message' => 'Provided information is not valid.', 'errors' => array(array('field' => 'email', 'message' => 'Login field is required.'))); } catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e) { $response = array('message' => 'Provided information is not valid.', 'errors' => array(array('field' => 'password', 'message' => 'Password field is required.'))); } catch (\Cartalyst\Sentry\Users\WrongPasswordException $e) { $response = array('message' => 'Provided information is not valid.', 'errors' => array(array('field' => 'password', 'message' => 'Wrong password, try again.'))); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { $response = array('message' => 'User was not found.'); } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) { $response = array('message' => 'Your account is not yet activated.'); } catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $response = array('message' => 'Your account is suspended.'); } catch (\Cartalyst\Sentry\Throttling\UserBannedException $e) { $response = array('message' => 'Your account is banned.'); } // Get current client $client = API::getClient(); // Logging in user if ($status == 200) { $clientEndpoint = $client->endpoint; $clientScopeIds = API::getResource()->getScopeIds(); $clientScopes = API::getResource()->getScopes(); $scopes = array(); if (!empty($clientScopeIds)) { foreach ($clientScopeIds as $id) { $scopes[] = array('id' => $id); } } unset($clientScopeIds); if (!is_array($clientScopes)) { $clientScopes = array(); } // Create a new client endpoint if not exist if (!is_object($clientEndpoint)) { $redirectUri = Request::getSchemeAndHttpHost(); $clientEndpoint = OauthClientEndpoint::create(array('client_id' => $client->id, 'redirect_uri' => $redirectUri)); } else { $redirectUri = $clientEndpoint->redirect_uri; } // Create a new authorization code $authCode = API::newAuthorizeRequest('user', $response->id, array('client_id' => $client->id, 'redirect_uri' => $redirectUri, 'scopes' => $scopes)); // Authorize the client to a user if (!empty($authCode)) { $params = array('grant_type' => 'authorization_code', 'client_id' => $client->id, 'client_secret' => $client->secret, 'redirect_uri' => $redirectUri, 'code' => $authCode, 'scope' => implode(',', $clientScopes), 'state' => time()); $authorizationResponse = API::performAccessTokenFlow(false, $params); if (array_key_exists('status', $authorizationResponse)) { $status = $authorizationResponse['status']; $headers = $authorizationResponse['headers']; unset($authorizationResponse['status']); unset($authorizationResponse['headers']); return API::resourceJson($authorizationResponse, $status, $headers); } // Merge user data with the new authorization data $authorizationResponse['user'] = new UserTemplate($response); $response = $authorizationResponse; unset($authorizationResponse); } else { $response = array('message' => 'There was a problem while logging you in, please try again or contact customer support.'); $status = 500; } unset($scopes); unset($clientScopes); // Logout user } else { $user = null; try { $user = Sentry::getUser(); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { } if (!is_null($user) and !is_null($client)) { // Cleanup OAuth session $session = new FluentSession(); $session->deleteSession($client->id, 'user', $user->getId()); unset($session); // Logout user via sentry Sentry::logout(); } unset($user); } return API::resourceJson($response, $status); }