Skip to content
Snippets Groups Projects
Commit a3c5bd8a authored by Anton Bagliy's avatar Anton Bagliy
Browse files

ADD: auth buttons for admin inside profiles #327

parent f1e584fa
Branches
No related merge requests found
"use strict";
$(document).ready(() => {
const $id = $('#AdminAuthDiv');
const $signInButton = $('#signin_asid_button');
var Auth = (function () {
var allowRequest = true;
return {
signIn: function (id) {
if (!allowRequest) return;
allowRequest = false;
var self = this;
return $.postJSON(g_URLdir + 'handler/sign/as', {
'id': id,
}).always(() => {
allowRequest = true;
});
},
}
})();
const tryToAuthorizeGrade = function () {
const singleNumRegexp = /\w_(\d+)/;
function parseClass($cell) {
singleNumRegexp.lastIndex = 0;
let found = singleNumRegexp.exec($cell.attr('class'));
return found ? parseInt(found[1]) : 0;
}
const id = parseClass($id);
Auth.signIn(id)
.fail(_ => Popup.error('Неверный id пользователя!'))
.done(() => {
$signInButton.val('Всё отлично!');
window.location.replace(g_URLdir);
})
};
$signInButton.click(tryToAuthorizeGrade);
});
......@@ -6,11 +6,21 @@
{{ HTML.style('static/css/admin/profilePage.css')|raw }}
{{ HTML.script('static/js/optionLoader.js')|raw }}
{{ HTML.script('static/js/admin/students/profile.js')|raw }}
{{ HTML.script('static/js/office/adminProfileAuth.js')|raw }}
<script>
var facultyID = {{ Profile.FacultyID }};
</script>
{% endblock %}
{% macro input(name, type, value, placeholder, focus) %}
{% if focus %}{% set focus = 'autofocus' %}{% endif %}
{% if type != 'button' %}
<input id='{{ name }}' placeholder='{{ placeholder }}' {{ focus }} class="marginBetween defaultForm" type='{{ type }}' name='{{ name }}' value='{{ value }}'>
{% else %}
<input id='{{ name }}' type='{{ type }}' name='{{ name }}' class="defaultForm GreenButton FullWidth" value='{{ value }}'>
{% endif %}
{% endmacro %}
{% block office_content %}
<h2>Профиль студента</h2>
......@@ -102,6 +112,10 @@
<div class="label">Роль:</div>
<div class="labeled_info">{{ Account.Role|default('—') }}</div>
</div>
<h2 class="Margin10 Bottom contentTitle">Авторизация от лица этого пользователя для администратора</h2>
<div id='AdminAuthDiv' class="authuser_{{ Account.ID }}">
{{ _self.input('signin_asid_button', 'button', 'Войти') }}
</div>
</div>
{% endif %}
</div>
......
......@@ -4,8 +4,18 @@
{% block office_media %}
{{ HTML.style('static/css/admin/profilePage.css')|raw }}
{{ HTML.script('static/js/office/adminProfileAuth.js')|raw }}
{% endblock %}
{% macro input(name, type, value, placeholder, focus) %}
{% if focus %}{% set focus = 'autofocus' %}{% endif %}
{% if type != 'button' %}
<input id='{{ name }}' placeholder='{{ placeholder }}' {{ focus }} class="marginBetween defaultForm" type='{{ type }}' name='{{ name }}' value='{{ value }}'>
{% else %}
<input id='{{ name }}' type='{{ type }}' name='{{ name }}' class="defaultForm GreenButton FullWidth" value='{{ value }}'>
{% endif %}
{% endmacro %}
{% block office_content %}
{#{{ dump(Account) }}#}
......@@ -48,6 +58,10 @@
<div class="label">Роль:</div>
<div class="labeled_info">{{ Account.Role|default('—') }} <a href="../../roles/change/{{ Account.ID }}">Изменить</a></div>
</div>
<h2 class="Margin10 Bottom contentTitle">Авторизация от лица этого пользователя для администратора</h2>
<div id='AdminAuthDiv' class="authuser_{{ Account.ID }}">
{{ _self.input('signin_asid_button', 'button', 'Войти') }}
</div>
</div>
{% endif %}
</div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment