| @@ -6,28 +6,28 @@ | ||
| 6 | 6 | |
| 7 | 7 | class BantenprovSsoServiceProvider extends ServiceProvider | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * Bootstrap the application services. | |
| 11 | - * | |
| 12 | - * @return void | |
| 13 | - */ | |
| 14 | - public function boot() | |
| 15 | -    { | |
| 16 | - include __DIR__.'/BantenprovSso.php'; | |
| 17 | - $this->publishes([ | |
| 18 | -        __DIR__ . '/views'          => base_path('public/js'), | |
| 19 | -        __DIR__ . '/controllers'    => base_path('app/Http/Controllers'), | |
| 20 | - ]); | |
| 21 | -        $this->commands('Bantenprov\BantenprovSso\Commands\RouteCommands'); | |
| 22 | - } | |
| 9 | + /** | |
| 10 | + * Bootstrap the application services. | |
| 11 | + * | |
| 12 | + * @return void | |
| 13 | + */ | |
| 14 | + public function boot() | |
| 15 | +	{ | |
| 16 | + include __DIR__.'/BantenprovSso.php'; | |
| 17 | + $this->publishes([ | |
| 18 | +		__DIR__ . '/views'          => base_path('public/js'), | |
| 19 | +		__DIR__ . '/controllers'    => base_path('app/Http/Controllers'), | |
| 20 | + ]); | |
| 21 | +		$this->commands('Bantenprov\BantenprovSso\Commands\RouteCommands'); | |
| 22 | + } | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * Register the application services. | |
| 26 | - * | |
| 27 | - * @return void | |
| 28 | - */ | |
| 29 | - public function register() | |
| 30 | -    { | |
| 31 | - // | |
| 32 | - } | |
| 24 | + /** | |
| 25 | + * Register the application services. | |
| 26 | + * | |
| 27 | + * @return void | |
| 28 | + */ | |
| 29 | + public function register() | |
| 30 | +	{ | |
| 31 | + // | |
| 32 | + } | |
| 33 | 33 | } | 
| @@ -11,146 +11,146 @@ | ||
| 11 | 11 | |
| 12 | 12 | class DevelController extends Controller | 
| 13 | 13 |  { | 
| 14 | - public function login() | |
| 15 | -    { | |
| 16 | - if(!Auth::check()) | |
| 17 | -    	{ | |
| 18 | -    		return view('pages.credential.login'); | |
| 19 | - } | |
| 20 | -    	return Redirect::to('dashboard'); | |
| 21 | - } | |
| 22 | - | |
| 23 | - public function post_login(Request $request) | |
| 24 | -    { | |
| 25 | - $validator = Validator::make($request->all(), | |
| 26 | - [ | |
| 27 | - 'email' => 'required|email', | |
| 28 | - 'password' => 'required' | |
| 29 | - ]); | |
| 30 | - | |
| 31 | - if($validator->fails()) | |
| 32 | -    	{ | |
| 33 | -    		Session::flash('message', 'Data tidak boleh kosong'); | |
| 34 | - return redirect()->back() | |
| 35 | - ->withErrors($validator) | |
| 36 | - ->withInput(); | |
| 37 | - } | |
| 38 | - $credential = [ | |
| 39 | -    	'email'			=> $request->input('email'),  | |
| 40 | -    	'password'		=> $request->input('password'), | |
| 41 | -    	'ipaddress'		=> $request->input('ip1').'-'.$request->input('ip2') | |
| 42 | - ]; | |
| 43 | - | |
| 44 | - //set session | |
| 45 | -    	Session(['ipaddress' => $request->input('ip1').'-'.$request->input('ip2')]); | |
| 46 | - | |
| 47 | - if(!BantenprovSso::Attempt($credential)) | |
| 48 | -    	{ | |
| 49 | - //dd(BantenprovSso::message()); | |
| 50 | -    		Session::flash('message', 'terjadi kesalah, login tidak berhasil'); | |
| 51 | - return redirect()->back() | |
| 52 | - ->withErrors(BantenprovSso::message()) | |
| 53 | - ->withInput(); | |
| 54 | - } | |
| 55 | - //dd(BantenprovSso::data()); | |
| 56 | - $data = BantenprovSso::data(); | |
| 57 | - //check data user pada table user | |
| 58 | -    	$user = User::where('email', $data->email) | |
| 59 | - ->first(); | |
| 60 | - if(count($user) == 0) | |
| 61 | -    	{ | |
| 62 | - //return 'gak ada'; | |
| 63 | - //insert data user | |
| 64 | - $create_user = new User; | |
| 65 | - $create_user->email = $data->email; | |
| 66 | - $create_user->name = $data->name; | |
| 67 | - $create_user->password = $data->password; | |
| 68 | - $create_user->save(); | |
| 69 | - | |
| 70 | - return Self::init_login($create_user); | |
| 71 | - } | |
| 72 | - else | |
| 73 | -    	{ | |
| 74 | - return Self::init_login($user); | |
| 75 | - } | |
| 76 | - | |
| 77 | - } | |
| 78 | - | |
| 79 | - public function init_login($data) | |
| 80 | -    { | |
| 81 | - //login with id | |
| 82 | - //dd($data->id); | |
| 83 | - if(Auth::loginUsingId($data->id)) | |
| 84 | -    	{ | |
| 85 | -    		return redirect::to('dashboard'); | |
| 86 | - | |
| 87 | - } | |
| 88 | - else | |
| 89 | -    	{ | |
| 90 | - //false | |
| 91 | -    		return Redirect::to('login'); | |
| 92 | - } | |
| 93 | - | |
| 94 | - | |
| 95 | - } | |
| 96 | - | |
| 97 | - public function check_logout(Request $request) | |
| 98 | -    { | |
| 99 | -    	if(BantenprovSso::check_logout(['ipaddress' => $request->input('ipaddress')])) | |
| 100 | -    	{ | |
| 101 | - return 1; | |
| 102 | - } | |
| 103 | - else | |
| 104 | -    	{ | |
| 105 | - return 0; | |
| 106 | - } | |
| 107 | - } | |
| 108 | - | |
| 109 | - public function check_login(Request $request) | |
| 110 | -    { | |
| 111 | -    	$check = BantenprovSso::check_login(['ipaddress' => $request->input('ipaddress')]); | |
| 112 | - if(!$check) | |
| 113 | -    	{ | |
| 114 | - return 0; | |
| 115 | - } | |
| 116 | - else | |
| 117 | -    	{ | |
| 118 | - // cari atau simpan data baru | |
| 119 | - $teng = BantenprovSso::check_login_data(); | |
| 120 | -    		$user_data = User::where('email', $teng->email)->first(); | |
| 121 | - if(count($user_data) == 0) | |
| 122 | -    		{ | |
| 123 | - //simpan data baru | |
| 124 | - $simpan = new User; | |
| 125 | - $simpan->email = $teng->email; | |
| 126 | - $simpan->name = $teng->name; | |
| 127 | - $simpan->password = 'bantenprov'; | |
| 128 | - $simpan->save(); | |
| 129 | - | |
| 130 | - Auth::loginUsingId($simpan->id); | |
| 131 | - return 1; | |
| 132 | - } | |
| 133 | - else | |
| 134 | -    		{ | |
| 135 | - Auth::loginUsingId($user_data->id); | |
| 136 | - return 1; | |
| 137 | - } | |
| 138 | - } | |
| 139 | - } | |
| 140 | - | |
| 141 | - public function cas_logout() | |
| 142 | -    { | |
| 143 | - Auth::logout(); | |
| 144 | -    	Session()->forget('ipaddress'); | |
| 145 | - return 1; | |
| 146 | - } | |
| 14 | + public function login() | |
| 15 | +	{ | |
| 16 | + if(!Auth::check()) | |
| 17 | +		{ | |
| 18 | +			return view('pages.credential.login'); | |
| 19 | + } | |
| 20 | +		return Redirect::to('dashboard'); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public function post_login(Request $request) | |
| 24 | +	{ | |
| 25 | + $validator = Validator::make($request->all(), | |
| 26 | + [ | |
| 27 | + 'email' => 'required|email', | |
| 28 | + 'password' => 'required' | |
| 29 | + ]); | |
| 30 | + | |
| 31 | + if($validator->fails()) | |
| 32 | +		{ | |
| 33 | +			Session::flash('message', 'Data tidak boleh kosong'); | |
| 34 | + return redirect()->back() | |
| 35 | + ->withErrors($validator) | |
| 36 | + ->withInput(); | |
| 37 | + } | |
| 38 | + $credential = [ | |
| 39 | +		'email'			=> $request->input('email'),  | |
| 40 | +		'password'		=> $request->input('password'), | |
| 41 | +		'ipaddress'		=> $request->input('ip1').'-'.$request->input('ip2') | |
| 42 | + ]; | |
| 43 | + | |
| 44 | + //set session | |
| 45 | +		Session(['ipaddress' => $request->input('ip1').'-'.$request->input('ip2')]); | |
| 46 | + | |
| 47 | + if(!BantenprovSso::Attempt($credential)) | |
| 48 | +		{ | |
| 49 | + //dd(BantenprovSso::message()); | |
| 50 | +			Session::flash('message', 'terjadi kesalah, login tidak berhasil'); | |
| 51 | + return redirect()->back() | |
| 52 | + ->withErrors(BantenprovSso::message()) | |
| 53 | + ->withInput(); | |
| 54 | + } | |
| 55 | + //dd(BantenprovSso::data()); | |
| 56 | + $data = BantenprovSso::data(); | |
| 57 | + //check data user pada table user | |
| 58 | +		$user = User::where('email', $data->email) | |
| 59 | + ->first(); | |
| 60 | + if(count($user) == 0) | |
| 61 | +		{ | |
| 62 | + //return 'gak ada'; | |
| 63 | + //insert data user | |
| 64 | + $create_user = new User; | |
| 65 | + $create_user->email = $data->email; | |
| 66 | + $create_user->name = $data->name; | |
| 67 | + $create_user->password = $data->password; | |
| 68 | + $create_user->save(); | |
| 69 | + | |
| 70 | + return Self::init_login($create_user); | |
| 71 | + } | |
| 72 | + else | |
| 73 | +		{ | |
| 74 | + return Self::init_login($user); | |
| 75 | + } | |
| 76 | + | |
| 77 | + } | |
| 78 | + | |
| 79 | + public function init_login($data) | |
| 80 | +	{ | |
| 81 | + //login with id | |
| 82 | + //dd($data->id); | |
| 83 | + if(Auth::loginUsingId($data->id)) | |
| 84 | +		{ | |
| 85 | +			return redirect::to('dashboard'); | |
| 86 | + | |
| 87 | + } | |
| 88 | + else | |
| 89 | +		{ | |
| 90 | + //false | |
| 91 | +			return Redirect::to('login'); | |
| 92 | + } | |
| 93 | + | |
| 94 | + | |
| 95 | + } | |
| 96 | + | |
| 97 | + public function check_logout(Request $request) | |
| 98 | +	{ | |
| 99 | +		if(BantenprovSso::check_logout(['ipaddress' => $request->input('ipaddress')])) | |
| 100 | +		{ | |
| 101 | + return 1; | |
| 102 | + } | |
| 103 | + else | |
| 104 | +		{ | |
| 105 | + return 0; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + public function check_login(Request $request) | |
| 110 | +	{ | |
| 111 | +		$check = BantenprovSso::check_login(['ipaddress' => $request->input('ipaddress')]); | |
| 112 | + if(!$check) | |
| 113 | +		{ | |
| 114 | + return 0; | |
| 115 | + } | |
| 116 | + else | |
| 117 | +		{ | |
| 118 | + // cari atau simpan data baru | |
| 119 | + $teng = BantenprovSso::check_login_data(); | |
| 120 | +			$user_data = User::where('email', $teng->email)->first(); | |
| 121 | + if(count($user_data) == 0) | |
| 122 | +			{ | |
| 123 | + //simpan data baru | |
| 124 | + $simpan = new User; | |
| 125 | + $simpan->email = $teng->email; | |
| 126 | + $simpan->name = $teng->name; | |
| 127 | + $simpan->password = 'bantenprov'; | |
| 128 | + $simpan->save(); | |
| 129 | + | |
| 130 | + Auth::loginUsingId($simpan->id); | |
| 131 | + return 1; | |
| 132 | + } | |
| 133 | + else | |
| 134 | +			{ | |
| 135 | + Auth::loginUsingId($user_data->id); | |
| 136 | + return 1; | |
| 137 | + } | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + public function cas_logout() | |
| 142 | +	{ | |
| 143 | + Auth::logout(); | |
| 144 | +		Session()->forget('ipaddress'); | |
| 145 | + return 1; | |
| 146 | + } | |
| 147 | 147 | |
| 148 | 148 | public function logout() | 
| 149 | -    { | |
| 150 | - Auth::logout(); | |
| 151 | -    	BantenprovSso::Logout(['ipaddress' => Session::get('ipaddress')]); | |
| 152 | -    	Session()->forget('ipaddress'); | |
| 153 | -    	return Redirect::to('/login'); | |
| 154 | - } | |
| 149 | +	{ | |
| 150 | + Auth::logout(); | |
| 151 | +		BantenprovSso::Logout(['ipaddress' => Session::get('ipaddress')]); | |
| 152 | +		Session()->forget('ipaddress'); | |
| 153 | +		return Redirect::to('/login'); | |
| 154 | + } | |
| 155 | 155 | |
| 156 | 156 | } | 
| @@ -17,51 +17,51 @@ | ||
| 17 | 17 | |
| 18 | 18 | class RouteCommands extends Command | 
| 19 | 19 |  { | 
| 20 | - /** | |
| 21 | - * The name and signature of the console command. | |
| 22 | - * | |
| 23 | - * @var string | |
| 24 | - */ | |
| 25 | - protected $signature = 'bantenprov-sso:add-route'; | |
| 20 | + /** | |
| 21 | + * The name and signature of the console command. | |
| 22 | + * | |
| 23 | + * @var string | |
| 24 | + */ | |
| 25 | + protected $signature = 'bantenprov-sso:add-route'; | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * The console command description. | |
| 29 | - * | |
| 30 | - * @var string | |
| 31 | - */ | |
| 32 | - protected $description = 'Add sso rotes to web route'; | |
| 27 | + /** | |
| 28 | + * The console command description. | |
| 29 | + * | |
| 30 | + * @var string | |
| 31 | + */ | |
| 32 | + protected $description = 'Add sso rotes to web route'; | |
| 33 | 33 | |
| 34 | - /** | |
| 35 | - * Create a new command instance. | |
| 36 | - * | |
| 37 | - * @return void | |
| 38 | - */ | |
| 34 | + /** | |
| 35 | + * Create a new command instance. | |
| 36 | + * | |
| 37 | + * @return void | |
| 38 | + */ | |
| 39 | 39 | |
| 40 | - protected $drip; | |
| 40 | + protected $drip; | |
| 41 | 41 | |
| 42 | - public function __construct() | |
| 43 | -    { | |
| 44 | - parent::__construct(); | |
| 42 | + public function __construct() | |
| 43 | +	{ | |
| 44 | + parent::__construct(); | |
| 45 | 45 | |
| 46 | - } | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | - * Execute the console command. | |
| 50 | - * | |
| 51 | - * @return mixed | |
| 52 | - */ | |
| 48 | + /** | |
| 49 | + * Execute the console command. | |
| 50 | + * | |
| 51 | + * @return mixed | |
| 52 | + */ | |
| 53 | 53 | |
| 54 | - protected function content() | |
| 55 | -    { | |
| 54 | + protected function content() | |
| 55 | +	{ | |
| 56 | 56 | |
| 57 | - $replace_middleware = File::get(__DIR__.'/../stubs/route.stub'); | |
| 58 | - return $replace_middleware; | |
| 59 | - } | |
| 57 | + $replace_middleware = File::get(__DIR__.'/../stubs/route.stub'); | |
| 58 | + return $replace_middleware; | |
| 59 | + } | |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - public function handle() | |
| 63 | -    {                | |
| 64 | -        $this->info('Route add success');  | |
| 65 | -        File::append(base_path('routes/web.php'),"\n".$this->content());         | |
| 66 | - } | |
| 62 | + public function handle() | |
| 63 | +	{                | |
| 64 | +		$this->info('Route add success');  | |
| 65 | +		File::append(base_path('routes/web.php'),"\n".$this->content());         | |
| 66 | + } | |
| 67 | 67 | } | 
| @@ -42,7 +42,7 @@ discard block | ||
| 42 | 42 | curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post)); | 
| 43 | 43 | curl_setopt($curl,CURLOPT_TIMEOUT,20); | 
| 44 | 44 | curl_setopt($curl,CURLOPT_HTTPHEADER, array( | 
| 45 | - 'Accept: application/json') | |
| 45 | + 'Accept: application/json') | |
| 46 | 46 | ); | 
| 47 | 47 | $exec=curl_exec($curl); | 
| 48 | 48 | if(!$exec) | 
| @@ -71,7 +71,7 @@ discard block | ||
| 71 | 71 | curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post)); | 
| 72 | 72 | curl_setopt($curl,CURLOPT_TIMEOUT,20); | 
| 73 | 73 | curl_setopt($curl,CURLOPT_HTTPHEADER, array( | 
| 74 | - 'Accept: application/json') | |
| 74 | + 'Accept: application/json') | |
| 75 | 75 | ); | 
| 76 | 76 | $exec=curl_exec($curl); | 
| 77 | 77 | if(!$exec) | 
| @@ -94,7 +94,7 @@ discard block | ||
| 94 | 94 | curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post)); | 
| 95 | 95 | curl_setopt($curl,CURLOPT_TIMEOUT,20); | 
| 96 | 96 | curl_setopt($curl,CURLOPT_HTTPHEADER, array( | 
| 97 | - 'Accept: application/json') | |
| 97 | + 'Accept: application/json') | |
| 98 | 98 | ); | 
| 99 | 99 | $exec=curl_exec($curl); | 
| 100 | 100 | |
| @@ -136,7 +136,7 @@ discard block | ||
| 136 | 136 | curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($post)); | 
| 137 | 137 | curl_setopt($curl,CURLOPT_TIMEOUT,20); | 
| 138 | 138 | curl_setopt($curl,CURLOPT_HTTPHEADER, array( | 
| 139 | - 'Accept: application/json') | |
| 139 | + 'Accept: application/json') | |
| 140 | 140 | ); | 
| 141 | 141 | $exec=curl_exec($curl); | 
| 142 | 142 | //dd($exec); | 
| @@ -153,21 +153,21 @@ discard block | ||
| 153 | 153 | static function InitAddress() | 
| 154 | 154 |  	{ | 
| 155 | 155 | $ipaddress = ''; | 
| 156 | -	    if (getenv('HTTP_CLIENT_IP')) | |
| 157 | -	        $ipaddress = getenv('HTTP_CLIENT_IP'); | |
| 158 | -	    else if(getenv('HTTP_X_FORWARDED_FOR')) | |
| 159 | -	        $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); | |
| 160 | -	    else if(getenv('HTTP_X_FORWARDED')) | |
| 161 | -	        $ipaddress = getenv('HTTP_X_FORWARDED'); | |
| 162 | -	    else if(getenv('HTTP_FORWARDED_FOR')) | |
| 163 | -	        $ipaddress = getenv('HTTP_FORWARDED_FOR'); | |
| 164 | -	    else if(getenv('HTTP_FORWARDED')) | |
| 165 | -	       $ipaddress = getenv('HTTP_FORWARDED'); | |
| 166 | -	    else if(getenv('REMOTE_ADDR')) | |
| 167 | -	        $ipaddress = getenv('REMOTE_ADDR'); | |
| 168 | - else | |
| 169 | - $ipaddress = 'UNKNOWN'; | |
| 170 | - return $ipaddress; | |
| 156 | +		if (getenv('HTTP_CLIENT_IP')) | |
| 157 | +			$ipaddress = getenv('HTTP_CLIENT_IP'); | |
| 158 | +		else if(getenv('HTTP_X_FORWARDED_FOR')) | |
| 159 | +			$ipaddress = getenv('HTTP_X_FORWARDED_FOR'); | |
| 160 | +		else if(getenv('HTTP_X_FORWARDED')) | |
| 161 | +			$ipaddress = getenv('HTTP_X_FORWARDED'); | |
| 162 | +		else if(getenv('HTTP_FORWARDED_FOR')) | |
| 163 | +			$ipaddress = getenv('HTTP_FORWARDED_FOR'); | |
| 164 | +		else if(getenv('HTTP_FORWARDED')) | |
| 165 | +		   $ipaddress = getenv('HTTP_FORWARDED'); | |
| 166 | +		else if(getenv('REMOTE_ADDR')) | |
| 167 | +			$ipaddress = getenv('REMOTE_ADDR'); | |
| 168 | + else | |
| 169 | + $ipaddress = 'UNKNOWN'; | |
| 170 | + return $ipaddress; | |
| 171 | 171 | } | 
| 172 | 172 | |
| 173 | 173 | static function init() |