KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How many users can see the panel #2268

Open daniel opened this topic on on Aug 17, 2021 - 52 comments

daniel commented on Aug 17, 2021

multiuser dashboard with sql

KoolReport commented on Aug 18, 2021

May I know your license number? It seems you posted from unlicensed one. Plus our SLA for licensed users is 24 hour response and we will assist you within 24h. Keep spamming is not a good way to get attention. Here is our forum guidelines.

And please tell me exactly what you want to complete in dashboard?

Javier Gallardo commented on Aug 18, 2021

Hi I am Daniel now that you know that I have everything bought help me with kindness. I need know if I can use the panel for a multi user that login with my database SQL and show the graphs for the logged in user

KoolReport commented on Aug 19, 2021

Yes, of course, you can use Dashboard for multiusers and create dashboard based on a specific logged user. The user A should see data of his, and user B should see B's data. In this post we have answer how to use authentication with SQL DataSource to facilitate user login.

So when a user login, you will get a User object containing id, name and role of them that you can access anywhere from $this->app()->user(), for example in a Widget, you can get data for specific user like this:

class PaymentTable extends Table
{
    protected function dataSource()
    {
        $userId = $this->app()->user()->id();
        return AutoMaker::table("payments")->where("user_id",$userId);
    }
}

Hope that helps.

Javier Gallardo commented on Aug 19, 2021

I need a more extensive tutorial for this, in the documentation there is nothing please

Javier Gallardo commented on Aug 19, 2021

I payed for eveterithing only for this work

Javier Gallardo commented on Aug 19, 2021

now I just try to create the login, but I need more documentation for this.

KoolReport commented on Aug 19, 2021

Well, you just need to define a datasource class like this:

AutoMaker.php

AutoMaker here is an datasource extending from MySQL. And inside connection() method, you define your connection to your database.

After that, you can use your datasource anywhere in your application. for example:

AutoMaker::table("customers")->run(); //Return all customers

More about datasource, you can read our documentation here

Let us know if you need further assistance.

Javier Gallardo commented on Aug 19, 2021

Please I need a extensive documentation for my petition, no only tracks

Javier Gallardo commented on Aug 19, 2021

First I need create the Login, how I connect the login with the database in App.php

Javier Gallardo commented on Aug 19, 2021

App.php

use \koolreport\dashboard\Application;
use \koolreport\dashboard\pages\Login;
use \koolreport\dashboard\User;

class App extends Application
{
	 protected function login()
    {
        return  Login::create()
      ->authenticate(function($username,$password) {
    $users = User::table("users")
                    ->where("username",$username)
                    ->where("password",md5($password))
                    ->run();
    // The $users is DataStore object which contain list of user, 
    // something like Collection class in Laravel if you know.
    $user = $users->get(0);
    if($user==null) return null;
    return User::create()
                ->id($user["id"])
                ->name($user["name"]);
            });
    }
}
Javier Gallardo commented on Aug 19, 2021

it doesn't work for me

KoolReport commented on Aug 19, 2021

I see that you use the User class in here

$users = User::table("users")  // <--here
                    ->where("username",$username)
                    ->where("password",md5($password))
                    ->run();

which seems not correct. It should be your datasource class, for example like AutoMaker in our example.

May you post also your datasource class.

Please remember: Our code is just example, you need to apply to your own case. For example, we use column "username" and "password" but they may have other names in your database.

Javier Gallardo commented on Aug 19, 2021

<?php //App.php use \koolreport\dashboard\Application; use \koolreport\dashboard\pages\Login; use \koolreport\dashboard\User;

class App extends Application {

 protected function login()
{
    return  Login::create()
  ->authenticate(function($username,$password) {
$users = AutoMaker::table("users")
                ->where("username",$username)
                ->where("password",md5($password))
                ->run();
// The $users is DataStore object which contain list of user, 
// something like Collection class in Laravel if you know.
$user = $users->get(0);
if($user==null) return null;
return User::create()
            ->id($user["id"])
            ->name($user["name"]);
        });
}

} don't work

KoolReport commented on Aug 19, 2021

Please use different class name for your datasource, don't use User as it will be conflict with User class of dashboard.

Javier Gallardo commented on Aug 19, 2021

I use automaker

KoolReport commented on Aug 19, 2021

Could you please post your AutoMaker class

Javier Gallardo commented on Aug 19, 2021
<?php

use \koolreport\dashboard\sources\MySQL;

class AutoMaker extends MySQL
{
    protected function connection()
    {
        return [
            "connectionString"=>"mysql:host=localhost;dbname=prueba",
            "username"=>"User",
            "password"=>"sdfsdfsdf",
            "charset"=>"utf8"
        ];
    }
}
KoolReport commented on Aug 19, 2021

Okay. Does your database "prueba" have table name called "users"? Does the table "users" has column "username" and "password"? I guess there is not, so you will get error. What I shown you here is just pseudo code to guide you how to access database to authenticate user. You need to replace or write your own query. Don't just copy because surely it will not work.

Another suggestion: Instead of using AutoMaker as the datasource name, you should use name like Prueba. It will make more sense.

<?php
//Prueba.php
use \koolreport\dashboard\sources\MySQL;

class Prueba extends MySQL
{
    protected function connection()
    {
        return [
            "connectionString"=>"mysql:host=localhost;dbname=prueba",
            "username"=>"User",
            "password"=>"sdfsdfsdf",
            "charset"=>"utf8"
        ];
    }
}

then later you can query like this:

Prueba::table("your-table-name")->select("column-name")->run();
Javier Gallardo commented on Aug 19, 2021

all the data entered in AutoMake is of database is obviously mine, but it still doesn't work at all ...

Javier Gallardo commented on Aug 19, 2021

The name of my database is PRUEBA and it has a table called USERS with USERNAME EMAIL and PASSWORD with m5d

KoolReport commented on Aug 19, 2021

Please tell me what does not work? What error do you get? "Does't work at all" can not help me to assist you.

Questions:

  1. Which table in your prueba database contains users information such as username, email and password?
  2. Can you tell me the schema of that table? At least the list of table column names
Javier Gallardo commented on Aug 19, 2021

the dashboard doesn't work when I try to enter, it says SOMETHING WRONG

KoolReport commented on Aug 19, 2021

It means that the query for your username and password returns zero record. It does not find any user with that username and password. Please check your username and password if they are correct.

Javier Gallardo commented on Aug 19, 2021

1.-the table USERS 2.- table USERS column USERNAME, PASSWORD, EMAIL

Javier Gallardo commented on Aug 19, 2021

I write anything in username and password and it doesn't even try to validate the fields it just jumps to SOMETHING WRONG

Javier Gallardo commented on Aug 19, 2021

I have record in the table

KoolReport commented on Aug 20, 2021

In general, the authenticate() function will get you the $username and $password which will need you to verify. If username and password is not correct, you return null which will show Something wrong ... result. On contrary, if you find the user with username and password from database, you will return User object with user information like id or name. The logic is simple as that.

Javier Gallardo commented on Aug 20, 2021

the code you sent me doesn't work, it doesn't even validate the fields

KoolReport commented on Aug 20, 2021

I see your column name in database is uppercased, and in the code you use the lowercase, it could be issue. Try to use uppercase to see how

Javier Gallardo commented on Aug 20, 2021

I only write here in my database it is all lowercase

Javier Gallardo commented on Aug 20, 2021

THIS IS THE PROBLEM, WHEN I TRY WITH

    return  Login::create()
  ->authenticate(function($username,$password) {
$users = AutoMaker::table("users")
                ->where("username",$username)
                ->where("password",md5($password))
                ->run();
// The $users is DataStore object which contain list of user, 
// something like Collection class in Laravel if you know.
$user = $users->get(0);
if($user==null) return null;
return User::create()
            ->id($user["id"])
            ->name($user["name"]);
        });
}

} ____THIS IT WORKS

    return  Login::create()
            ->authenticate(function($username,$password){
                if($username==="admin@example.com" && $password==="admin_password")
                {
                    // If authenticated, return User object
                    return User::create()
                        ->id(1)
                        ->name("Admin")
                        ->avatar("avatars/8.jpg")
                        ->roles(["admin"]);
                }
                // If unauthenticated, return null
                return null;
            });
}

}

KoolReport commented on Aug 20, 2021

Let try this:

    return  Login::create()
  ->authenticate(function($username,$password) {
$users = AutoMaker::table("users")
                ->where("username",$username)
                ->where("password",$password)
                ->run();
// The $users is DataStore object which contain list of user, 
// something like Collection class in Laravel if you know.
$user = $users->get(0);
if($user==null) return null;
return User::create()
            ->id($user["id"])
            ->name($user["name"]);
        });
}

Make sure you have "users" table and in table you have id,username,password and name columns. Let try to have a row like this:

idusernamepasswordname
1admin@example.comadmin_passwordAdmin
Javier Gallardo commented on Aug 23, 2021

it does not work

Javier Gallardo commented on Aug 23, 2021

the problem is in the code you give me

    return  Login::create()
  ->authenticate(function($username,$password) {
$users = AutoMaker::table("users")
                ->where("username",$username)
                ->where("password",$password)
                ->run();
// The $users is DataStore object which contain list of user, 
// something like Collection class in Laravel if you know.
$user = $users->get(0);
if($user==null) return null;
return User::create()
            ->id($user["id"])
            ->name($user["name"]);
        });
}
Javier Gallardo commented on Aug 23, 2021

I've been with Koolreport for a week and I haven't made any progress, I have paid for everything and it has not been of any use, I am already regretting this

KoolReport commented on Aug 23, 2021

Well, it always take a little time for learning, be patient and you will make progress, no worry. Thousand of developers have used Dashboard framework so for sure we will not make a not-working product and we can sell.. so no worry, you will get what you need. I have talked to dev.team to make a simple working example for you and will share code to Github. I will keep you update on this.

Javier Gallardo commented on Aug 23, 2021

We need extensive documentation and more video tutorials please, it is very bad that they have only one video on YouTube

Javier Gallardo commented on Aug 24, 2021

I need work with JSON, I don't see tutorials to use JSON

KoolReport commented on Aug 25, 2021

Our dev.team has been added "login using database" into our demo. Here is the working code

    protected function login()
    {
        return  Login::create()
                ->descriptionText("
                    <i style='color:#333'>
                    Please log in with <b class='text-danger'>demo</b>/<b class='text-danger'>demo</b>
                    </i>
                ")
                ->failedText("Wrong! Please use <b>demo</b> for both username and password!")
                ->authenticate(function ($username, $password) {

                    //Look for user that have username and password 
                    $users = AutoMaker::table("users")
                                ->where("username",$username)
                                ->where("password",$password)
                                ->run();
                                
                    $user = $users->get(0);//Try to get first user, get associate array contain user information

                    if($user!==null) {
                        //Found a user, return User object
                        return User::create()
                        ->id($user["id"])
                        ->name($user["displayname"])
                        ->avatar("images/8.jpg")
                        ->roles([$user["role"]]);                        
                    }

                    //Other: fail to login, return null
                    return null;
                });
    }

Alternatively you can View On Github.

We have added a table called "users" to AutoMaker database and here is the schema and data of "users" table:

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `displayname` varchar(50) NOT NULL,
  `role` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`, `displayname`, `role`) VALUES
(1, 'admin', 'admin', 'Admin', 'admin'),
(2, 'demo', 'demo', 'Demo', 'user');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

We have implemented the login into our online demo as well at Dashboard Demo. So according to data of users table, beside login with "demo/demo", you can login with "admin/admin".

Hope that helps.

Javier Gallardo commented on Aug 25, 2021

It doesn't work for me, I'm going to try it all week.

KoolReport commented on Aug 25, 2021

This is just example to show you how to do login with user data from database. We want to show you the frame of code, how it should be done and also show you that it works. Your application will have its own unique characteristics like different tables, different columns so you will need to insert your own code that we will not able to write for you, you need to do it by yourself.

The framework like Dashboard will save you effort in long run but not in short run since you will have to take little time to learn structure of framework. It is like you purchase an microwave to cook food faster but still you need to learn how to use microwave.

About the role of user, you insert list of roles into roles() method (the list o role can comes from db), for example:

User::create()
->roles(["user","moderator"]);

So later in any where, you can do:

if($this->app()->user()->hasRole("moderator")) {
    //Doing something
}

That's how user roles works.

Javier Gallardo commented on Aug 25, 2021

I DON'T NEED ROLES

KoolReport commented on Aug 25, 2021

Then remove the roles

Javier Gallardo commented on Aug 25, 2021

ok I will try thanks

Javier Gallardo commented on Aug 25, 2021

I just press the login button I don't even fill in the fields and it sends me an error SOMETHING WRONG

KoolReport commented on Aug 25, 2021

Can you capture me the screen

Javier Gallardo commented on Aug 25, 2021

APP.PHP

<?php
//App.php
use \koolreport\dashboard\menu\Section;
use \koolreport\dashboard\menu\Group;
use \koolreport\dashboard\pages\Login;
use \koolreport\dashboard\User;



class App extends \koolreport\dashboard\Application
{
    protected function login()
    {
        return  Login::create()
                ->failedText("Wrong! Please use <b>demo</b> for both username and password!")
                ->authenticate(function ($username, $password) {

                    //Look for user that have username and password 
                    $users = ConnectDB::table("users")
                                ->where("username",$username)
                                ->where("password",$password)
                                ->run();
                                
                    $user = $users->get(0);//Try to get first user, get associate array contain user information

                    if($user!==null) {
                        //Found a user, return User object
                        return User::create()
                        ->id($user["id"])
                        ->name($user["displayname"])
                        ->avatar("images/8.jpg")
                        ->roles([$user["role"]]);                        
                    }

                    //Other: fail to login, return null
                    return null;
                });
    }
}
KoolReport commented on Aug 25, 2021

I mean you screenshot your application on browser when it shows you "Something wrong"

KoolReport commented on Aug 25, 2021

By the way, you put this into your application:

class App extends \koolreport\dashboard\Application
{
    ...
    protected function onCreated()
    {
        $this->debugMode(true); //Turn on debug mode
    }
    ...
}

By turn on debugging mode, you will see the error details.

Javier Gallardo commented on Aug 25, 2021

KoolReport commented on Aug 26, 2021

Now the real error is showing not like "Something wrong", it is not working because your php could not connect to MySQL due to "could not find driver".

You need to have a driver module called pdo_mysql. Please install that module to your php. Below link might help:

MySQL PDO documentation

Alternatively, you can use XAMPP which has everything installed for you.

Hope that helps.

Javier Gallardo commented on Sep 7, 2021

it works, now how can I call a column inside GraphicTable.php?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None