• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Myth::Auth Login problem

#1
Since i am new here, first of all, "hello to everyone!".
Let me shortly introduce myself.
My main programming-language for the last two years was Java. And that was also what i was mainly focused on during my vocational training
before.
My PHP experiance until recently was just some procedural PHP here an there, creating my own little projects, like creating a login/registration system plus post and comment functionallity. My expieriance with OOP was only Java and C# and i never associated it with PHP, because when i first tried PHP back in the days, PHP wasnt't yet object orientated.
To cut a long story short:
I have got a new Job that requieres me to get into oo-PHP and into MVC-frameworks. During the last 6 weeks i first build my own little MVC-Framework and then tried Laravel, Slim and CodeIgniter.
I liked CodeIgniter the most and stayed with it.

Now i'm working on a small project, that requieres authentification and group-based authorization and i found out that Myth::Auth fits al my needs.
I installed Myth::Auth via Composer into a fresh CodeIgniter project.
All the routing and the views seem to work like intened.
I can register a new User, but when i Login, i am redirected to my welcome-page and when i revisit the login page, i have the possibility to login again. There seems to be no indication that a am already logged in and my $_SESSION is null. So how can i verify that i am logged in? Like making the login page only visible to visitors, who are not logged in
I sorry for asking an obvious question an for my english, i am not a native speaker.
Reply

#2
Ok, thanks to a little research with the help of this Forum i found out that i need to add 'auth' to the BaseControllers $helpers property and make the AuthController extend the BaseController. Adding 'auth' to the AuthControllers own $helpers property somehow didnt work. Now i can use something like this im my views:
<?php if (logged_in()) : ?>
<h1>Logged in</h1>
<?php endif; ?>
And im being automatically redirected to the welcome-page by the AuthControllers login method. But why did i need to add 'auth' to the BaseControllers $helpers property to make the redirection working?
Reply

#3
Welcome to PHP and CodeIgniter! Glad you found Myth:Auth - I think it’s a great module.

Helpers are a set of function definitions, not really anything more. In order to use any of those functions you need to load their definitions, and adding the list to the controller is a great way to do it. logged_in() is a function provided by Myth:Auth’s auth_helper
Reply

#4
(07-18-2020, 06:03 AM)MGatner Wrote: Welcome to PHP and CodeIgniter! Glad you found Myth:Auth - I think it’s a great module.

Helpers are a set of function definitions, not really anything more. In order to use any of those functions you need to load their definitions, and adding the list to the controller is a great way to do it. logged_in() is a function provided by Myth:Auth’s auth_helper
I'm a little embarrassed  of asking another Myth::Auth related question, since a am a newbie in this forum. But i ran into another problem.

I started a little project at work, where i am forced to use a Windows 10 client.

Now i wanted to continue on this project at home, where i use Manjaro Linux.

I just downloaded my project folder and correctly configured my .env file, according to my database (i am using a fresh intsall of XAMPP).



But when in try to run my migrations, using the following command:
Code:
php spark migrate -all



I'll get the following exceptions:

Code:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-20 06:16:02am

Running all new migrations...
An uncaught Exception was encountered

Type:        CodeIgniter\Database\Exceptions\DatabaseException
Message:     Unable to connect to the database.
Filename:    /opt/lampp/htdocs/stundenplanTest2/vendor/codeigniter4/framework/system/Database/BaseConnection.php
Line Number: 425

        Backtrace:
                                                -109 - /opt/lampp/htdocs/stundenplanTest2/vendor/codeigniter4/framework/system/Database/Database.php::initialize
                                                                -148 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/Database/Config.php::loadForge
                                                                -78 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/Database/Migration.php::forge
                                                                -1026 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/Database/MigrationRunner.php::__construct
                                                                -223 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/Database/MigrationRunner.php::migrate
                                                                -128 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/Commands/Database/Migrate.php::latest
                                                                -100 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CLI/Commands.php::run
                                                                -107 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CLI/CommandRunner.php::run
                                                                -85 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CLI/CommandRunner.php::index
                                                                -914 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CodeIgniter.php::_remap
                                                                -404 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CodeIgniter.php::runController
                                                                -312 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CodeIgniter.php::handleRequest
                                                                -86 - /opt/lampp/htdocs/Test2/vendor/codeigniter4/framework/system/CLI/Console.php::run
                                                                -57 - /opt/lampp/htdocs/Test2/spark::run




But the tables are there afterwards.



The second problem is related to the database-seeder.



When i try to run:



Code:
php spark db:seed GroupSeeder






It results in:







Code:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-20 06:17:05am


Unknown column 'name' in 'field list'
/opt/lampp/htdocs/stundenplanTest2/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php - 331



Here is the Seeder:
<?php


namespace App\Database\Seeds;


class GroupSeeder extends \CodeIgniter\Database\Seeder
{
    public function run()
    {
        $data = [
            'name' => 'admins',
            'description'    => 'godlike'
        ];

        // Simple Queries
        $this->db->query("INSERT INTO auth_groups (name, description) VALUES(:name:, :description:)",
            $data
        );

        // Using Query Builder
        $this->db->table('users')->insert($data);
Code:
But again, the entry is there afterwards, but the seeder is only working, making one entry, but the seeder originally was intended to create more groups an worked just fine at work.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.