[Cascavel-pm] Catalyst: Autentication

Giuliani Sanches giulianisanches em gmail.com
Quinta Junho 3 17:59:21 PDT 2010


Em 3 de junho de 2010 20:50, Giuliani Sanches
<giulianisanches em gmail.com> escreveu:
> Em 27 de maio de 2010 10:14, Ednardo Lobo <ednardo em lobo.eti.br> escreveu:
>> Giuliani,
>>
>> Seguem esquemas complementares:
>>
>> - Role
>>
>> ------------------------------------------------------------------------
>> __PACKAGE__->load_components("Core");
>> __PACKAGE__->table("role");
>> __PACKAGE__->add_columns(
>>  "id",
>>  { data_type => "INT", default_value => undef, is_nullable => 0, size => 11
>> },
>>  "role",
>>  {
>>    data_type => "TEXT",
>>    default_value => undef,
>>    is_nullable => 1,
>>    size => 65535,
>>  },
>> );
>> __PACKAGE__->set_primary_key("id");
>> ------------------------------------------------------------------------
>>
>> - UserRole
>>
>> ------------------------------------------------------------------------
>> __PACKAGE__->load_components("Core");
>> __PACKAGE__->table("user_role");
>> __PACKAGE__->add_columns(
>>  "user_id",
>>  { data_type => "INT", default_value => 0, is_nullable => 0, size => 11 },
>>  "role_id",
>>  { data_type => "INT", default_value => 0, is_nullable => 0, size => 11 },
>> );
>> __PACKAGE__->set_primary_key("user_id", "role_id");
>>
>> __PACKAGE__->belongs_to(user => 'sgle::Schema::User', 'user_id');
>> __PACKAGE__->belongs_to(role => 'sgle::Schema::Role', 'role_id');
>> ------------------------------------------------------------------------
>>
>> Precisando de qualquer outra informação, é só solicitar.
>>
>> Agradeço desde já sua ajuda!
>>
>> Giuliani Sanches escreveu:
>>>
>>> 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
>>
>>
>> --
>>    Ednardo Lobo
>>
>>    www.lobo.eti.br
>> _______________________________________________
>> Cascavel-pm mailing list
>> Cascavel-pm em pm.org
>> http://mail.pm.org/mailman/listinfo/cascavel-pm
>>
>
> Ednardo,
>
> Desculpe a demora em responder, mas os ultimos dias foram bem tensos
> em todos as áreas do meu dia a dia e somente nesse momento consegui
> dar uma olhada nisso.
>
> Como estou com preguiça e achei mais rápido e prático refazer os
> seguintes passos:
>
> http://search.cpan.org/~hkclark/Catalyst-Manual-5.8004/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod
> http://search.cpan.org/~hkclark/Catalyst-Manual-5.8004/lib/Catalyst/Manual/Tutorial/05_Authentication.pod
>
> ao invés de analisar seus "schemas", para ver se ao menos eu conseguia
> gerar a aplicação e fazer funcionar o esquema de autenticação.
>
> Eu consegui montar a app com a autenticação sem problemas. Utilizei o
> postgresql, baseado nas instruções oferecidas aqui:
>
> http://search.cpan.org/~hkclark/Catalyst-Manual-5.8004/lib/Catalyst/Manual/Tutorial/10_Appendices.pod
>
> Apesar de não estar te apontando a solução exata, espero que isso
> ajude (apesar de você ter dito que já havia lido o tutorial, mas
> enfim, as vezes alguma detalhes passa em branco  ;) ).
>
> []'s
>
> --
> Giuliani Sanches
> twitter.com/giulianisanches
> giulianisanches.blogspot.com
>
> Como elaborar uma pergunta:
> http://www.istf.com.br/perguntas/
>

Ops,

No lugar do 04, substitua por:

http://search.cpan.org/~hkclark/Catalyst-Manual-5.8004/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod

Eu fiz o 03 e 05 (pela metade, apenas para funcionar).

Resolvi te mandar o exemplo para matar a cobra e mostrar o sarrafo
(sarrafo foi usado para evitar piadinhas infames :P), você vai
precisar criar o banco, setar seu usuário e senha no DB.pm e importar
os sql que estão em script/sql.

Se não for permitido anexos na lista me avisem que não enviarei mais.

[]'s

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

Como elaborar uma pergunta:
http://www.istf.com.br/perguntas/
-------------- Próxima Parte ----------
Um anexo não-texto foi limpo...
Nome: MyApp.tar.bz2
Tipo: application/x-bzip2
Tamanho: 87985 bytes
Descrição: não disponível
URL: <http://mail.pm.org/pipermail/cascavel-pm/attachments/20100603/dd872877/attachment-0001.bz2>


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