Complete initial admin_users script, including deactivate, reactivate, really delete...
[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
570cf8ba 15has 'traditions' => (is => 'rw', isa => 'ArrayRef[Text::Tradition]', default => sub { [] }, required => 0);
2006bd3f 16
17# after add_tradition => sub {
18# $tradition->set_user($self)
cd726824 19# unless $tradition->user->id eq $self->id;
2006bd3f 20# }
21
221;
cd726824 23
24=head1 NAME
25
26Text::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
52User objects representing owners of L<Text::Tradition>s and authenticated users.
53
54=head2 ATTRIBUTES
55
56=head3 id
57
58Inherited from KiokuX::User, stores the 'username' (login) of the user.
59
60=head3 password
61
62User's password, encrypted on creation (by
63L<KiokuX::User::Util/crypt_password>.
64
65=head3 active
66
67Active flag, defaults to true (1). Will be set to false (0) by
68L<Text::Tradition::UserStore/deactivate_user>.
69
70=head3 traditions
71
72Returns an ArrayRef of L<Text::Tradition> objects belonging to this user.
73
74=head2 METHODS
75
76=head3 check_password
77
78Inherited from KiokuX::User, verifies a given password string against
79the stored encrypted version.