[Cascavel-pm] Catalyst: Autentication

Giuliani Sanches giulianisanches em gmail.com
Quinta Maio 27 04:53:54 PDT 2010


Em 27 de maio de 2010 07:55, Ednardo Lobo <ednardo em lobo.eti.br> escreveu:
> Giuliani,
>
> Ajustei meu "realm" para:
>
> <Plugin::Authentication>
>    default_realm default
>    <realms>
>        <default>
>            <credential>
>                class Password
>                password_field password
>                password_type clear
>            </credential>
>            <store>
>                class DBIx::Class
>                user_model sgle::Schema::User
>                role_relation roles
>                role_field role
>            </store>
>        </default>
>    </realms>
> </Plugin::Authentication>
>
> Não consegui, entretanto, compreender o que é exatamente o "user_model",
>  cuja definição extraída do manual reproduzo a seguir:
>
> ------------------------------------------------------------------------
> user_model
>
> Contains the model name (as passed to $c->model()) of the DBIx::Class schema
> to use as the source for user information. This config item is REQUIRED.
>
> (Note that this option used to be called user_class. user_class is still
> functional, but should be used only for compatibility with previous configs.
> The setting called user_class on other authentication stores is present, but
> named store_user_class in this store)
> ------------------------------------------------------------------------
>
> Informei, porém, a classe que refere-se ao esquema da minha tabela de
> usuários onde fica registrado o "username" e "password", veja:
>
> ------------------------------------------------------------------------
> __PACKAGE__->load_components("Core");
> __PACKAGE__->table("user");
> __PACKAGE__->add_columns(
>  "id",
>  { data_type => "INT", default_value => undef, is_nullable => 0, size => 11
> },
>  "username",
>  {
>    data_type => "TEXT",
>    default_value => undef,
>    is_nullable => 1,
>    size => 65535,
>  },
>  "password",
>  {
>    data_type => "TEXT",
>    default_value => undef,
>    is_nullable => 1,
>    size => 65535,
>  },
>  "email_address",
>  {
>    data_type => "TEXT",
>    default_value => undef,
>    is_nullable => 1,
>    size => 65535,
>  },
>  "first_name",
>  {
>    data_type => "TEXT",
>    default_value => undef,
>    is_nullable => 1,
>    size => 65535,
>  },
>  "last_name",
>  {
>    data_type => "TEXT",
>    default_value => undef,
>    is_nullable => 1,
>    size => 65535,
>  },
>  "active",
>  { data_type => "INT", default_value => undef, is_nullable => 1, size => 11
> },
> );
>
> __PACKAGE__->set_primary_key("id");
>
> __PACKAGE__->has_many(user_roles => 'sgle::Schema::UserRole', 'user_id');
> __PACKAGE__->many_to_many(roles => 'user_roles', 'role');
> ------------------------------------------------------------------------
>
> Entretanto, quando a ação "Controller::Login" é tomada apenas a tabela
> 'role' é acessada, veja:
>
> ------------------------------------------------------------------------
> SELECT me.id, me.role FROM role me
> ------------------------------------------------------------------------
>
> E não consegui descobrir a razão disto. Esperava que tabela 'user' também
> fosse acessada.
>
> Onde estou errando?
>
>
> Grato,
>
>
> Giuliani Sanches escreveu:
>>
>> Em 26 de maio de 2010 14:33, Ednardo Lobo <ednardo em lobo.eti.br> escreveu:
>>>
>>> Giuliani,
>>>
>>> O "default realm" está configurado, veja:
>>>
>>> - sgle.conf
>>>
>>> <Plugin::Authentication>
>>>   <default>
>>>       password_type   clear
>>>       user_model   DB::User
>>>       class   SimpleDB
>>>   </default>
>>> </Plugin::Authentication>
>>>
>>>
>>> Li o artigo e a documentação que indicou, mas não ajudaram.
>>>
>>> Alguma outra sugestão?
>>>
>>>
>>> Grato,
>>>
>>> Giuliani Sanches escreveu:
>>>>
>>>> 2010/5/26 Ednardo Lobo <ednardo em lobo.eti.br>:
>>>>>
>>>>> Pessoal,
>>>>>
>>>>> Estou testando o módulo Catalyst::Plugin::Autentication e não estou
>>>>> conseguindo identificar a origem do erro:
>>>>>
>>>>> --------------
>>>>> Caught exception in sgle::Controller::Login->index "authenticate called
>>>>> with
>>>>> nonexistant realm: 'default'. at
>>>>>
>>>>>
>>>>> /home/ftp/www/lobosnet.cjb.net/sgle/script/../lib/sgle/Controller/Login.pm
>>>>> line 30"
>>>>> --------------
>>>>>
>>>>> Isso ocorre quando a seguinte ação é tomada:
>>>>>
>>>>> - Login.pm
>>>>>
>>>>> sub index :Path :Args(0) {
>>>>>  my ( $self, $c ) = @_;
>>>>>
>>>>>  my $u = $c->req->params->{username};
>>>>>  my $p = $c->req->params->{password};
>>>>>
>>>>>  if ($u && $p) {
>>>>>      if ($c->authenticate({username => $u, password => $p})) {
>>>>>          $c->res->redirect('Welcome');
>>>>>      }
>>>>>      else {
>>>>>          $c->stash(error_msg => "Bad username or password.");
>>>>>      }
>>>>>  }
>>>>>  else {
>>>>>      $c->stash(error_msg => "Empty username or password.");
>>>>>  }
>>>>> }
>>>>>
>>>>>
>>>>> Qualquer palpite é bem-vindo!
>>>>>
>>>>>
>>>>> Grato,
>>>>
>>>> Hum.. a mensagem deixa bem claro que faltou configurar o realm default.
>>>>
>>>> Da uma olhada no primeiro exemplo da documentação do plugin:
>>>>
>>>>
>>>>
>>>> http://search.cpan.org/~flora/Catalyst-Plugin-Authentication-0.10016/lib/Catalyst/Plugin/Authentication.pm#EXAMPLE
>>>>
>>>> Tem também esse ótimo artigo do Wallace Reis no sao-paullo.pm.org:
>>>>
>>>> http://sao-paulo.pm.org/artigo/2010/AutenticacaoCatalyst
>>>>
>>>> []'s
>>
>>
>> Senti falta do Credential e Store na sua configuração.
>>
>>
>> http://search.cpan.org/~flora/Catalyst-Plugin-Authentication-0.10016/lib/Catalyst/Plugin/Authentication.pm#Credential_Verifiers
>>
>> []'s
>>
>
>
> --
>    Ednardo Lobo
>
>    www.lobo.eti.br
> _______________________________________________
> Cascavel-pm mailing list
> Cascavel-pm em pm.org
> http://mail.pm.org/mailman/listinfo/cascavel-pm
>


Manda o código do teu Schema::UserRole.

Até o inicio da tarde eu consigo dar uma olhada com calma e tento te ajudar.

[]'s

-- 
Giuliani Sanches
twitter.com/giulianisanches
giulianisanches.blogspot.com

Como elaborar uma pergunta:
http://www.istf.com.br/perguntas/


Mais detalhes sobre a lista de discussão Cascavel-pm