Docs for Text::Tradition::User
[scpubgit/stemmatology.git] / lib / Text / Tradition / User.pm
1 package Text::Tradition::User;
2
3 use strict;
4 use warnings;
5
6 use Moose;
7 with qw(KiokuX::User);
8
9 ## 'id' provided by KiokuX::User stores our username
10 has 'password'   => (is => 'rw', required => 1);
11 has 'active'     => (is => 'rw', default => sub { 1; });
12 # 'traits' => ['Array'] ?
13 # https://metacpan.org/module/Moose::Meta::Attribute::Native::Trait::Array
14 has 'traditions' => (is => 'rw', isa => 'ArrayRef[Text::Tradition]', required => 0);
15
16 # after add_tradition => sub { 
17 #     $tradition->set_user($self) 
18 #         unless $tradition->user->id eq $self->id;
19 # }
20
21 1;
22
23 =head1 NAME
24
25 Text::Tradition::User - Users which own traditions, and can login to the web app
26
27 =head1 SYNOPSIS
28
29     ## Users are managed by Text::Tradition::UserStore
30
31     my $userstore = Text::Tradition::UserStore->new(dsn => 'dbi:SQLite:foo.db');
32     my $newuser = $userstore->add_user({ username => 'fred',
33                                          password => 'somepassword' });
34
35     my $fetchuser = $userstore->find_user({ username => 'fred' });
36     if($fetchuser->check_password('somepassword')) { 
37        ## login user or .. whatever
38     }
39
40     my $user = $userstore->deactivate_user({ username => 'fred' });
41     if(!$user->active) { 
42       ## shouldnt be able to login etc
43     }
44
45     foreach my $t (@{ $user->traditions }) {
46       ## do something with traditions owned by this user.
47     }
48
49 =head1 DESCRIPTION
50
51 User objects representing owners of L<Text::Tradition>s and authenticated users.
52
53 =head2 ATTRIBUTES
54
55 =head3 id
56
57 Inherited from KiokuX::User, stores the 'username' (login) of the user.
58
59 =head3 password
60
61 User's password, encrypted on creation (by
62 L<KiokuX::User::Util/crypt_password>.
63
64 =head3 active
65
66 Active flag, defaults to true (1). Will be set to false (0) by
67 L<Text::Tradition::UserStore/deactivate_user>.
68
69 =head3 traditions
70
71 Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
72
73 =head2 METHODS
74
75 =head3 check_password
76
77 Inherited from KiokuX::User, verifies a given password string against
78 the stored encrypted version.