/** * test client fingerprint */ public function testClientFingerprint() { // generate server data $this->fakeServerData(); // check if we have an ip address $fingerprint = CCIn::client()->fingerprint; // generate server data $this->fakeServerData(); // check if we have an ip address $this->assertEquals($fingerprint, CCIn::client()->fingerprint); // generate server data $this->fakeServerData(array(), array(), array('HTTP_CF_CONNECTING_IP' => '123.121.123.122')); // check if we have an ip address $this->assertTrue($fingerprint != CCIn::client()->fingerprint); }
/** * Sign the user and optinal also set the resore keys * * @param Auth\User $user * @param bool $keep_login * @return bool */ public function sign_in(\Auth\User $user, $keep_login = true) { // set the session key so the session knows we are logged in $this->session->set($this->config->session_key, $user->{$this->config->user_key}); // update the current user object $this->user = $user; // update the last login timestamp $this->user->last_login = time(); // pass the user trough the events to allow modifications // of the user object at sign in $this->user = \CCEvent::pass('auth.sign_in', $this->user); // save the user object to the database $this->user->save(); // set the restore keys to keep the login // after the session ends if ($keep_login) { $restore_id_cookie = $this->config->get('restore.id_cookie'); $restore_token_cookie = $this->config->get('restore.token_cookie'); $restore_lifetime = $this->config->get('restore.lifetime'); $restore_id = $this->session->get($this->config->session_key); $restore_token = $this->restore_key($this->user); CCCookie::set($restore_id_cookie, $restore_id, $restore_lifetime); CCCookie::set($restore_token_cookie, $restore_token, $restore_lifetime); // try to get the current login $login = $this->select_logins()->where('restore_id', $restore_id)->where('restore_token', $restore_token); // prepare the login data $login_data = array('restore_id' => $restore_id, 'restore_token' => $restore_token, 'last_login' => time(), 'client_agent' => \CCIn::client()->agent); // pass the login data trough the events $login_data = \CCEvent::pass('auth.store_login', $login_data); // if there is no such login create a new one if (!$login->run()) { \DB::insert($this->config->get('logins.table'), $login_data)->run($this->config->get('logins.handler')); } else { \DB::update($this->config->get('logins.table'), $login_data)->where('restore_id', $restore_id)->where('restore_token', $restore_token)->run($this->config->get('logins.handler')); } } // and finally we are authenticated return $this->authenticated = true; }