use Moose;
use KiokuX::User::Util qw(crypt_password);
+use Text::Tradition::Error;
extends 'Text::Tradition::Directory';
# extends 'KiokuX::Model';
## XX_user, but leaving that way for now incase we merge this code
## into ::Directory for one-store.
-## To die or not to die, on error, this is the question.
-
=head2 METHODS
=head3 add_user
my $username = $userinfo->{url} || $userinfo->{username};
my $password = $userinfo->{password};
- return unless ($username =~ /^https?:/
- || ($username && $self->validate_password($password))) ;
-
+ throw( "No username given" ) unless $username;
+ throw( "Invalid password - too short?" )
+ unless ( $self->validate_password($password) || $username =~ /^https?:/ );
+
my $user = Text::Tradition::User->new(
id => $username,
password => ($password ? crypt_password($password) : ''),
Takes a hashref of C<username> and C<password> (same as add_user).
Retrieves the user, and updates it with the new information. Username
-changing is not currently supported.
-
-Returns the updated user object, or undef if not found.
+changing is not currently supported. Returns the updated user object.
+Throws an error if user not found.
=cut
my $username = $userinfo->{username};
my $password = $userinfo->{password};
- return unless $username && $self->validate_password($password);
+ throw( "Missing username or bad password" )
+ unless $username && $self->validate_password($password);
my $user = $self->find_user({ username => $username });
- return unless $user;
+ throw( "Could not find user $username" ) unless $user;
my $scope = $self->new_scope;
$user->password(crypt_password($password));
assigned to them to non-public, updates the storage and returns the
deactivated user.
-Returns undef if user not found.
+Throws an error if user not found.
=cut
my ($self, $userinfo) = @_;
my $username = $userinfo->{username};
- return if !$username;
+ throw( "Need to specify a username for deactivation" ) unless $username;
my $user = $self->find_user({ username => $username });
- return if !$user;
+ throw( "User $username not found" ) unless $user;
$user->active(0);
foreach my $tradition (@{ $user->traditions }) {
Returns the user object if already activated. Activates (sets the
active flag to true (1)), updates the storage and returns the user.
-Returns undef if the user is not found.
+Throws an error if the user is not found.
=cut
my ($self, $userinfo) = @_;
my $username = $userinfo->{username};
- return if !$username;
+ throw( "Need to specify a username for reactivation" ) unless $username;
my $user = $self->find_user({ username => $username });
- return if !$user;
+ throw( "User $username not found" ) unless $user;
return $user if $user->active;
Takes a hashref of C<username>.
-Returns undef if the user doesn't exist.
+Throws an error if the user doesn't exist.
Removes the user from the store and returns 1.
my ($self, $userinfo) = @_;
my $username = $userinfo->{username};
- return if !$username;
+ throw( "Need to specify a username for deletion" ) unless $username;
my $user = $self->find_user({ username => $username });
- return if !$user;
+ throw( "User $username not found" ) unless $user;
my $scope = $self->new_scope;
return 1;
}
+sub throw {
+ Text::Tradition::Error->throw(
+ 'ident' => 'UserStore error',
+ 'message' => $_[0],
+ );
+}
+
1;