1 package Text::Tradition::User;
9 ## 'id' provided by KiokuX::User stores our username (email for local users, openid url for openid/google)
10 has 'password' => (is => 'rw', required => 1);
11 has 'email' => (is => 'rw', lazy => 1, builder => '_build_email');
12 ## Change this default active value if you want/need to have an admin confirm a user after they self-create.
13 has 'active' => (is => 'rw', default => sub { 1; });
14 has 'role' => (is => 'rw', default => sub { 'user' });
15 # 'traits' => ['Array'] ?
16 # https://metacpan.org/module/Moose::Meta::Attribute::Native::Trait::Array
17 has 'traditions' => (is => 'rw',
20 'add_tradition' => 'push',
22 isa => 'ArrayRef[Text::Tradition]',
23 default => sub { [] },
26 after add_tradition => sub {
27 my ($self, $tradition) = @_;
28 $tradition->user($self)
29 unless $tradition->has_user && $tradition->user->id eq $self->id;
35 ## no email set, so use username/id
39 sub remove_tradition {
40 my ($self, $tradition) = @_;
42 ## FIXME: Is "name" a good unique field to compare traditions on?
43 my @traditions = @{$self->traditions};
44 @traditions = grep { $tradition != $_ } @traditions;
46 $tradition->clear_user;
47 $self->traditions(\@traditions);
53 return $self->role && $self->role eq 'admin';
60 Text::Tradition::User - Users which own traditions, and can login to the web app
64 ## Users are managed by Text::Tradition::UserStore
66 my $userstore = Text::Tradition::UserStore->new(dsn => 'dbi:SQLite:foo.db');
67 my $newuser = $userstore->add_user({ username => 'fred',
68 password => 'somepassword' });
70 my $fetchuser = $userstore->find_user({ username => 'fred' });
71 if($fetchuser->check_password('somepassword')) {
72 ## login user or .. whatever
75 my $user = $userstore->deactivate_user({ username => 'fred' });
77 ## shouldnt be able to login etc
80 foreach my $t (@{ $user->traditions }) {
81 ## do something with traditions owned by this user.
86 User objects representing owners of L<Text::Tradition>s and authenticated users.
92 Inherited from KiokuX::User, stores the 'username' (login) of the user.
96 User's password, encrypted on creation (by
97 L<KiokuX::User::Util/crypt_password>.
101 Active flag, defaults to true (1). Will be set to false (0) by
102 L<Text::Tradition::UserStore/deactivate_user>.
106 Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
110 =head3 check_password
112 Inherited from KiokuX::User, verifies a given password string against
113 the stored encrypted version.