mardi 15 mai 2018

How to track sessions & invalidate them on demand in Laravel 5.1

It started with invalidating all other sessions except current one when a user changes the password, so with this, I came with a thought, if I am doing this then why shouldn't the user be provided a facility/feature where a user can check a list of his active sessions and invalidate any of them whenever he/she wishes, thus a feature to track the user sessions...

Example: There are three sessions of the user, 1. Windows-Chrome, 2. Android-Chrome, 3. Mac-Safari. Now say user is currently logged in from 2nd one (Android-Chrome) and wishes to invalidate his 3rd session (Mac-Safari), then he should be able to do it. This feature, is what I am tring to achieve.

I'm working with Laravel 5.1 & file-driver based Sessions.

What I've done/tried:

  1. I created a separate sessions table for user (user_sessions) with following properties:

    id (PK), user_id(FK users table), session_id(varchar), ...userAgentProps fields..., created_at, updated_at

  2. Then overrode authenticated() & logout() methods within AuthController, to manage session records within user_sessions table. Whenever a user is authenticated, its session_id is recorded within the table, Whenever a user logs out, that session's record is removed from user_sessions table.

  3. Using user_sessions table, I can show a user the list of his active sessions. Now with this list, I'm providing a button saying invalidate this session which when clicked, would invalidate that particular session.

The Problem: Everything depicted above works just perfectly fine! but with a catch: User should not use remember me feature, Why?: Without remember me cookie, this works perfectly well, but with remember me cookie, browser re-logins the user, so deleting/invalidating the older session becomes of no use, as a fresh new session for the user is created using that remember me cookie within the browser.

The Question: How do I achieve this whole feature along with remember me cookie?



via Chebli Mohamed

lundi 14 mai 2018

How to display tld value from the json given below

From the below json I need to display the values of tld i.e., co.uk, eu, live, org...

Array ( [tldlist] => Array ( [tld] => Array ( [0] => Array ( [tld] => co.uk ) [1] => Array ( [tld] => eu ) [2] => Array ( [tld] => live ) [3] => Array ( [tld] => org ) [4] => Array ( [tld] => Array ( ) ) ) [tldcount] => 5 ) [Command] => GETTLDLIST [APIType] => API [Language] => eng [ErrCount] => 0 [ResponseCount] => 0 [MinPeriod] => Array ( ) [MaxPeriod] => 10 [Server] => SJL1VWRESELL_T [Site] => eNom [IsLockable] => Array ( ) [IsRealTimeTLD] => Array ( ) [TimeDifference] => +0.00 [ExecTime] => 0.000 [Done] => true [TrackingKey] => 7cbc3d47-c11c-4a39-8387-448777e82af5 [RequestDateTime] => 5/14/2018 12:21:18 AM [debug] => Array ( ) ) 1

find below my blade code:

 @foreach($final_data1['tldlist']['tld'] as $key)

    <br>

 @endforeach

Please suggest me corrections in my blade file to display the tld from the above json.



via Chebli Mohamed

dimanche 13 mai 2018

How to use session to be alive between http and https laravel 5.1

We recently bought an SSL from goDaddy domain and the site successfully used that SSL to amazon ec2. Though we will only use the https on a specific url like the billing (eg. https://www.ourdomain.com/billing) and the rest of the sites will still use the "HTTP"

My question is, is it possible for the session to be alive when switching to different protocol or http/https?

I found this link which should be the solution but when I tried adding the

'secure'    => true,
'http_only' => true,

it still didn't work.

Also when I tried logging-in using just the HTTP, i am unable to login. It seems the app is not functioning.

Sorry, this is my first time using SSL on a site. Any pointers is much appreciated.

Regards,



via Chebli Mohamed

vendredi 11 mai 2018

How to display a table in a popup box with javascript?

I have the form below, with 4 comboboxes "Metier" "tache" "tacrification" et "technicien", i select a Metier and a tache, after this i want that a popup box appears and show me a table that contains all the "techniciens" and their "tarification" (of course only the "techniciens" that are related with the "tache" already selected.) after this i select a "technicien" from that table a now the form is completely filled with the "technicien" and it's "tarification". Could anyone help me with this please?

enter image description here

iterventioncontroller

public function create()

{
$client = client::orderBy('id', 'asc')->get();
$metiers = metier::orderBy('id', 'asc')->get();
$technicien = Technicien::orderBy('id', 'desc')->get();
$tarifications = tarificationtache::orderBy('id', 'desc')->get();

return view('intervention.create')->with('technicien', $technicien)- 
>with('client',$client)- 
>with('metiers',$metiers)->with('tarifications',$tarifications);
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
 public function store(InterventionRequest $request)
 {
$intervention = new Intervention();
$intervention ->date_intervention =$request- 
>input('date_intervention');
$intervention ->description =$request->input('description');
$intervention ->duree_prevu =$request->input('duree_prevu');
 if($request->has('statut')){
$intervention->statut = $request->input('statut');
}else{
       $intervention->statut = 0;
}

$intervention ->technicien_id = $request->input('technicien_id');
$intervention ->client_id = $request->input('client_id');
$intervention ->tarification_id = $request->tarification_id;
$intervention->save();
return redirect('intervention');

}

create.blade.php

 @extends('Layouts/app')
 @extends('Layouts/master')

 @section('content')
 <!--  jQuery -->
 <script 

src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>



<script type="text/javascript">


var getTachesByMetierUrl = "";
var getAdresseByClientUrl = "";
var getTarificationsByTacheUrl = "";
var getTechniciensByTarificationtacheUrl = " 
";

//console.log(getMetiersByTechnicienUrl,getTachesByMetierUrl,getTarificationsByTacheUrl);

    function getAdresseByClient(val) {
    if(val.length>0) {
        var client_id = val;
        $.get(getAdresseByClientUrl+'/'+client_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.adresses,function(index,item) {
                html+='<option 
    value="'+item.id+'">'+item.code_postal+'</option>';
            });
            $('#adresses').html(html);

        });
    }
    }


function getTachesByMetier(val) {
    if(val.length>0) {
        var metier_id = val;
        $.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.taches,function(index,item) {
                html+='<option 
  value="'+item.id+'">'+item.libelle_tache+'</option>';
            });
            $('#taches').html(html);

        });
    }
}
function getTarificationsByTache(val) {

    if(val.length>0) {
        var tache_id = val;
        $.get(getTarificationsByTacheUrl+'/'+tache_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.tarifications,function(index,item) {
                html+='<option 
  value="'+item.id+'">'+item.tarif+'</option>';
            });
            $('#tarifications').html(html);

        });
    }
}

function getTechniciensByTarificationtache(val) {
    if(val.length>0) {
        var tarificationtache_id = val;
        $.get(getTechniciensByTarificationtacheUrl+'/'+tarificationtache_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.techniciens,function(index,item) {
                html+='<option value="'+item.id+'">'+item.id+'</option>';
            });
            $('#techniciens').html(html);

        });
    }
}

@if(count($errors))
<div class="alert alert-danger" role="alert">
    <ul>
        @foreach($errors ->all() as $message)
            <li></li>
        @endforeach
    </ul>
</div>
@endif
<div class="container">
<div class="row"></div>
<div class="col-md-10">
    <h1>Ajout Intervention</h1>
    <form action=" " method="post">
        
        <div class="form-group">
            <label for="client">Client</label>
            <select onchange="getAdresseByClient(this.value)" 
 name="client_id" id="client" 
 class="form-control">
                <option value="">-Select-</option>
                @foreach($client as $t)
                    <option value="">
                        
                    </option>
                @endforeach
            </select>
        </div>


        <div class="form-group">
            <label for="">date intervention</label>

            <input class="form-control" type="date" id="example-date- 
 input" name 
 ="date_intervention" value="">
        </div>

        <div class="form-group">
            <label for="">description</label>
            <input type="text"  name ="description" class="form- 
 control"value=" 
 ">
        </div>


        <div class="form-group">
            <label for="">duree_prevu</label>
            <input class="form-control" type="datetime-local"  name 
 ="duree_prevu" value=" 
 ">
        </div>

 <div class="form-group">
            <div class="col-md-12">
            <div class="col-md-4">
            <label>Metier: </label>
            <select onchange="getTachesByMetier(this.value)" 
style="width: 200px" 
class="productm form-control" id="metiers">
           <option value="">-Select-</option>
                    @foreach($metiers as $t)
                    <option value="">
                        
                    </option>
                @endforeach
            </select>
        </div>

        <div class="col-md-4">
            <label>tache: </label>
            <select onchange="getTarificationsByTache(this.value)" 
style="width: 200px" 
class="productname form-control" name="tache" id="taches">
            <option value="">-Select-</option>
            </select>
        </div>

        <div class="col-md-4">
            <label>tarification: </label>
            <select 
 onchange="getTechniciensByTarificationtache(this.value)" 
 style="width: 
 200px" class="productname form-control" name="tarificationtache_id" 
 id="tarifications">
            <option value="">-Select-</option>
            </select>
        </div>

        <div class="col-md-4">
                    <label>technicien: </label>
                    <select style="width: 200px" class="productname 
 form-control" 
 name="technicien_id" id="techniciens">
                        <option value="">-Select-</option>
                    </select>
                </div>



 </div>
 </div>

 </div>
 </div>
 </div>

 <link 

href="https://ift.tt/1jAc5cP" rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/css/bootstrap- 
datepicker.css" rel="stylesheet">

<script 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"> 
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/js/bootstrap-         
datepicker.js"></script>
@endsection



via Chebli Mohamed

RDS Laravel SQLSTATE[HY000] [2002] Connection refused

I am trying to connect my Laravel 5.1 application using rds mysql. But it ended up in getting

SQLSTATE[HY000] [2002] Connection refused

The same rds database is using in other EC2 instance. But it works fine there. Only difference between two EC2 is the security group. As i come to notice that 3306 port should be open for mysql. I make it open in my security group. But still getting the same error. Can anybody help me to resolve this issue?

Thanks in advance for any help



via Chebli Mohamed

jeudi 10 mai 2018

White Screen of Death in Laravel Project

I have a Laravel 5.1 app that for some reason I can’t see any stack trace or an error at all.

I tried to name my function wrong to cause this error.

In a normal set up, I would see this

enter image description here

But another set up, I only see a white blank screen, even if I have APP_DEBUG set to true

I think I am haunted by the white screen of death. :(


Questions

I can only see this on 1 specific set up.

What should I check more on that set up to get this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!

I've looked at all of these already

tail -f usr/share/ssc-portal/storage/logs/laravel.log
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log
tail -f /var/log/fpm-php.www.log

/var/log/messages
/var/log/secure
/var/log/syslog



via Chebli Mohamed

mercredi 9 mai 2018

How to convert the below mentioned xml data into json array in laravel

Find below the xml data:

<?xml version="1.0" encoding="utf-8"?> <interface-response> <Command>CHECK</Command> <APIType>API.NET</APIType> <Language>eng</Language> <ErrCount>1</ErrCount> <errors> <Err1>User not permitted from this IP address - 113.193.131.41. See http://enom.help/whitelist for details</Err1> </errors> <ResponseCount>1</ResponseCount> <responses> <response> <ResponseNumber>713254</ResponseNumber> <ResponseString>Policy error; unauthorized; user(s)</ResponseString> </response> </responses> <MinPeriod>1</MinPeriod> <MaxPeriod>10</MaxPeriod> <Server>sjl0vwapi08</Server> <Site>eNom</Site> <IsLockable>True</IsLockable> <IsRealTimeTLD>True</IsRealTimeTLD> <TimeDifference>+7.00</TimeDifference> <ExecTime>0.034</ExecTime> <Done>true</Done> <TrackingKey>5baa515b-8e29-4517-b879-05ae68e94f9a</TrackingKey> <RequestDateTime>5/9/2018 3:49:10 AM</RequestDateTime> <debug/> </interface-response>

I need to convert the above xml data to json array and pass it to view from the controller.

Find below the conrtroller code:

public function test()
{

    $response = Curl::to('https://reseller.enom.com/interface.asp?command=check&sld=decksys&tld=info&responsetype=xml&uid=decksys&pw=Amy.th3ist4917')->get();         


 $data = simplexml_load_string($response);

 $configdata   = json_encode($data);

 $value = json_decode($configdata, true);

 return view('clientlayout.main.test', array('response' =>$response));

 }

Find below the view code:



The route is given below:

Route::get('/test','EnomController@test');

suggest a solution solve this and print the data in my view page.



via Chebli Mohamed