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