Skip to content
Snippets Groups Projects
Commit e5c0bbc4 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts] static/templates/templatetags/views added first account information...

[accounts] static/templates/templatetags/views added first account information for valid user and implemented yearly revalidation functionality
parent 62f32761
No related branches found
No related tags found
1 merge request!224Security accounts
Pipeline #
/****************** ACCOUNT DIALOG ******************************/
div.renew_account .progress
{
margin: 40px auto;
}
div.renew_account #infos
{
text-align: center;
display: block;
margin-top: 10px;
margin-bottom: 10px;
color: #777777;
}
div.renew_account span.label
{
display: inline-block;
width: 15%;
color: black;
font-size: 1em;
}
div.renew_account input#prefix,
div.renew_account input#suffix
{
display: inline-block;
width: 79%;
}
div.renew_account input#suffix
{
margin-top: 10px;
}
div.renew_account span.documentation
{
color: #AAAAAA;
font-size: 0.8em;
}
/*
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
* This file is part of the beat.web module of the BEAT platform.
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
*/
/**
* beat.accounts.dialogs.js
* Implementation of experiment-related dialogs
*/
if (beat === undefined) var beat = {};
if (beat.accounts === undefined) beat.accounts = {};
if (beat.accounts.dialogs === undefined) beat.accounts.dialogs = {};
/**
* Implements a modal dialog to renew a user account.
* The user is presented with a small modal window that will allow
* him to set the new experiment name. It is possible to cancel the action at
* any moment by pressing "Cancel" or hitting the ESC key.
*
* Parameters:
*
* dialog_id: ID of the DOM element to use
* api_url (str): The URL towards the API for renewing the account
* redirect_url (str): The URL where to redirect the user if the operation is
* successful
*/
beat.accounts.dialogs.modal_renew_account = function(dialog_id, api_url, redirect_url) {
// Create the dialog
$('#' + dialog_id).dialog({
autoOpen: false,
resizable: false,
width: Math.min($(window).width() * 0.6, 700),
position: { my: "center", at: "center", of: window },
modal: true,
closeOnEscape: true,
buttons: [
{
id: 'button-' + dialog_id + '-renameit',
text: 'Revalidate account',
click: function() {
$.ajaxSetup({
beforeSend: function(xhr, settings) {
var csrftoken = $.cookie('csrftoken');
xhr.setRequestHeader('X-CSRFToken', csrftoken);
}
});
$.ajax({
type: "PUT",
url: api_url /*+ experiment_fullname + '/' */,
data: JSON.stringify({
name: name,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$('#' + dialog_id).dialog("close");
window.location.href = redirect_url;
},
error: function(jqXHR, textStatus, errorThrown) {
if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0))
alert(jqXHR.responseText);
else
alert('Error: ' + errorThrown);
$(this).dialog("close");
}
});
}
},
{
id: 'button-' + dialog_id + '-cancel',
text: 'Cancel',
click: function() {
$(this).dialog("close");
}
}
]
});
// Display the dialog
$('#' + dialog_id).dialog("open");
}
{% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
* This file is part of the beat.web module of the BEAT platform.
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %}
<div id="{{ dialog_id }}" class="renew_account" style="display:none;" title="Account revalidation">
<div class="settings">
<div><span id="infos"></span></div>
By revalidating your account you acknowledge that you wish to continue using the platform and your
supervision is still valid.
</div>
</div>
......@@ -25,9 +25,27 @@
{% load ui_tags %}
{% load gravatar %}
{% load registration_tags %}
{% load account_tags %}
{% block title %}Settings for {{ request.user.first_name }} ({{ request.user.username }}){% endblock %}
{% block stylesheets %}
{{ block.super }}
<link rel="stylesheet" href="{% fingerprint "accounts/css/dialogs.css" %}" type="text/css" media="screen" />
<link rel="stylesheet" href="{% fingerprint "jquery-ui/themes/base/minified/jquery-ui.min.css" %}" type="text/css" media="screen" />
{% endblock %}
{% block scripts %}
{{ block.super }}
{% csrf_token %}
<script src="{% fingerprint "accounts/js/dialogs.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "jquery-ui/ui/minified/jquery.ui.core.min.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "jquery-ui/ui/minified/jquery.ui.position.min.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "jquery-ui/ui/minified/jquery.ui.widget.min.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "jquery-ui/ui/minified/jquery.ui.button.min.js" %}" type="text/javascript" charset="utf-8"></script>
<script src="{% fingerprint "jquery-ui/ui/minified/jquery.ui.dialog.min.js" %}" type="text/javascript" charset="utf-8"></script>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
......@@ -178,6 +196,63 @@
</div>
</div>
<div class="row">
<div class="col-sm-4 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-credit-card-alt"></i> Account management
{% if user.profile.status == 'A' %}
<span class="label label-success" style="float:right">Status Accepted</span>
{% elif user.profile.status == 'R' %}
<span class="label label-danger" style="float:right">Status Rejected</span>
{% elif user.profile.status == 'Y' %}
<span class="label label-warning" style="float:right">Status Revalidation Required</span>
{% endif %}
</div>
<div class="panel-body">
<form id="token" method="post" action="" class="form">
{% csrf_token %}
<div class="form-group" style="text-align: justify;">
{% if user.profile.status == 'A' %}
<li class="list-group-item list-group-item-success" style="text-align:center;">Status is currently accepted: No action is directly required</li>
<br>
<h4>General Information</h4>
<ul class="list-group">
<li class="list-group-item"><b>Supervisor:</b> {{ supervisiontrack.godfather.username }}</li>
<li class="list-group-item"><b>Supervision Track started on:</b> {{ supervisiontrack.start_date }}</li>
<li class="list-group-item"><b>Supervision Track last validation date:</b> {{ supervisiontrack.last_validation_date }}</li>
<li class="list-group-item"><b>Supervision Track expiration date:</b> {{ supervisiontrack.expiration_date }}</li>
</ul>
{% elif user.profile.status == 'R' %}
<li class="list-group-item list-group-item-warning" style="text-align:center;">Rejected: You need to find a new supervisor</li>
<br>
{% elif user.profile.status == 'Y' %}
<li class="list-group-item list-group-item-warning" style="text-align:center;">Revalidation required: You need to confirm that you wish to revalidate your account (year basis check)</li>
<br>
<h4>General Information</h4>
<ul class="list-group">
<li class="list-group-item"><b>Supervisor:</b> {{ supervisiontrack.godfather.username }}</li>
<li class="list-group-item"><b>Supervision Track started on:</b> {{ supervisiontrack.start_date }}</li>
<li class="list-group-item"><b>Supervision Track last validation date:</b> {{ supervisiontrack.last_validation_date }}</li>
<li class="list-group-item"><b>Supervision Track expiration date:</b> {{ supervisiontrack.expiration_date }}</li>
</ul>
<div class="form-group" style="text-align: center;">
<input type="hidden" name="token" value="true">
<button type="button" class="btn btn-warning" onclick="beat.accounts.dialogs.modal_renew_account('account_renew', '{% url 'api_accounts:revalidate_account' %}', '{% url 'accounts:settings' %}');"><i class="fa fa-refresh fa-fw fa-lg"></i> Revalidate account for 12 months</button>
</div>
{% endif %}
</div>
</form>
</div>
</div>
</div>
</div>
{% account_renew "account_renew" %}
<script type="text/javascript">
jQuery(document).ready(function() {
$('form#token').submit(function(event) {
......
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import random
from django import template
from django.conf import settings
register = template.Library()
@register.inclusion_tag('accounts/dialogs/renew_account.html')
def account_renew(id):
return { 'dialog_id': id,
}
......@@ -29,11 +29,13 @@ from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib import messages
from django.db import models
from rest_framework.authtoken.models import Token
from .forms import AccountSettingsForm
from .models import AccountSettings
from .models import SupervisionTrack, Profile
@login_required
def account_settings(request):
......@@ -65,8 +67,19 @@ def account_settings(request):
account_settings_form = AccountSettingsForm(instance=account_settings)
password_change_form = PasswordChangeForm(user=user)
supervisiontrack = None
if user.profile.is_godfather == False:
supervisee = user
if supervisee.profile.supervision_key is not None:
#There's a key check if there's a valid track
supervisiontrack = SupervisionTrack.objects.get(supervisee=supervisee, supervisee__profile__supervision_key=models.F('supervision_key'))
else:
supervisiontrack = None
return render(request,
'accounts/settings.html',
{'account_settings_form': account_settings_form,
'password_change_form': password_change_form,
'user': user,
'supervisiontrack': supervisiontrack,
'token' : user.auth_token})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment