Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Kohana]Simple Auth
Forum PHP.pl > Forum > PHP > Frameworki
PawelC
Witam,
Mógłbym mi ktoś łopatologicznie wyjaśnić, jak używać simple auth w KO 3.0.3 bo nie mogę się połapać ;/ W internecie też nie ma za bardzo opisane co i jak, jedynie kod odpowiedzialny za logowanie, dodanie usera itp

A mi chodzi o to, jak zaimplementować simple auth w Kohanie 3, w KO2 nie miałem żadnych problemów, ale tutaj masakra. Kombinowałem na różne sposoby, ale nie ogarniam tego ;/ Z góry dziękuję za pomoc
skowron-line
A czego dokładnie nie możesz ogarnąć bo z tego co kojarze to wiele się nie zmienił od wersji na ko2 ten moduł.
https://github.com/thejw23/simple_auth/blob...leauth/core.php zobacz jakie są metody i do czego służą.
PawelC
Wgrywam moduł simple_auth do katalogu modules, dodaje go do boostrap.php

W kontrolerze daję kod:
  1. $user_data['email']='my@email.com';
  2. $user_data['username']='myuser';
  3. $user_data['password']='verysecret';
  4. $user_data['admin']=true;
  5. $result = Simple_Auth::instance()->create_user($user_data);
  6. //if user created, $result will be true
  7. //by default role active is true and admin false so there is no need to pass them
  8. //to forbid user login after some date simple before user_create() add:
  9. $user_data['active_to']='2009-06-01 22:23:24';
  10. //to get ie. 3 months from now:
  11. $user_data['active_to']=date('Y-m-d H:i:s',mktime(date('H'), date('i'), date('s'), date('m')+3, date('d'), date('Y')));
I wywala mi Class "Simple_Auth" no found

Błąd wskazuje na tą linie:
  1. $result = Simple_Auth::instance()->create_user($user_data);
skowron-line
Cytat(ExPlOiT @ 24.01.2013, 12:22:48 ) *
Błąd wskazuje na tą linie:
  1. $result = Simple_Auth::instance()->create_user($user_data);

A jesteś pewnien że tak się nazywa klasa questionmark.gif
https://github.com/thejw23/simple_auth/blob.../simpleauth.php
PawelC
fakt, dałem simpleauth to jak na złość mam:
Cytat
ErrorException [ Fatal Error ]: Class 'simpleauth_Core' not found

Swoją drogą po ściągnięciu paczki, wgrywam ją do katalogu modules, dopisuje do bootstrap.php i kopiuje plik config do application/config?
skowron-line
Ja pobrałem paczke z githuba i wszystko mi działa
bootstrap
Kod
'simpleauth' => MODPATH .'simple_auth'

controller
Kod
Simpleauth::instance()


p.s chmody masz dobrze ustawione ?
PawelC
Tak, mam ustawione na odczyt i zapis ;/

Cały czas pokazuje błąd tutaj
  1. class simpleauth extends simpleauth_Core {
  2.  
  3. }

Cytat
ErrorException [ Fatal Error ]: Class 'simpleauth_Core' not found


Pobrałem paczkę, wgrałem do frameworka, ustawiłem chmod na zapis/odczyt, dopisałem do bootstrap, wkleiłem kod który Ci pokazałem wcześniej, i błąd.
skowron-line
Zobacz tak.
  1. var_dump(file_exists(MODPATH .'/simple_auth/classes/simpleauth/core.php'));

Możesz też ręcznie załadować plik z klasą, i jak wtedy pójdzie to znaczy że coś z autoloaderem jest nie tak.
PawelC
Poszło dalej jak załadowałem ręcznie i od razu wywaliło mi:
Cytat
Kohana_Exception [ 0 ]: A valid cookie salt is required. Please set Cookie::$salt.
skowron-line
Cytat(ExPlOiT @ 24.01.2013, 13:58:14 ) *
Poszło dalej jak załadowałem ręcznie i od razu wywaliło mi:

google Ci zablokowali questionmark.gif czy jak questionmark.gif
  1. Cookie::$salt = '';
musisz sobie ustawić
PawelC
Poszło, muszę sprawdzić co i jak, bo narazie każdy plik z simpleauth muszę ręcznie ładować, żeby coś szło.
skowron-line
A w autoloaderze nic nie kombinowałeś questionmark.gif
PawelC
NIe, nie kombinowałem z niczym. Tak jak pobrałem KO tak zostawiłem, poza podstawowymi zmianiami, czyli żeby mi strona śmigała na / a nie /kohana/
Jego zawartość:
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. // -- Environment setup --------------------------------------------------------
  4.  
  5. // Load the core Kohana class
  6. require SYSPATH.'classes/Kohana/Core'.EXT;
  7.  
  8. if (is_file(APPPATH.'classes/Kohana'.EXT))
  9. {
  10. // Application extends the core
  11. require APPPATH.'classes/Kohana'.EXT;
  12. }
  13. else
  14. {
  15. // Load empty core extension
  16. require SYSPATH.'classes/Kohana'.EXT;
  17. }
  18.  
  19. /**
  20.  * Set the default time zone.
  21.  *
  22.  * @link <a href="http://kohanaframework.org/guide/using.configuration" target="_blank">http://kohanaframework.org/guide/using.configuration</a>
  23.  * @link <a href="http://www.php.net/manual/timezones" target="_blank">http://www.php.net/manual/timezones</a>
  24.  */
  25. date_default_timezone_set('America/Chicago');
  26.  
  27. /**
  28.  * Set the default locale.
  29.  *
  30.  * @link <a href="http://kohanaframework.org/guide/using.configuration" target="_blank">http://kohanaframework.org/guide/using.configuration</a>
  31.  * @link <a href="http://www.php.net/manual/function.setlocale" target="_blank">http://www.php.net/manual/function.setlocale</a>
  32.  */
  33. setlocale(LC_ALL, 'en_US.utf-8');
  34.  
  35. /**
  36.  * Enable the Kohana auto-loader.
  37.  *
  38.  * @link <a href="http://kohanaframework.org/guide/using.autoloading" target="_blank">http://kohanaframework.org/guide/using.autoloading</a>
  39.  * @link <a href="http://www.php.net/manual/function.spl-autoload-register" target="_blank">http://www.php.net/manual/function.spl-autoload-register</a>
  40.  */
  41. spl_autoload_register(array('Kohana', 'auto_load'));
  42.  
  43. /**
  44.  * Optionally, you can enable a compatibility auto-loader for use with
  45.  * older modules that have not been updated for PSR-0.
  46.  *
  47.  * It is recommended to not enable this unless absolutely necessary.
  48.  */
  49. //spl_autoload_register(array('Kohana', 'auto_load_lowercase'));
  50.  
  51. /**
  52.  * Enable the Kohana auto-loader for unserialization.
  53.  *
  54.  * @link <a href="http://www.php.net/manual/function.spl-autoload-call" target="_blank">http://www.php.net/manual/function.spl-autoload-call</a>
  55.  * @link <a href="http://www.php.net/manual/var.configuration#unserialize-callback-func" target="_blank">http://www.php.net/manual/var.configuratio...e-callback-func</a>
  56.  */
  57. ini_set('unserialize_callback_func', 'spl_autoload_call');
  58.  
  59. // -- Configuration and initialization -----------------------------------------
  60.  
  61. /**
  62.  * Set the default language
  63.  */
  64. I18n::lang('en-us');
  65.  
  66. /**
  67.  * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
  68.  *
  69.  * Note: If you supply an invalid environment name, a PHP warning will be thrown
  70.  * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
  71.  */
  72. if (isset($_SERVER['KOHANA_ENV']))
  73. {
  74. Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
  75. }
  76.  
  77. /**
  78.  * Initialize Kohana, setting the default options.
  79.  *
  80.  * The following options are available:
  81.  *
  82.  * - string base_url path, and optionally domain, of your application NULL
  83.  * - string index_file name of your index file, usually "index.php" index.php
  84.  * - string charset internal character set used for input and output utf-8
  85.  * - string cache_dir set the internal cache directory APPPATH/cache
  86.  * - integer cache_life lifetime, in seconds, of items cached 60
  87.  * - boolean errors enable or disable error handling TRUE
  88.  * - boolean profile enable or disable internal profiling TRUE
  89.  * - boolean caching enable or disable internal caching FALSE
  90.  * - boolean expose set the X-Powered-By header FALSE
  91.  */
  92. Kohana::init(array(
  93. 'base_url' => '/',
  94. ));
  95.  
  96. /**
  97.  * Attach the file write to logging. Multiple writers are supported.
  98.  */
  99. Kohana::$log->attach(new Log_File(APPPATH.'logs'));
  100.  
  101. /**
  102.  * Attach a file reader to config. Multiple readers are supported.
  103.  */
  104. Kohana::$config->attach(new Config_File);
  105.  
  106. /**
  107.  * Enable modules. Modules are referenced by a relative or absolute path.
  108.  */
  109. Kohana::modules(array(
  110. //'auth' => MODPATH.'auth', // Basic authentication
  111. // 'cache' => MODPATH.'cache', // Caching with multiple backends
  112. // 'codebench' => MODPATH.'codebench', // Benchmarking tool
  113. 'database' => MODPATH.'database', // Database access
  114. // 'image' => MODPATH.'image', // Image manipulation
  115. // 'minion' => MODPATH.'minion', // CLI Tasks
  116. 'orm' => MODPATH.'orm', // Object Relationship Mapping
  117. // 'unittest' => MODPATH.'unittest', // Unit testing
  118. // 'userguide' => MODPATH.'userguide', // User guide and API documentation
  119. 'simpleauth' => MODPATH .'simple_auth'
  120. ));
  121.  
  122. /**
  123.  * Set the routes. Each route must have a minimum of a name, a URI and a set of
  124.  * defaults for the URI.
  125.  */
  126.  
  127. Route :: set( 'default', '(<controller>(/<action>(/<id>)))')
  128. -> defaults( array( 'controller' => 'welcome',
  129. 'action' => 'index' ) );
  130.  
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.