Guest User

Untitled

a guest
Feb 28th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 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. @@ -23,15 +23,16 @@
  18. my ( $self, $c, $id ) = @_;
  19.  
  20. return $id if ref $id;
  21. +
  22. + return $self->{auth}{catalyst_user_class}->new( $id, { %{$self} } );
  23.  
  24. - # XXX: hits the database on every request? Not good...
  25. - return $self->get_user( $id );
  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. @@ -49,6 +50,7 @@
  37. }
  38.  
  39. 1;
  40. +
  41. __END__
  42.  
  43. =pod
  44. === lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm
  45. ==================================================================
  46. --- lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm (revision 18123)
  47. +++ lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm (local)
  48. @@ -4,28 +4,42 @@
  49. use warnings;
  50. use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/;
  51. use Set::Object ();
  52. +use Carp qw/confess/;
  53. +use Data::Dumper;
  54.  
  55. use overload '""' => sub { shift->id }, 'bool' => sub { 1 }, fallback => 1;
  56.  
  57. -__PACKAGE__->mk_accessors(qw/id config obj store/);
  58. +__PACKAGE__->mk_accessors(qw/id config store _obj/);
  59.  
  60. +
  61. sub new {
  62. my ( $class, $id, $config ) = @_;
  63. -
  64. - my $query = @{$config->{auth}{user_field}} > 1
  65. - ? { -or => [ map { { $_ => $id } } @{$config->{auth}{user_field}} ] }
  66. - : { $config->{auth}{user_field}[0] => $id };
  67. -
  68. - my $user_obj = $config->{auth}{user_class}->search($query)->first;
  69. - return unless $user_obj;
  70. -
  71. bless {
  72. id => $id,
  73. - config => $config,
  74. - obj => $user_obj,
  75. + config => $config
  76. }, $class;
  77. }
  78.  
  79. +sub obj {
  80. + my $self=shift;
  81. + my $config=$self->config;
  82. + my $id=$self->id;
  83. + unless (ref $self->_obj) {
  84. + my $query = @{$config->{auth}{user_field}} > 1
  85. + ? { -or => [ map { { $_ => $id } } @{$config->{auth}{user_field}} ] }
  86. + : { $config->{auth}{user_field}[0] => $id };
  87. + $self->_obj($config->{auth}{user_class}->search($query)->first);
  88. + }
  89. + return $self->_obj;
  90. +}
  91. +
  92. +sub canonical_id {
  93. + my $self=shift;
  94. + return undef unless $self->obj();
  95. + return $self->obj->get_column($self->config->{auth}{user_field}[0]),
  96. +}
  97. +
  98. +
  99. *user = \&obj;
  100. *crypted_password = \&password;
  101. *hashed_password = \&password;
Add Comment
Please, Sign In to add comment