line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Authentication::Store::MongoDB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20501
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
415
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Catalyst::Authentication::Store::MongoDB - L backend for |
10
|
|
|
|
|
|
|
Catalyst::Plugin::Authentication |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.02 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module links a subclass of MongoDB to your Catalyst application as a user |
23
|
|
|
|
|
|
|
store for the Authentication plugin. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
class Password |
29
|
|
|
|
|
|
|
password_type self_check |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
class MongoDB |
33
|
|
|
|
|
|
|
user_collection user |
34
|
|
|
|
|
|
|
user_class Catalyst::Authentication::User::Hash |
35
|
|
|
|
|
|
|
model MongoDB |
36
|
|
|
|
|
|
|
database db |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Then use it as normal |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub login : Local { |
44
|
|
|
|
|
|
|
my ($self, $c) = @_; |
45
|
|
|
|
|
|
|
$c->authenticate({ |
46
|
|
|
|
|
|
|
username => $username, |
47
|
|
|
|
|
|
|
password => $password |
48
|
|
|
|
|
|
|
}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 CONFIGURATION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 class |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The configuration required by L to load this |
56
|
|
|
|
|
|
|
store in the first place. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 user_collection |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The collection in your database that holds users. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 user_class |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Some subclass of Catalyst::Authentication::User to bless the returned objects |
65
|
|
|
|
|
|
|
as. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 model |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The model name that you'd give to $c->model. It is expected that your model |
70
|
|
|
|
|
|
|
is a L subclass. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 database |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The database that your user_collection is a collection in. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub new { |
79
|
0
|
|
|
0
|
0
|
|
my ($class, $config, $app) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
0
|
|
|
|
$config->{user_class} //= 'Catalyst::Authentication::User::Hash'; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $self = { |
84
|
|
|
|
|
|
|
config => $config |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
bless $self, $class; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub from_session { |
91
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $frozen) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $user = $c->model($self->{config}->{model}) |
94
|
|
|
|
|
|
|
->connection |
95
|
|
|
|
|
|
|
->get_database($self->{config}->{database}) |
96
|
|
|
|
|
|
|
->get_collection($self->{config}->{user_collection}) |
97
|
|
|
|
|
|
|
->find_one({ |
98
|
|
|
|
|
|
|
_id => MongoDB::OID->new(value => $frozen) |
99
|
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
bless $user, $self->{config}->{user_class} if $user; |
102
|
0
|
|
|
|
|
|
return $user; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub for_session { |
106
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $user) = @_; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $user->{_id}->{value}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub find_user { |
112
|
0
|
|
|
0
|
0
|
|
my ($self, $authinfo, $c) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# note to self before I forget: password is deleted from $authinfo by the |
115
|
|
|
|
|
|
|
# realm when finding the user. kthx |
116
|
0
|
|
|
|
|
|
my $user = $c->model($self->{config}->{model}) |
117
|
|
|
|
|
|
|
->connection |
118
|
|
|
|
|
|
|
->get_database($self->{config}->{database}) |
119
|
|
|
|
|
|
|
->get_collection($self->{config}->{user_collection}) |
120
|
|
|
|
|
|
|
->find_one($authinfo); |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
return undef unless $user; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
bless $user, $self->{config}->{user_class}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub user_supports { |
128
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
129
|
0
|
|
|
|
|
|
$self->{config}->{user_class}->supports( @_ ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Altreus, C<< >> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 BUGS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
I'll be amazed if this works for you at all. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Bugs and requests to github please - |
141
|
|
|
|
|
|
|
https://github.com/Altreus/Catalyst-Authentication-Store-MongoDB/issues |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SUPPORT |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
You are reading all the support you're likely to get. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Thanks to BOBTFISH for wracking his brains to try to remember how this stuff |
150
|
|
|
|
|
|
|
works. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Copyright 2012 Altreus. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
MIT licence. Go nuts. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; # End of Catalyst::Authentication::Store::MongoDB |