package Daje::Plugin::Users;
use Mojo::Base 'Mojolicious::Plugin', -base, -signatures;
use v5.42;

# NAME
# ====
#
# Daje::Plugin::Users - Mojolicious Plugin
#
# SYNOPSIS
# ========
#
# Mojolicious
# ===========
#
#      $self->plugin('Users');
#
# Mojolicious::Lite
# =================
#
#      plugin 'Users';
#
# DESCRIPTION
# ===========
#
# Daje::Plugin::Users is a Mojolicious plugin.
#
# METHODS
# =======
#
# Daje::Plugin::Users inherits all methods from
# Mojolicious::Plugin and implements the following new ones.
#
# register
# ========
#  $plugin->register(Mojolicious->new);
#
# Register plugin in L<Mojolicious> application.
#
# SEE ALSO
# ========
#
# Mojolicious, Mojolicious::Guides, https://mojolicious.org.
#
# LICENSE
# =======
#
# Copyright (C) janeskil1525.
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# AUTHOR
# ======
#
# janeskil1525 E<lt>janeskil1525@gmail.com
#

# This file is generated once automatically by Daje Tools 2026-01-17 11:42:23.
# It will not be touched by Daje Tools again.

# <!-- Autogenerated file 2026-01-17 11:42:23 -->

use Daje::Plugin::Users::Routes;
use Daje::Plugin::Users::Helpers;
use Daje::Database::Migrator;
use Daje::Helper::Users::Login;
use Daje::Plugin::Users::Authorities;
use Daje::Plugin::Users::Languages;
use Data::Dumper;

our $VERSION = '0.01';

sub register ($self, $app, $config) {
    $app->log->debug("Daje::Plugin::Users::register start");

    my $migration->{class} = 'Daje::Database::Users';
    $migration->{name} = 'users';
    $migration->{migration} = 1;
    my $migrations;
    push @{$migrations}, $migration;
    try {
        Daje::Database::Migrator->new(
            pg         => $app->pg,
            migrations => $migrations,
        )->migrate();
    } catch ($e) {
        $app->log->error($e);
    };

    my $r = $app->routes();

    $r->put($app->config->{project} . '/login')->to('Login#login_user');
    $r->put($app->config->{project} . '/new/client/signup')->to('Login#signup');

    $app->auth->put('check_verify/')->to('Login#check_verify');
    $app->auth->put('verify/')->to('Login#verify');
    $app->auth->put('post_login/')->to('Login#post_login');

    $app->helper(
        login => sub {
            state $login = Daje::Helper::Users::Login->new(
                db     => $app->pg->db,
                config => $app->config
            )
        }
    );

    Daje::Plugin::Users::Routes->new()->routes($app, $config);
    Daje::Plugin::Users::Helpers->new()->helpers($app, $config);
    Daje::Plugin::Users::Authorities->new(
        db => $app->pg->db
    )->authorize();

    Daje::Plugin::Users::Languages->new(
        db => $app->pg->db
    )->language();

    $app->log->debug("Daje::Plugin::Users::register ends");
}

1;



#################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################

=head1 NAME


Daje::Plugin::Users - Mojolicious Plugin



=head1 SYNOPSIS




=head1 DESCRIPTION


Daje::Plugin::Users is a Mojolicious plugin.



=head1 REQUIRES

L<Daje::Database::Migrator> 

L<Daje::Plugin::Users::Helpers> 

L<Daje::Plugin::Users::Routes> 

L<v5.42> 

L<Mojo::Base> 


=head1 METHODS


Daje::Plugin::Users inherits all methods from
Mojolicious::Plugin and implements the following new ones.



=head1 Mojolicious::Lite


     plugin 'Users';



=head1 register

 $plugin->register(Mojolicious->new);

Register plugin in L<Mojolicious> application.



=head1 Mojolicious


     $self->plugin('Users');



=head1 SEE ALSO


Mojolicious, Mojolicious::Guides, https://mojolicious.org.



=head1 AUTHOR


janeskil1525 E<lt>janeskil1525@gmail.com



=head1 LICENSE


Copyright (C) janeskil1525.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.



=cut

