public function signin($provider = null) { if ($provider === null) { View::setTemplate('social_signin.tpl.php'); } else { View::setTemplate('third_party.tpl.php'); $service = $this->getSigninServiceObject($provider); $authStatus = $service->signin(); if ($authStatus === false) { View::set('failed', true); View::set('status', 'failed'); } else { // Check if the third party profile exists if it does fetch the // associated user. $thirdPartyProfile = Model::load('third_party_profiles')->fetchFirstWithKey($authStatus['key']); if (count($thirdPartyProfile) > 0) { $_SESSION['user'] = $thirdPartyProfile['user']->toArray(); $_SESSION['logged_in'] = true; $this->performSuccessOperation(); } else { // If the third party profile doesn't exist create it and create // an associated user. However check if the email exists and warn // if necessary $user = Model::load('users')->getJustFirst(array('conditions' => array('email' => $authStatus['email'], 'email<>' => null))); if ($user->count() == 1) { View::set('status', 'existing'); return; } else { $user = Model::load('users')->getNew(); $user->username = $authStatus['email'] == '' ? uniqid() : $authStatus['email']; $user->password = '******'; $user->email = $authStatus['email']; @($avatar = uniqid()); // . '.' . (isset($authStatus['avatar_format']) ? $authStatus['avatar_format'] : end(explode('.', $authStatus['avatar']))); $avatarData = file_get_contents($authStatus['avatar']); file_put_contents("uploads/avatars/{$avatar}", $avatarData); $finfo = new \finfo(FILEINFO_MIME_TYPE); $mime = $finfo->file("uploads/avatars/{$avatar}"); @($finalAvatar = $avatar . '.' . end(explode('/', $mime))); rename("uploads/avatars/{$avatar}", "uploads/avatars/{$finalAvatar}"); $user->avatar = $finalAvatar; $user->firstname = $authStatus['firstname']; $user->lastname = $authStatus['lastname']; $user->email_confirmed = $authStatus['email_confirmed']; $userID = $user->save(); $user->id = $userID; $thirdParty = Model::load('third_party_profiles')->getNew(); $thirdParty->user_id = $userID; $thirdParty->provider = $service->getProvider(); $thirdParty->key = $authStatus['key']; $thirdParty->save(); $_SESSION['user'] = $user->toArray(); $_SESSION['logged_in'] = true; $this->performSuccessOperation(); } } } } }
public function rest($path) { View::setLayout('plain'); View::setTemplate('api'); $model = $this->getModel($path); $model->limit(Input::get('limit')); $model->offset((Input::get('page') - 1) * Input::get('limit')); header("X-Item-Count: " . $model->count()); View::set('response', $model->fetch()->toArray()); }
public function executeControllerAction($action, $params) { $name = $this->getName(); $path = Text::camelize($action); $return = null; $invokeParameters = []; if ($methodDetails = $this->getMethod($path)) { panie\InjectionContainer::bind(controllers\ModelBinderInterface::class)->to($methodDetails['binder']); $method = new \ReflectionMethod($this, $methodDetails['name']); honam\TemplateEngine::prependPath("views/{$name}"); if (View::getTemplate() == null) { View::setTemplate("{$name}_{$action}" . '.tpl.php'); } $methodParameters = $method->getParameters(); foreach ($methodParameters as $methodParameter) { $this->bindParameter($invokeParameters, $methodParameter, $params); } $method->invokeArgs($this, $invokeParameters); $return = View::out(); echo $return; return; } else { foreach ($this->loadedComponents as $component) { //@todo Look at how to prevent this from running several times if ($component->hasMethod($path)) { $component->executeControllerAction($path, $params); return; } } } throw new exceptions\ControllerActionNotFoundException($this, $path); }