Blame view

src/lib/models/admins.php 2.55 KB
1ea3b987   Administrator   maby first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  <?php
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  namespace models;
  
  class admins extends \db
  {
      /////////////////////////////////////////////////////////////////////////////
  
      public function adminLogin( $registration )
      {
          $connection = $this->database;
  
          try
          {
              $connection->begin();
  
              $data =  $this->get(
                  '
                      SELECT
                          id,
                          status
                      FROM
                          public.admins
                      WHERE
                          email = :email
                          AND
                          passwd = :passwd
                      LIMIT
                          1
                  ',
                  [
                      'email' => $registration['email'],
                      'passwd' => $registration['passwd'],
                  ],
                  -1
              );
  
              $result = 0;
  
              if( !empty($data) )
              {
                  $this->exec(
                      '
                          UPDATE
                              public.admins
                          SET
                              lastlogin_date  = :lastlogin_date
                          WHERE
                              id     = :id
                      ',
                      [
                          'id'                => $data['0']['id'],
                          'lastlogin_date'    => date( 'Y-m-d H:i' )
                      ]
                  );
  
                  if( $data['0']['status'] == 1 )
                  {
                      $result = 1;
  
                      // auth user
                      $this->getDi()->get('session')->set( 'isAdminAuth',      true );
                      $this->getDi()->get('session')->set( 'adminId',          $data['0']['id'] );
                  }
                  else
                  {
                      $result = 2; // user with status 0
                  }
  
                  unset($data);
              }
              else
              {
                  $result = -1;
              }
  
              $connection->commit();
  
              return $result;
  
          }
          catch(\Exception $e)
          {
              $connection->rollback();
          }
          return false;
      }
  
      /////////////////////////////////////////////////////////////////////////////
  }
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////