Guest User

Untitled

a guest
Feb 28th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. === Changes
  2. ==================================================================
  3. --- Changes (revision 18123)
  4. +++ Changes (local)
  5. @@ -1,5 +1,7 @@
  6. Revision history for Perl extension Catalyst::Plugin::Authentication::Store::DBIC
  7.  
  8. + - Made $c->user->id return the first field of user_field, rather than whatever was passed in.
  9. +
  10. 0.07 2006-06-30 01:08:47
  11. - make the User class stringify to the user id
  12. - documentation fixes
  13. === lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm
  14. ==================================================================
  15. --- lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm (revision 18123)
  16. +++ lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm (local)
  17. @@ -24,19 +24,20 @@
  18.  
  19. return $id if ref $id;
  20.  
  21. - # XXX: hits the database on every request? Not good...
  22. - return $self->get_user( $id );
  23. +
  24. + return $self->{auth}{catalyst_user_class}->new( $id, { %{$self} } );
  25. +
  26. }
  27.  
  28. sub get_user {
  29. my ( $self, $id, @rest ) = @_;
  30.  
  31. my $user = $self->{auth}{catalyst_user_class}->new( $id, { %{$self} } );
  32. + $user->id($user->canonical_id);
  33.  
  34. if ( $user ) {
  35. $user->store( $self );
  36. $user->obj->auto_update( $id, @rest ) if $self->{auth}{auto_update_user};
  37. - return $user;
  38. } elsif ( $self->{auth}{auto_create_user} ) {
  39. $self->{auth}{user_class}->auto_create( $id, @rest ) and return $self->get_user( $id );
  40. }
  41. === lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm
  42. ==================================================================
  43. --- lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm (revision 18123)
  44. +++ lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm (local)
  45. @@ -7,25 +7,34 @@
  46.  
  47. use overload '""' => sub { shift->id }, 'bool' => sub { 1 }, fallback => 1;
  48.  
  49. -__PACKAGE__->mk_accessors(qw/id config obj store/);
  50. +__PACKAGE__->mk_accessors(qw/id config store/);
  51.  
  52. +
  53. sub new {
  54. my ( $class, $id, $config ) = @_;
  55. + bless {
  56. + id => $id,
  57. + config => $config
  58. + }, $class;
  59. +}
  60.  
  61. +sub obj {
  62. + my $self=shift;
  63. + my $config=$self->config;
  64. + my $id=$self->id;
  65. my $query = @{$config->{auth}{user_field}} > 1
  66. ? { -or => [ map { { $_ => $id } } @{$config->{auth}{user_field}} ] }
  67. : { $config->{auth}{user_field}[0] => $id };
  68.  
  69. - my $user_obj = $config->{auth}{user_class}->search($query)->first;
  70. - return unless $user_obj;
  71. + return $config->{auth}{user_class}->search($query)->first;
  72. +}
  73.  
  74. - bless {
  75. - id => $id,
  76. - config => $config,
  77. - obj => $user_obj,
  78. - }, $class;
  79. +sub canonical_id {
  80. + my $self=shift;
  81. + return $self->obj->get_column($self->config->{auth}{user_field}[0]),
  82. }
  83.  
  84. +
  85. *user = \&obj;
  86. *crypted_password = \&password;
  87. *hashed_password = \&password;
Add Comment
Please, Sign In to add comment