/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $email = $this->argument('email');
     $password = $this->argument('password', 'admin123');
     $firstName = $this->argument('first_name', 'Admin');
     $lastName = $this->argument('last_name', 'Tea');
     if (empty($email)) {
         $email = '*****@*****.**';
     }
     if (empty($password)) {
         $password = '******';
     }
     if (empty($firstName)) {
         $firstName = 'Admin';
     }
     if (empty($lastName)) {
         $lastName = 'Tea';
     }
     try {
         // Let's register a user.
         $user = Sentry::createUser(array('email' => $email, 'password' => $password, 'first_name' => $firstName, 'last_name' => $lastName, 'activated' => true));
         // Find the group using the group id
         $group = Sentry::findGroupByName('Administrators');
         // Assign the group to the user
         $user->addGroup($group);
     } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
         $this->error('User with this login already exists');
     } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         $this->error('Group was not found');
     }
 }
 public function testGetUser()
 {
     Sentry::shouldReceive('getUser')->once()->withNoArgs()->andReturn(array());
     $this->assertEquals(array(), $this->auth->getUser());
     Sentry::shouldReceive('getUser')->once()->andThrow('Cartalyst\\Sentry\\Users\\UserNotFoundException');
     $this->assertFalse($this->auth->getUser());
 }
Esempio n. 3
0
 public function postReset()
 {
     $this->beforeFilter('csrf');
     // Use the same password validation rules
     // from the user model
     $rules = array('code' => 'required', 'email' => 'required|email', 'password' => User::$rules['password'] . '|confirmed');
     $validator = Validator::make(Input::all(), $rules);
     if (!$validator->fails()) {
         try {
             $user = Sentry::findUserByCredentials(array('email' => Input::get('email')));
             if ($user->checkResetPasswordCode(Input::get('code'))) {
                 if ($user->attemptResetPassword(Input::get('code'), Input::get('password'))) {
                     // Password reset passed
                     Mail::queue(array('emails.password.done', 'emails.password.done_text'), array(), function ($message) use($user) {
                         $message->to($user->email, $user->first_name . ' ' . $user->last_name)->subject('Password Reset Successful');
                     });
                     return Redirect::action('AuthController@getDone');
                 } else {
                     // Password reset failed
                     Session::flash('error', 'Your password could not be reset');
                 }
             } else {
                 // The provided password reset code is Invalid
                 Session::flash('error', 'Invalid password reset code');
             }
         } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
             Session::flash('error', 'User not found, please check your email address');
         }
     } else {
         Session::flash('error', 'Please correct the following errors and try again');
     }
     Input::flash();
     return Redirect::action('AuthController@getReset')->withErrors($validator);
 }
 public function update($id, array $attributes)
 {
     try {
         // Find the user using the user id
         $user = Sentry::findUserById($id);
         $group_id = 0;
         foreach ($user->groups as $group) {
             $group_id = $group->id;
         }
         if ($group_id > 0 && $group_id != $attributes['group_id']) {
             // User is  Assigned , So Remove Old Group and Re-assigned New Group
             // Find Old the group using the group id
             $oldGroup = Sentry::findGroupById($group_id);
             $user->removeGroup($oldGroup);
             // Find New the group using the group id
             $newGroup = Sentry::findGroupById($attributes['group_id']);
             $user->addGroup($newGroup);
         } else {
             if ($group_id == 0 && $attributes['group_id'] > 0) {
                 // User is Not Assigned , So Assigned New Group
                 // Find New the group using the group id
                 $newGroup = Sentry::findGroupById($attributes['group_id']);
                 $user->addGroup($newGroup);
             }
         }
         $user->email = $attributes['email'];
         $user->save();
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * 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();
     });
 }
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index()
 {
     if (!Sentry::check()) {
         return Redirect::to('/giris');
     }
     return view('apanel/yonetim');
 }
Esempio n. 7
0
 public function doLogin(Request $request)
 {
     if ($request->has('email') and $request->has('password')) {
         $outputMessage = array();
         try {
             $email = $request->input('email');
             $password = $request->input('password');
             $remember = false;
             if ($request->has('remember')) {
                 $remember = true;
             }
             $user = Sentry::authenticate(array('email' => $email, 'password' => $password), $remember);
             return redirect(\Config::get('app.settings.url.admin_dashboard'));
         } catch (\Cartalyst\Sentry\Users\LoginRequiredException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "Login field is required.");
         } catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "Password field is required.");
         } catch (\Cartalyst\Sentry\Users\WrongPasswordException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "Wrong password, try again.");
         } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "User was not found.");
         } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "User is not activated.");
         } catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "User is suspended.");
         } catch (\Cartalyst\Sentry\Throttling\UserBannedException $e) {
             $outputMessage[] = array("type" => "alert", "msg" => "User is banned.");
         }
         return view('users.login')->with('messages', $outputMessage);
     } else {
         $outputMessage[] = array("type" => "alert", "msg" => "Login and password field is required.");
         return view('users.login')->with('messages', $outputMessage);
     }
 }
Esempio n. 8
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!Sentry::check()) {
         return redirect('/login');
     }
     return $next($request);
 }
Esempio n. 9
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $model = AdminUser::findOrFail($id);
     $modules = Module::all();
     $groups = Group::all();
     $usergroups = Sentry::findUserByID($id)->getGroups();
     return View::make("CoreCms::user.edit")->with("model", $model)->with("groups", $groups)->with("modules", $modules)->with("usergroups", $usergroups);
 }
Esempio n. 10
0
 public function retrieve($id)
 {
     try {
         return Sentry::getUserProvider()->findById($id);
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
     }
     return false;
 }
Esempio n. 11
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // Create an Admin group
     Sentry::createGroup(array('name' => 'Admin', 'permissions' => ['dashboard.index' => 1, 'dashboard.grid.save' => 1, 'dashboard.grid.reset' => 1, 'workshop.modules.index' => 1, 'workshop.modules.show' => 1, 'workshop.modules.disable' => 1, 'workshop.modules.enable' => 1, 'user.roles.index' => 1, 'user.roles.create' => 1, 'user.roles.store' => 1, 'user.roles.edit' => 1, 'user.roles.update' => 1, 'user.roles.destroy' => 1, 'user.users.index' => 1, 'user.users.create' => 1, 'user.users.store' => 1, 'user.users.edit' => 1, 'user.users.update' => 1, 'user.users.destroy' => 1, 'menu.menus.index' => 1, 'menu.menus.create' => 1, 'menu.menus.store' => 1, 'menu.menus.edit' => 1, 'menu.menus.update' => 1, 'menu.menus.destroy' => 1, 'menu.menuitem.index' => 1, 'menu.menuitem.create' => 1, 'menu.menuitem.store' => 1, 'menu.menuitem.edit' => 1, 'menu.menuitem.update' => 1, 'menu.menuitem.destroy' => 1, 'media.media.index' => 1, 'media.media.create' => 1, 'media.media.store' => 1, 'media.media.edit' => 1, 'media.media.update' => 1, 'media.media.destroy' => 1, 'media.media-grid.index' => 1, 'media.media-grid.ckIndex' => 1, 'setting.settings.index' => 1, 'setting.settings.store' => 1, 'setting.settings.getModuleSettings' => 1, 'page.pages.index' => 1, 'page.pages.create' => 1, 'page.pages.store' => 1, 'page.pages.edit' => 1, 'page.pages.update' => 1, 'page.pages.destroy' => 1]));
     // Create an Users group
     Sentry::createGroup(array('name' => 'User', 'permissions' => ['dashboard.index' => 1]));
 }
Esempio n. 12
0
 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);
 }
Esempio n. 13
0
 public static function getUser($id = 0)
 {
     if ($id == 0) {
         return Sentry::getUser();
     } else {
         return Sentry::findUserById($id);
     }
 }
 public function testDelete()
 {
     $mock = m::mock('Group');
     $mock->shouldReceive('delete')->once()->andReturn(true);
     Sentry::shouldReceive('findGroupById')->with(1)->once()->andReturn($mock);
     $this->assertTrue($this->groups->delete(1));
     Sentry::shouldReceive('findGroupById')->once()->andThrow('Cartalyst\\Sentry\\Groups\\GroupNotFoundException');
     $this->assertFalse($this->groups->delete(10));
 }
Esempio n. 15
0
 /**
  * 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());
     }
 }
Esempio n. 16
0
 public function index()
 {
     $app_id = Config::get('registration::social.fb.api_id');
     $app_secret = Config::get('registration::social.fb.secret_key');
     $my_url = "http://" . $_SERVER['HTTP_HOST'] . "/auth_soc/face_res";
     $code = Input::get("code");
     $state = Input::get("state");
     if (empty($code)) {
         Session::put('state', md5(uniqid(rand(), TRUE)));
         $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=public_profile,publish_actions,email&state=" . Session::get('state') . "&fields=email,first_name,last_name,id,gender";
         header("Location: {$dialog_url}");
     }
     if ($state == Session::get('state')) {
         $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code . "&fields=email,first_name,last_name,id,gender";
         $response = file_get_contents($token_url);
         $params = null;
         parse_str($response, $params);
         $graph_url = "https://graph.facebook.com/me?access_token=" . $params['access_token'] . "&fields=email,first_name,last_name,id,gender";
         $user = json_decode(file_get_contents($graph_url));
         $first_name = $user->first_name;
         $last_name = $user->last_name;
         $fb_id = $user->id;
         if (isset($user->email)) {
             $user_email = $user->email;
         } else {
             $user_email = $fb_id;
         }
         //проверка юзера
         if ($user_email && $fb_id) {
             $user = DB::table("users")->where("id_fb", $fb_id)->first();
             if (!$user['id']) {
                 $user = DB::table("users")->where("email", "like", $user_email)->first();
             }
             if (!$user['id']) {
                 $new_pass = str_random(6);
                 $user = Sentry::register(array('email' => $user_email, 'password' => $new_pass, 'id_fb' => $fb_id, 'activated' => "1", 'first_name' => $first_name, 'last_name' => $last_name));
                 $user_auth = Sentry::findUserById($user->id);
                 Sentry::login($user_auth, Config::get('registration::social.fb.remember'));
             } else {
                 $user_auth = Sentry::findUserById($user['id']);
                 Sentry::login($user_auth, Config::get('registration::social.fb.remember'));
             }
             $redirect = Session::get('url_previous', "/");
             Session::forget('url_previous');
             //if not empty redirect_url
             if (Config::get('registration::social.fb.redirect_url')) {
                 $redirect = Config::get('registration::social.fb.redirect_url');
                 Session::flash('id_user', $user_auth->id);
             } else {
                 $redirect = Session::get('url_previous', "/");
                 Session::forget('url_previous');
             }
             return Redirect::to($redirect);
         }
     }
 }
Esempio n. 17
0
 /**
  * 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);
 }
Esempio n. 18
0
 /**
  * @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', 'شما دسترسی به صفحه مورد نظر را ندارید.');
     }
 }
Esempio n. 19
0
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIndex()
 {
     $status = Input::get('type');
     $shops = $this->shop->where('status', '=', $status)->paginate(1);
     foreach ($shops as $k => $v) {
         $shops[$k]['category'] = $this->category->find($v->category_id)->name;
         $shops[$k]['user'] = Sentry::findUserById($v->user_id)->username;
     }
     return Response::json($shops);
 }
Esempio n. 20
0
 public function index()
 {
     if (Input::get("code")) {
         $api_id = Config::get('registration::social.vk.api_id');
         $secret_key = Config::get('registration::social.vk.secret_key');
         $params = array('client_id' => $api_id, 'client_secret' => $secret_key, 'code' => Input::get("code"), 'redirect_uri' => "http://" . $_SERVER['HTTP_HOST'] . "/auth_soc/vk_res");
         $url = 'https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params));
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $result = curl_exec($ch);
         curl_close($ch);
         $data = json_decode($result, true);
         if (isset($data['access_token'])) {
             $str = "https://api.vkontakte.ru/method/getProfiles?uid=" . $data['user_id'] . "&fields=photo_big&access_token=" . $data['access_token'];
             $resp2 = file_get_contents($str);
             $el = json_decode($resp2, true);
             $first_name = $el['response'][0]['first_name'];
             $last_name = $el['response'][0]['last_name'];
             $id_user = $el['response'][0]['uid'];
             $user = DB::table("users")->where("id_vk", $id_user)->first();
             if (!isset($user['id'])) {
                 $new_pass = str_random(6);
                 $user = Sentry::register(array('email' => $id_user, 'password' => $new_pass, 'id_vk' => $id_user, 'activated' => "1", 'first_name' => $first_name, 'last_name' => $last_name));
                 //качаем аватарку юзера
                 if ($el['response'][0]['photo_big'] && Config::get('registration::social.vk.foto')) {
                     $id_one = substr($user->id, 0, 1);
                     $destinationPath = "/storage/users/{$id_one}/{$user->id}/";
                     $path_server = public_path() . $destinationPath;
                     File::makeDirectory($path_server, $mode = 0777, true, true);
                     $foto_resource = file_get_contents($el['response'][0]['photo_big']);
                     $foto_user = time() . basename($el['response'][0]['photo_big']);
                     $f = fopen($_SERVER['DOCUMENT_ROOT'] . $destinationPath . $foto_user, 'w');
                     fwrite($f, $foto_resource);
                     fclose($f);
                     $user->photo = $destinationPath . $foto_user;
                     $user->save();
                 }
                 $user_auth = Sentry::findUserById($user->id);
                 Sentry::login($user_auth, Config::get('registration::social.vk.remember'));
             } else {
                 $user_auth = Sentry::findUserById($user['id']);
                 Sentry::login($user_auth, Config::get('registration::social.vk.remember'));
             }
             //if not empty redirect_url
             if (Config::get('registration::social.vk.redirect_url')) {
                 $redirect = Config::get('registration::social.vk.redirect_url');
                 Session::flash('id_user', $user_auth->id);
             } else {
                 $redirect = Session::get('url_previous', "/");
                 Session::forget('url_previous');
             }
             return Redirect::to($redirect);
         }
     }
 }
Esempio n. 21
0
 public function run()
 {
     $groups = ['Administrator' => ['create' => 1, 'update' => 1, 'delete' => 1, 'view' => 1], 'Moderator' => ['create' => 0, 'update' => 1, 'delete' => 0, 'view' => 1], 'General' => ['create' => 0, 'update' => 0, 'delete' => 0, 'view' => 1]];
     foreach ($groups as $key => $group) {
         try {
             // Create the group
             Sentry::createGroup(array('name' => $key, 'permissions' => $group));
         } catch (Exception $e) {
         }
     }
 }
Esempio n. 22
0
 /**
  * @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]);
 }
Esempio n. 23
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     try {
         // Create the group
         $group = Sentry::createGroup(array('name' => 'Moderator', 'permissions' => array('admin' => 1, 'users' => 1)));
     } catch (Cartalyst\Sentry\Groups\NameRequiredException $e) {
         echo 'Name field is required';
     } catch (Cartalyst\Sentry\Groups\GroupExistsException $e) {
         echo 'Group already exists';
     }
 }
Esempio n. 24
0
 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;
 }
Esempio n. 25
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;
     });
 }
Esempio n. 26
0
 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]);
     }
 }
Esempio n. 27
0
 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};
     }
 }
 /**
  * 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');
 }
Esempio n. 29
0
 /**
  * Deletes specified group.
  * 
  * @param  array $id
  */
 public function delete($id)
 {
     try {
         $group = Sentry::findGroupById($id);
         $group->where('id', $id)->forceDelete();
         \Cache::flush();
         Event::fire('Groups.Deleted', array($id, Carbon::now(), 'Deleted'));
         return 'success';
     } catch (GroupNotFoundException $e) {
         return 'Group was not found.';
     }
 }
Esempio n. 30
0
 public function run()
 {
     DB::table('users')->delete();
     DB::table('groups')->delete();
     DB::table('users_groups')->delete();
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'password' => "admin", 'first_name' => 'System', 'last_name' => 'Admin', 'activated' => 1));
     Sentry::getGroupProvider()->create(array('name' => 'Admin', 'permissions' => array('admin' => 1)));
     Sentry::getGroupProvider()->create(array('name' => 'User', 'permissions' => array('user' => 1)));
     // Assign user permissions
     $adminUser = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     $adminGroup = Sentry::getGroupProvider()->findByName('Admin');
     $adminUser->addGroup($adminGroup);
 }