Database/Model/Login.pm untested

filter: Statementstmt 0.0% 0 / 20 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 29 CC 2 SCAR 12.0
CC
2
Cov
0%
login
6.0
check_creds
2.0
BEGIN
2.0
CRAP 3.3
1 package Daje::Database::Model::Login;
2 use Mojo::Base 'Daje::Database::Model::Super::Users', -base, -signatures, -async_await;
3  
4 # Autogenerated class Sun Feb 9 13:11:20 2025
5 # This class is generated once. Any over rides or special methods should be put here
6  
7 # NAME
8 # ====
9 #
10 # Daje::Database::Model::Login - It's the login class for users
11 #
12 #
13 # REQUIRES
14 # ========
15 #
16 # use Mojo::Base;
17 # use Daje::Database::Model::Super::Users;
18 #
19 # DESCRIPTION
20 # ===========
21 #
22 # Daje::Database::Model::Login is logging in users
23 #
24 # LICENSE
25 # =======
26 #
27 # Copyright (C) janeskil1525.
28 #
29 # This library is free software; you can redistribute it and/or modify
30 # it under the same terms as Perl itself.
31 #
32 # AUTHOR
33 # ======
34 #
35 # janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
36 #
37 #
38  
39 use Data::Dumper;
40 use Digest::SHA qw{sha512_base64};
41  
42 our $VERSION = "0.01";
43  
44 has 'pg';
45  
46 sub login ($self, $userid, $password) {
47  
48 my $login_stmt = qq{
49 SELECT users_pkey, userid, username, is_admin, companies_pkey, name,
50 password, support
51 FROM users, companies, companies_users
52 WHERE companies_pkey = companies_fkey AND users_pkey = users_fkey
53 AND userid = ? AND password = ? AND active = 1
54 };
55  
56  
57 my $result = $self->pg->db->query($login_stmt,($userid, $password));
58  
59 my $hash;
60 $hash = $result->hash if $result->rows;
61 say "Login " . Dumper($hash);
62 return $hash;
63 }
64  
65 sub check_creds ($self, $userid, $password) {
66  
67 my $check_stmt = qq{
68 SELECT count(*) as exists
69 FROM users, companies, users_companies
70 WHERE companies_pkey = companies_fkey AND users_pkey = users_fkey
71 AND userid = ? AND passwd = ? AND active = 1
72 };
73  
74 my $result = $self->pg->db->query(
75 $check_stmt,($userid, $password)
76 )->hash->{exists};
77  
78 return $result;
79 }
80  
81  
82  
83  
84 1;
85  
86  
87 #################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################
88  
89 =head1 NAME
90  
91 Daje::Database::Model::Login
92  
93  
94 =head1 DESCRIPTION
95  
96 Autogenerated class Sun Feb 9 13:11:20 2025
97 This class is generated once. Any over rides or special methods should be put here
98  
99  
100 =head1 REQUIRES
101  
102 L<Digest::SHA>
103  
104 L<Data::Dumper>
105  
106 L<Mojo::Base>
107  
108  
109 =head1 METHODS
110  
111 =head2 check_creds
112  
113 check_creds();
114  
115 =head2 login
116  
117 login();
118  
119  
120 =cut
121