Docs for Text::Tradition::User
[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);
cd726824 11has 'active' => (is => 'rw', default => sub { 1; });
12# 'traits' => ['Array'] ?
13# https://metacpan.org/module/Moose::Meta::Attribute::Native::Trait::Array
2006bd3f 14has 'traditions' => (is => 'rw', isa => 'ArrayRef[Text::Tradition]', required => 0);
15
16# after add_tradition => sub {
17# $tradition->set_user($self)
cd726824 18# unless $tradition->user->id eq $self->id;
2006bd3f 19# }
20
211;
cd726824 22
23=head1 NAME
24
25Text::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
51User objects representing owners of L<Text::Tradition>s and authenticated users.
52
53=head2 ATTRIBUTES
54
55=head3 id
56
57Inherited from KiokuX::User, stores the 'username' (login) of the user.
58
59=head3 password
60
61User's password, encrypted on creation (by
62L<KiokuX::User::Util/crypt_password>.
63
64=head3 active
65
66Active flag, defaults to true (1). Will be set to false (0) by
67L<Text::Tradition::UserStore/deactivate_user>.
68
69=head3 traditions
70
71Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
72
73=head2 METHODS
74
75=head3 check_password
76
77Inherited from KiokuX::User, verifies a given password string against
78the stored encrypted version.