Skip to content

Adding support for password reset. Fix for database has gone away error #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions lib/Dancer2/Plugin/Auth/Extensible/Provider/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ has users_password_column => (
default => 'password',
);

=head2 pw_rest_code_column
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: s/rest/reset/


Defaults to pw_reset_code

=cut

has users_pw_reset_code_column => (
is => 'ro',
default => 'pw_reset_code',
);

=head2 roles_table

Defaults to 'roles'.
Expand Down Expand Up @@ -375,7 +386,9 @@ sub get_user_details {
unless defined $username;

# Get our database handle and find out the table and column names:
my $database = $self->database;
#my $database = $self->database;

my $database = $self->plugin_database($self->db_connection_name);

# Look up the user,
my $user = $database->quick_select(
Expand All @@ -389,14 +402,44 @@ sub get_user_details {
}
}

=Head2 get_user_by_code

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Head2/head2/


Used when reseting user passwords

=cut

sub get_user_by_code {
my ($self, $code) = @_;
croak "code must be defined"
unless defined $code;

# Get our database handle and find out the table and column names:
#my $database = $self->database;

my $database = $self->plugin_database($self->db_connection_name);

# Look up the user,
my $user = $database->quick_select(
$self->users_table, { $self->users_pw_reset_code_column => $code }
);
if (!$user) {
$self->plugin->app->log("debug", "No such user for code $code");
return;
} else {
return $user->{username};
}
}

=head2 get_user_roles $username

=cut

sub get_user_roles {
my ($self, $username) = @_;

my $database = $self->database;
#my $database = $self->database;

my $database = $self->plugin_database($self->db_connection_name);

# Get details of the user first; both to check they exist, and so we have
# their ID to use.
Expand Down