Welcome Guest, Not a member yet? Register   Sign In
MYTH-AUTH userModel Factory
#1

I am trying to understand how CI4 works, and above all MYTH-AUTH.
My intention is to integrate the creation of the tables if they are non-existent.
From what I understand it seems that a new copy of UserModel in the "App \ Models" folder can extend the "UserModel" of MYTH-AUTH based on the Factory rules, but is it ready to use or does it need a configuration?
Reply
#2

It’s all set! Since Myth:Auth loads all its models using Factories (in this case via the shorthand `model('UserModel')` ) Factories will take care of identifying extended version located in your App namespace and use those instead.
Reply
#3

(This post was last modified: 05-12-2021, 02:36 PM by mauroMbs.)

(05-11-2021, 03:14 PM)MGatner Wrote: It’s all set! Since Myth:Auth loads all its models using Factories (in this case via the shorthand `model('UserModel')` ) Factories will take care of identifying extended version located in your App namespace and use those instead.

I thought I had understood this from the documentation, but it doesn't actually work.
Surely I made some mistakes.
my model :
PHP Code:
<?php 

namespace App\Models;

use 
Myth\Auth\Models\UserModel as MythModel;

class 
UserModel extends MythModel
{
     public function __construct()
    {
      $db = \Config\Database::connect();        
       if(!$db->tableExists('users'))
    
   {
        
   $this->migrate_users();
    
   };

       if(!$db->tableExists('auth_logins'))
    
   {
        
   $this->migrate_auth_logins();
    
   };


       if(!$db->tableExists('auth_tokens'))
    
   {
        
   $this->migrate_auth_tokens();
    
   };
 
       if(!$db->tableExists('auth_reset_attempts'))
    
   {
        
   $this->migrate_auth_reset_attempts();
    
   };  
       
       
if(!$db->tableExists('auth_activation_attempts'))
    
   {
        
   $this->migrate_auth_activation_attempts();
    
   };  

       
if(!$db->tableExists('auth_groups'))
    
   {
        
   $this->migrate_auth_groups();
    
   };

       if(!$db->tableExists('auth_permissions'))
    
   {
        
   $this->migrate_auth_permissions();
    
   };        

       
if(!$db->tableExists('auth_groups_permissions'))
    
   {
        
   $this->migrate_auth_groups_permissions();
    
   };     

       if(!$db->tableExists('auth_groups_users'))
    
   {
        
   $this->migrate_auth_groups_users();
    
   };     

       if(!$db->tableExists('auth_users_permissions'))
    
   {
        
   $this->migrate_auth_users_permissions();
    
   }; 

    
   
    




I use a controller called by ajax:
PHP Code:
<?php
namespace App\Controllers;
    
 use 
Myth\Auth\Controllers\AuthController as MyAuth;
    
class 
Auth extends MyAuth
{
    public function __construct()
    {
        helper(['auth','url','form','generic_helper']);
        
$this->session service('session');
        
$this->config  config('Auth');        
        
$this->auth    service('authentication');  
    
}    
        
    
    public function 
register()
    {

        
$rules = [
            
'username'      => 'required|alpha_numeric_space|min_length[3]|is_unique[users.username]',
            
'email'        => 'required|valid_email|is_unique[users.email]',
            
'password'    => 'required|strong_password',
            
'pass_confirm'     => 'required|matches[password]',
        ];

        
        if (!
$this->validate($rules))
        {
            echo 
print_r($this->validator->getErrors(), true);
        }else{
            
$value = ['username'            => $user,
                    
'email'        => $mail,
                    
'password_hash'    => $pswd
                    
];
                 
            
$this->attemptRegister();
        }        
    }
    


the _construct() of UserModel it's not execute.



this
Reply
#4

(05-11-2021, 01:23 PM)mauroMbs Wrote: I am trying to understand how CI4 works, and above all MYTH-AUTH.
My intention is to integrate the creation of the tables if they are non-existent.
From what I understand it seems that a new copy of UserModel in the "App \ Models" folder can extend the "UserModel" of MYTH-AUTH based on the Factory rules, but is it ready to use or does it need a configuration?

I have the same question as you
Reply




Theme © iAndrew 2016 - Forum software by © MyBB