public function index(string $jwt, string $url = '') { if ($payload = $this->jwtEx->decode($jwt)) { if ($user_id = $payload->user_id ?? 0) { if ($user = User::find($user_id)) { if (!empty($payload->authorize)) { /** @var User $user */ if ($user->verified == 'n') { $user->ip_addr = $this->sniffer->getUserIP(); $user->verified = 'y'; $user->save(); } $this->session->startSession($user_id); } if (!empty($payload->eventName)) { $event = new UserEvent($user_id, $user->toArray()); $event->setData($payload->eventData ?? ''); $this->dispatcher->fire($payload->eventName, $event); } } } } else { $params = ['msg' => 'Sorry this link has expired']; } return new Redirection($url ?: '/', $params ?? []); }
public function index($redir = '') { $userId = $this->session->getLoggedInUserId(); $this->session->destroySession(); $this->session->startSession($userId); return new Redirection($redir ?: '/members'); }
public function index($_params) { $event = new UserLoginEvent($_params); $this->dispatcher->fire(UserLoginEvent::USER_LOGIN_AUTHENTICATE, $event); if ($user = $event->getUser()) { $this->session->startSession($user->user_id); return json_encode(['update' => ['user' => $user], 'event' => 'session_user_login']); } else { throw new UserLoginError($event->getError() ?: 'UNKNOWN_ERROR'); } }
public function registerUser($_params) { $event = new UserSignupEvent($_params); $this->dispatcher->fire(UserSignupEvent::USER_SIGNUP_BEGIN, $event); if ($user = $event->getUser()) { $this->session->startSession($user->user_id); return $user; } else { throw new UserSignupError($event->getError() ?: 'UNKNOWN_ERROR'); } }
/** * @param $provider * * @throws HybridAuthError */ public function index($provider) { if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) { Hybrid_Endpoint::process(); } else { try { $map = ['Facebook' => 'id', 'Google' => 'id', 'GitHub' => 'id']; $settings = ['Facebook' => ['scope' => 'email', 'display' => 'popup'], 'Google' => ['scope' => 'https://www.googleapis.com/auth/userinfo.email'], 'Twitter' => ['includeEmail' => true]]; $config = $this->providers->getProvider($provider); if (!empty($config['key']) && !empty($config['secret'])) { $pConfig = array_merge(['enabled' => true, "keys" => [$map[$provider] ?? 'key' => $config['key'], 'secret' => $config['secret']]], $settings[$provider] ?? []); $config = ["providers" => [$provider => $pConfig]]; $hauth = new Hybrid_Auth($config); $auth = $hauth->authenticate($provider); if ($profile = $auth->getUserProfile()) { $event = 'session_user_login'; $data = ['ident' => $profile->identifier, 'email' => $profile->email, 'first_name' => $profile->firstName, 'last_name' => $profile->lastName, 'photo_url' => $profile->photoURL, 'verified' => 'true']; /** @var User $user */ if ($user = User::where('ident', '=', $profile->identifier)->first()) { if (empty($user->email) && !empty($profile->email)) { $user->email = $profile->email; $user->save(); } if (!empty($profile->email)) { $user->contact_email = $profile->email; $user->save(); } } elseif (!empty($profile->email) && ($user = User::where('email', '=', $profile->email)->first())) { $user->ident = $profile->identifier; $user->save(); } else { $user = $this->signupHandler->registerUser($data); $event = 'session_user_signup'; } if ($user_id = $user->user_id ?? null) { $this->session->startSession($user_id); $socialEvent = new UserSocialEvent($user->user_id, array_merge((array) $profile, ['provider' => $provider])); $this->dispatcher->fire($event === 'session_user_signup' ? UserSocialEvent::USER_SOCIAL_SIGNUP : UserSocialEvent::USER_SOCIAL_LOGIN, $socialEvent); $userData = json_encode(['user' => $user->toArray()]); printf("<scrip" . "t>try { self.opener.Minute.setSessionData(%s, '%s'); } catch(err) { console.log(err); } finally { self.window.close(); }</script>", $userData, $event); } } } else { throw new Exception("Configuration for {$provider} is incomplete"); } } catch (\Throwable $e) { Hybrid_Auth::logoutAllProviders(); throw new HybridAuthError($e->getMessage()); } } }
public function setup(HttpRequestEx $request) { $params = $request->getParameters(); try { if (!empty($params['db']['database']) && !empty($params['db']['username']) && !empty($params['db']['password'])) { try { $conn = $this->database->connect($params['db']); if ($pdo = $conn->getPdo()) { $conf = sprintf('%s/app/Config/db-config', $this->bootLoader->getBaseDir()); if (file_put_contents($conf, sprintf('mysql://%s:%s@%s/%s', $params['db']['username'], $params['db']['password'], $params['db']['host'], $params['db']['database']))) { if ($this->installer->install(['minutephp/site'], 'require', true)) { $sth = $pdo->prepare('REPLACE INTO users SET email = :email, password = :password, ip_addr = :ip, created_at = NOW(), updated_at = NOW(), first_name = "Admin", verified = "true"'); $sth->execute(['email' => sprintf('admin@%s', $params['site']['domain'] ?? 'localhost'), 'password' => password_hash(Str::random(), PASSWORD_DEFAULT), 'ip' => $this->sniffer->getUserIP()]); if ($admin_id = $pdo->lastInsertId()) { $sth = $pdo->prepare('REPLACE INTO m_user_groups set user_id = :user_id, group_name = "admin", created_at = NOW(), updated_at = NOW(), expires_at = "20200101", credits = 999, comments = "First run"'); $sth->execute(['user_id' => $admin_id]); $types = ['public' => $params['site'] ?? [], 'private' => []]; foreach ($types as $type => $data) { $sth = $pdo->prepare('REPLACE INTO m_configs set type = :type, data_json = :data'); $sth->execute(['type' => $type, 'data' => json_encode($data)]); } $this->session->startSession($admin_id); return 'pass'; } } else { throw new FirstRunError($this->lang->getText("Unable to run composer")); } } } } catch (\Throwable $e) { throw new FirstRunError($this->lang->getText("Unable to connect to database.\n") . $e->getMessage()); } } throw new FirstRunError($this->lang->getText('All connection parameters are required. Please check connection details')); } catch (\Throwable $e) { if (!empty($conf) && file_exists($conf)) { @unlink($conf); } throw new FirstRunError("Error: " . $e->getMessage()); } }