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