diff --git a/db/postgresql/issue248_choose_role.sql b/db/postgresql/issue248_choose_role.sql new file mode 100644 index 0000000000000000000000000000000000000000..ff3ad66048ba3d15664273e1a2fedccea5011b4a --- /dev/null +++ b/db/postgresql/issue248_choose_role.sql @@ -0,0 +1,9 @@ +DROP FUNCTION IF EXISTS public.GetAccountExtIdByInila(pinila character varying); +CREATE OR REPLACE FUNCTION public.GetAccountExtIdByInila(pinila character varying) + RETURNS character varying +LANGUAGE sql +AS $function$ +SELECT accounts.externalid FROM accounts +WHERE inila = pinila; + +$function$; diff --git a/media/js/sign.js b/media/js/sign.js index e03b4429c52c5d147e772fe2cbc2877a8a932ece..0b633c54f42b635152ceed1e1419f841876a2b7e 100644 --- a/media/js/sign.js +++ b/media/js/sign.js @@ -22,11 +22,12 @@ $(function () { const tryToAuthorizeByOpenID = function () { const login = $loginOpenID.val(); + const userRole = $('#user_role').val(); if (! login.trim()) { alert('Необходимо ввести логин ЮФУ') return; } - window.location = g_URLdir + "handler/sign/openidlogin?loginopenid=" + login; + window.location = g_URLdir + "handler/sign/openidlogin?loginopenid=" + login + "&user_role=" + userRole; }; $signInOpenIDButton.click(tryToAuthorizeByOpenID); diff --git a/~dev_rating/application/classes/Controller/Handler/Sign.php b/~dev_rating/application/classes/Controller/Handler/Sign.php index d05253f1e92f7005da44e9b512b5ee7f51aef25a..7e8e4d0c159fff20bcd162888258799530187d1b 100644 --- a/~dev_rating/application/classes/Controller/Handler/Sign.php +++ b/~dev_rating/application/classes/Controller/Handler/Sign.php @@ -77,12 +77,14 @@ class Controller_Handler_Sign extends Controller_Handler public function action_openidlogin() { $openid = new OpenID; + $loginopenid = explode('@', $_GET["loginopenid"])[0]; + $user_role = $_GET["user_role"]; $openid->SetIdentity("https://openid.sfedu.ru/server.php/idpage?user=" . $loginopenid); $openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]); $openid->SetOptionalFields(['email', 'nickname', 'r61globalkey', 'staff', 'student', 'r61studentid']); if ($openid->GetOpenIDServer()) { - $openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . Kohana::$base_url . 'handler/sign/openidfinish'); + $openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . Kohana::$base_url . 'handler/sign/openidfinish?user_role='.$user_role); $openid->Redirect(); } else { $error = $openid->GetError(); @@ -121,11 +123,23 @@ class Controller_Handler_Sign extends Controller_Handler $isStaff = $_GET["openid_sreg_staff"]; $globalKey = $_GET["openid_sreg_r61globalkey"]; $email = $_GET["openid_sreg_email"]; + $chosen_role = $_GET["user_role"]; $id = 0; $error = null; try { - if ($isStudent) { + if ($isStudent && $isStaff) { + if ($chosen_role === 'student') { + // find student with same ext id + $inila = str_replace('st-ss-', '', $globalKey); + $extId = Model_Account::getAccountExtIdByInila($inila); + $globalKey = 'st-'.$extId; + $id = User::instance()->signInByOpenID($globalKey); + } else { + $globalKey = str_replace('st-ss-', 'ss-', $globalKey); + $id = User::instance()->signInByOpenID($globalKey); + } + } elseif ($isStudent) { $globalKey = 'st-' . str_pad(str_replace('st-', '', $globalKey), 9, '0', STR_PAD_LEFT); $id = User::instance()->signInByOpenID($globalKey); } elseif ($isStaff) { diff --git a/~dev_rating/application/classes/Model/Account.php b/~dev_rating/application/classes/Model/Account.php index a7abcaea4048dbeced58a2a5c61b4e7370a38e23..51d768e12de34798a838d69e528f028ebf9d3857 100644 --- a/~dev_rating/application/classes/Model/Account.php +++ b/~dev_rating/application/classes/Model/Account.php @@ -88,6 +88,13 @@ class Model_Account extends Model ->execute()->get('Num'); } + public static function getAccountExtIdByInila($inila) { + $sql = 'SELECT * FROM GetAccountExtIdByInila(:value) AS "Num"'; + return DB::query(Database::SELECT, $sql) + ->param(':value', $inila) + ->execute()->get('Num'); + } + // ===================================== // sign up diff --git a/~dev_rating/application/views/sign/in.twig b/~dev_rating/application/views/sign/in.twig index 7ef276e98656008f0df4b98f4ffd704592f4d29e..51b860626df905b836fdcec7af638eaad65b51fe 100644 --- a/~dev_rating/application/views/sign/in.twig +++ b/~dev_rating/application/views/sign/in.twig @@ -12,7 +12,15 @@ {% if GradeAuthAllowed %}{{ HTML.anchor('#', 'Вход через локальную учетную запись', {'class': 'authMethodToggler', 'id': 'grade'})|raw }} | {{ HTML.anchor('sign/up', 'Активировать аккаунт')|raw }} - | {{ HTML.anchor('remind', 'Забыли пароль?')|raw }} {% endif %} + | {{ HTML.anchor('remind', 'Забыли пароль?')|raw }} + | <label title="При наличии аккаунтов студента и преподавателя следует выбрать какой из них использовать"> + <input id="user_role" list="user_roles"> + <datalist id = "user_roles"> + <option value="student"> + <option value="staff"> + </datalist> + Выберите роль + </label>{% endif %} </div> </div> <div id='GradeAuthDiv' style='display:none'>