Ejemplo n.º 1
0
 /**
  *  check the ip's
  *
  * @param LoginObject|ip
  * @return bool
  */
 public function isSameIp($ip)
 {
     if ($ip instanceof LoginObject) {
         $ip = $ip['ip'];
     }
     return $ip === Security::ip();
 }
Ejemplo n.º 2
0
 /**
  * Kullanıcı girişi yaptırılır
  * $remember true girilirse cookie e atanır veriler.
  *
  * @param string $username
  * @param string $password
  * @param bool|false $remember
  * @return bool|LoginObject
  */
 public function login($username = '', $password = '', $remember = false)
 {
     $db = $this->getDb();
     $table = $this->getTables();
     list($userColumnName, $passColumnName) = $table['login'];
     $getTables = $table['select'];
     $getTables[] = $table['authentication']['column'];
     // login
     $login = $db->read($table['table'], function (Read $mode) use($userColumnName, $passColumnName, $username, $password, $getTables) {
         return $mode->where([[$userColumnName, '=', $username], [$passColumnName, '=', $password]])->select($getTables)->build();
     });
     if ($login) {
         if ($login->rowCount()) {
             $login = (array) $login->fetch();
             // we will find user ip address
             // and add it to login informations
             $ip = Security::ip();
             // add client ip addres to login object
             $login['ip'] = $ip;
             $login = new LoginObject($login);
             $this->getSession()->set(static::USER_SESSION, $login);
             if ($remember) {
                 $this->getCookie()->set(static::USER_SESSION, serialize($login));
             }
             $this->getDb()->insert(self::LOGIN_LOGS_TABLE, function (Insert $insert) use($ip, $username) {
                 return $insert->set(['ip' => $ip, 'username' => $username]);
             });
             return $login;
         }
     }
     return false;
 }