public function get_user() { if ($this->enabled() and $this->logged_in()) { $user = Jam::find_or_build($this->_user_model, array($this->_service_field => $this->service_uid())); $user->_is_new = TRUE; $data = $this->service_user_info(); if (!$user->loaded()) { if (isset($data['email'])) { $user = Jam::find_or_build($this->_user_model, array('email' => $data['email'])); if ($user->loaded()) { $user->_is_new = FALSE; } } if (!$user->loaded() and Arr::get($this->_config, 'create_user')) { $user = $this->build_user($data, TRUE); } if (!$user) { throw new Auth_Exception_Service('Service :service user with service uid :id does not exist and faild to create', array(':service' => $this->type(), ':id' => $this->service_uid())); } $user->set($this->_service_field, $this->service_uid()); $user->save(); } elseif (Arr::get($this->_config, 'update_user')) { $user->_is_new = FALSE; $user->load_service_values($this, $data, FALSE); $user->save(); } else { $user->_is_new = FALSE; } return $user; } return FALSE; }
public function model_before_check(Jam_Model $model) { if (!$model->loaded() or $model->changed($this->_ip_field)) { $info = $this->geoip_record($model->{$this->_ip_field}); foreach ($this->_locations as $association => $info_name) { if (isset($info[$info_name])) { $model->{$association} = Jam::find_or_build('location', array('name' => $info[$info_name])); } } } }