public static function login_or_register($strategy) { $token = $strategy->callback(); switch ($strategy->name) { case 'oauth': $user_hash = $strategy->provider->get_user_info($strategy->consumer, $token); break; case 'oauth2': $user_hash = $strategy->provider->get_user_info($token); break; case 'openid': $user_hash = $strategy->get_user_info($token); break; default: throw new Exception("Unsupported Strategy: {$strategy->name}"); } if (\Auth::check()) { list($driver, $user_id) = \Auth::instance()->get_user_id(); $num_linked = Model_Authentication::count_by_user_id($user_id); // Allowed multiple providers, or not authed yet? if ($num_linked === 0 or \Config::get('ninjauth.link_multiple_providers') === true) { // If there is no uid we can't remember who this is if (!isset($user_hash['uid'])) { throw new Exception('No uid in response.'); } // Attach this account to the logged in user Model_Authentication::forge(array('user_id' => $user_id, 'provider' => $strategy->provider->name, 'uid' => $user_hash['uid'], 'access_token' => isset($token->access_token) ? $token->access_token : null, 'secret' => isset($token->secret) ? $token->secret : null, 'expires' => isset($token->expires) ? $token->expires : null, 'refresh_token' => isset($token->refresh_token) ? $token->refresh_token : null, 'created_at' => time()))->save(); // Attachment went ok so we'll redirect \Response::redirect(\Config::get('ninjauth.urls.logged_in')); } else { $auth = Model_Authentication::find_by_user_id($user_id); throw new Exception(sprintf('This user is already linked to "%s".', $auth->provider)); } } else { if ($authentication = Model_Authentication::find_by_uid($user_hash['uid'])) { // Force a login with this username if (\Auth::instance()->force_login($authentication->user_id)) { // credentials ok, go right in \Response::redirect(\Config::get('ninjauth.urls.logged_in')); } } else { \Session::set('ninjauth', array('user' => $user_hash, 'authentication' => array('provider' => $strategy->provider->name, 'uid' => $user_hash['uid'], 'access_token' => isset($token->access_token) ? $token->access_token : null, 'secret' => isset($token->secret) ? $token->secret : null, 'expires' => isset($token->expires) ? $token->expires : null, 'refresh_token' => isset($token->refresh_token) ? $token->refresh_token : null))); \Response::redirect(\Config::get('ninjauth.urls.registration')); } } }
public function action_register() { $user_hash = \Session::get('ninjauth.user'); $authentication = \Session::get('ninjauth.authentication'); $full_name = \Input::post('full_name') ?: \Arr::get($user_hash, 'name'); $username = \Input::post('username') ?: \Arr::get($user_hash, 'nickname'); $email = \Input::post('email') ?: \Arr::get($user_hash, 'email'); $password = \Input::post('password'); if ($username and $full_name and $email and $password) { try { $user_id = \Auth::create_user($username, $password, $email, \Config::get('ninjauth.default_group'), array('full_name' => $full_name)); } catch (SimpleUserUpdateException $e) { \Session::set_flash('ninjauth.error', $e->getMessage()); goto display; } if ($user_id) { Model_Authentication::forge(array('user_id' => $user_id, 'provider' => $authentication['provider'], 'uid' => $authentication['uid'], 'access_token' => $authentication['access_token'], 'secret' => $authentication['secret'], 'refresh_token' => $authentication['refresh_token'], 'expires' => $authentication['expires'], 'created_at' => time()))->save(); } \Response::redirect(\Config::get('ninjauth.urls.registered')); } display: $this->response->body = \View::forge('register', array('user' => (object) compact('username', 'full_name', 'email', 'password'))); }
<?php error_reporting(0); session_start(); $page = $_GET["page"]; $option = $_GET["option"]; require_once 'Model/dbclass.php'; $dbObj = new Model_DBClass(); if (isset($_POST['sub'])) { /*------------------------------- */ require_once 'Model/Authentication.php'; $authenticationObj = new Model_Authentication(); $data["user_name"] = $_POST["login_name"]; $data["user_password"] = $_POST["login_password"]; /*------------------------------- */ if (!empty($data["user_name"]) && !empty($data["user_password"])) { /*$data["password"] = md5($pass);*/ $data["password"] = $pass; $result = $authenticationObj->loginUser($data); $num = $authenticationObj->numRows($result); if ($num == 1) { $row = $authenticationObj->fetchObject($result); $_SESSION["user_id"] = $row->user_id; $_SESSION["user_name"] = $row->user_name; $_SESSION["status"] = $row->status; echo '<script>window.location = "index.php?status=1"; </script>'; } else { echo '<script>window.location = "index.php?status=0"; </script>'; } } }