forked from shaba/openuds
* Added stat about accessing platform (OS, browser & browser version)
* Added bar informing about cookie usage by site
This commit is contained in:
parent
9ee66cf6ed
commit
54d41c1931
@ -53,7 +53,7 @@ from uds.models import User
|
||||
import logging
|
||||
import six
|
||||
|
||||
__updated__ = '2015-04-30'
|
||||
__updated__ = '2015-05-03'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
authLogger = logging.getLogger('authLog')
|
||||
@ -157,12 +157,15 @@ def __registerUser(authenticator, authInstance, username):
|
||||
username = authInstance.transformUsername(username)
|
||||
logger.debug('Transformed username: {0}'.format(username))
|
||||
|
||||
request = getRequest()
|
||||
|
||||
usr = authenticator.getOrCreateUser(username, authInstance.getRealName(username))
|
||||
if usr is not None and State.isActive(usr.state):
|
||||
# Now we update database groups for this user
|
||||
usr.getManager().recreateGroups(usr)
|
||||
# And add an login event
|
||||
events.addEvent(authenticator, events.ET_LOGIN, username=username, srcip=getRequest().ip) # pylint: disable=maybe-no-member
|
||||
events.addEvent(authenticator, events.ET_LOGIN, username=username, srcip=request.ip) # pylint: disable=maybe-no-member
|
||||
events.addEvent(authenticator, events.ET_PLATFORM, platform=request.os.OS, browser=request.os.Browser, version=request.os.Version) # pylint: disable=maybe-no-member
|
||||
return usr
|
||||
|
||||
return None
|
||||
@ -277,7 +280,7 @@ def webLogin(request, response, user, password):
|
||||
request.session.clear()
|
||||
request.session[USER_KEY] = user.id
|
||||
request.session[PASS_KEY] = CryptoManager.manager().xor(password, cookie)
|
||||
# Ensures that this user will have access througt REST api if logged in through web interface
|
||||
# Ensures that this user will have access through REST api if logged in through web interface
|
||||
REST.Handler.storeSessionAuthdata(request.session, manager_id, user.name, get_language(), user.is_admin, user.staff_member)
|
||||
return True
|
||||
|
||||
|
@ -165,9 +165,9 @@ class StatsManager(object):
|
||||
def noneToEmpty(str):
|
||||
return six.text_type(str) if str is not None else ''
|
||||
|
||||
fld1 = noneToEmpty(kwargs.get('fld1', kwargs.get('username', '')))
|
||||
fld2 = noneToEmpty(kwargs.get('fld2', kwargs.get('srcip', '')))
|
||||
fld3 = noneToEmpty(kwargs.get('fld3', kwargs.get('dstip', '')))
|
||||
fld1 = noneToEmpty(kwargs.get('fld1', kwargs.get('username', kwargs.get('platform', ''))))
|
||||
fld2 = noneToEmpty(kwargs.get('fld2', kwargs.get('srcip', kwargs.get('browser', ''))))
|
||||
fld3 = noneToEmpty(kwargs.get('fld3', kwargs.get('dstip', kwargs.get('version', ''))))
|
||||
fld4 = noneToEmpty(kwargs.get('fld4', kwargs.get('uniqueid', '')))
|
||||
|
||||
StatsEvents.objects.create(owner_type=owner_type, owner_id=owner_id, event_type=eventType, stamp=stamp, fld1=fld1, fld2=fld2, fld3=fld3, fld4=fld4)
|
||||
|
@ -33,8 +33,6 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2015-01-22'
|
||||
|
||||
from django.db import models
|
||||
|
||||
from uds.models.Util import NEVER_UNIX
|
||||
@ -42,6 +40,9 @@ from uds.models.Util import getSqlDatetime
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2015-05-03'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -133,3 +133,61 @@ footer {
|
||||
height: 32px;
|
||||
margin-top: -8px;
|
||||
}
|
||||
|
||||
# cookiebar
|
||||
#cookie-bar {
|
||||
background: #333333;
|
||||
height: 30px;
|
||||
line-height: 24px;
|
||||
color: #eeeeee;
|
||||
text-align: center;
|
||||
padding: 3px 0;
|
||||
}
|
||||
#cookie-bar.fixed {
|
||||
background: #333333;
|
||||
height: 30px;
|
||||
line-height: 24px;
|
||||
color: #eeeeee;
|
||||
text-align: center;
|
||||
padding: 3px 0;
|
||||
position: fixed;
|
||||
bottom: 0px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
#cookie-bar p {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
#cookie-bar a {
|
||||
color: #ffffff;
|
||||
display: inline-block;
|
||||
border-radius: 3px;
|
||||
text-decoration: none;
|
||||
padding: 0 6px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
#cookie-bar .cb-enable {
|
||||
background: #007700;
|
||||
}
|
||||
#cookie-bar .cb-enable:hover {
|
||||
background: #009900;
|
||||
}
|
||||
#cookie-bar .cb-disable {
|
||||
background: #990000;
|
||||
}
|
||||
#cookie-bar .cb-disable:hover {
|
||||
background: #bb0000;
|
||||
}
|
||||
#cookie-bar .cb-policy {
|
||||
background: #0033bb;
|
||||
}
|
||||
#cookie-bar .cb-policy:hover {
|
||||
background: #0055dd;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
#cookie-bar {
|
||||
height: 60px;
|
||||
}
|
||||
}
|
183
server/src/uds/static/js/jquery.cookiebar.js
Normal file
183
server/src/uds/static/js/jquery.cookiebar.js
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (C) 2012 PrimeBox (info@primebox.co.uk)
|
||||
*
|
||||
* This work is licensed under the Creative Commons
|
||||
* Attribution 3.0 Unported License. To view a copy
|
||||
* of this license, visit
|
||||
* http://creativecommons.org/licenses/by/3.0/.
|
||||
*
|
||||
* Documentation available at:
|
||||
* http://www.primebox.co.uk/projects/cookie-bar/
|
||||
*
|
||||
* When using this software you use it at your own risk. We hold
|
||||
* no responsibility for any damage caused by using this plugin
|
||||
* or the documentation provided.
|
||||
*/
|
||||
(function($){
|
||||
$.cookieBar = function(options,val){
|
||||
if(options=='cookies'){
|
||||
var doReturn = 'cookies';
|
||||
}else if(options=='set'){
|
||||
var doReturn = 'set';
|
||||
}else{
|
||||
var doReturn = false;
|
||||
}
|
||||
var defaults = {
|
||||
message: 'We use cookies to track usage and preferences.', //Message displayed on bar
|
||||
acceptButton: true, //Set to true to show accept/enable button
|
||||
acceptText: 'I Understand', //Text on accept/enable button
|
||||
declineButton: false, //Set to true to show decline/disable button
|
||||
declineText: 'Disable Cookies', //Text on decline/disable button
|
||||
policyButton: false, //Set to true to show Privacy Policy button
|
||||
policyText: 'Privacy Policy', //Text on Privacy Policy button
|
||||
policyURL: '/privacy-policy/', //URL of Privacy Policy
|
||||
autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows
|
||||
acceptOnContinue: false, //Set to true to silently accept cookies when visitor moves to another page
|
||||
expireDays: 365, //Number of days for cookieBar cookie to be stored for
|
||||
forceShow: false, //Force cookieBar to show regardless of user cookie preference
|
||||
effect: 'slide', //Options: slide, fade, hide
|
||||
element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id.
|
||||
append: false, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS
|
||||
fixed: false, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position
|
||||
bottom: false, //Force CSS when fixed, so bar appears at bottom of website
|
||||
zindex: '', //Can be set in CSS, although some may prefer to set here
|
||||
redirect: String(window.location.href), //Current location
|
||||
domain: String(window.location.hostname), //Location of privacy policy
|
||||
referrer: String(document.referrer) //Where visitor has come from
|
||||
};
|
||||
var options = $.extend(defaults,options);
|
||||
|
||||
//Sets expiration date for cookie
|
||||
var expireDate = new Date();
|
||||
expireDate.setTime(expireDate.getTime()+(options.expireDays*24*60*60*1000));
|
||||
expireDate = expireDate.toGMTString();
|
||||
|
||||
var cookieEntry = 'cb-enabled={value}; expires='+expireDate+'; path=/';
|
||||
|
||||
//Retrieves current cookie preference
|
||||
var i,cookieValue='',aCookie,aCookies=document.cookie.split('; ');
|
||||
for (i=0;i<aCookies.length;i++){
|
||||
aCookie = aCookies[i].split('=');
|
||||
if(aCookie[0]=='cb-enabled'){
|
||||
cookieValue = aCookie[1];
|
||||
}
|
||||
}
|
||||
//Sets up default cookie preference if not already set
|
||||
if(cookieValue=='' && options.autoEnable){
|
||||
cookieValue = 'enabled';
|
||||
document.cookie = cookieEntry.replace('{value}','enabled');
|
||||
}
|
||||
if(options.acceptOnContinue){
|
||||
if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){
|
||||
doReturn = 'set';
|
||||
val = 'accepted';
|
||||
}
|
||||
}
|
||||
if(doReturn=='cookies'){
|
||||
//Returns true if cookies are enabled, false otherwise
|
||||
if(cookieValue=='enabled' || cookieValue=='accepted'){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else if(doReturn=='set' && (val=='accepted' || val=='declined')){
|
||||
//Sets value of cookie to 'accepted' or 'declined'
|
||||
document.cookie = cookieEntry.replace('{value}',val);
|
||||
if(val=='accepted'){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
//Sets up enable/accept button if required
|
||||
var message = options.message.replace('{policy_url}',options.policyURL);
|
||||
|
||||
if(options.acceptButton){
|
||||
var acceptButton = '<a href="" class="cb-enable">'+options.acceptText+'</a>';
|
||||
}else{
|
||||
var acceptButton = '';
|
||||
}
|
||||
//Sets up disable/decline button if required
|
||||
if(options.declineButton){
|
||||
var declineButton = '<a href="" class="cb-disable">'+options.declineText+'</a>';
|
||||
}else{
|
||||
var declineButton = '';
|
||||
}
|
||||
//Sets up privacy policy button if required
|
||||
if(options.policyButton){
|
||||
var policyButton = '<a href="'+options.policyURL+'" class="cb-policy">'+options.policyText+'</a>';
|
||||
}else{
|
||||
var policyButton = '';
|
||||
}
|
||||
//Whether to add "fixed" class to cookie bar
|
||||
if(options.fixed){
|
||||
if(options.bottom){
|
||||
var fixed = ' class="fixed bottom"';
|
||||
}else{
|
||||
var fixed = ' class="fixed"';
|
||||
}
|
||||
}else{
|
||||
var fixed = '';
|
||||
}
|
||||
if(options.zindex!=''){
|
||||
var zindex = ' style="z-index:'+options.zindex+';"';
|
||||
}else{
|
||||
var zindex = '';
|
||||
}
|
||||
|
||||
//Displays the cookie bar if arguments met
|
||||
if(options.forceShow || cookieValue=='enabled' || cookieValue==''){
|
||||
if(options.append){
|
||||
$(options.element).append('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>');
|
||||
}else{
|
||||
$(options.element).prepend('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>');
|
||||
}
|
||||
}
|
||||
|
||||
//Sets the cookie preference to accepted if enable/accept button pressed
|
||||
$('#cookie-bar .cb-enable').click(function(){
|
||||
document.cookie = cookieEntry.replace('{value}','accepted');
|
||||
if(cookieValue!='enabled' && cookieValue!='accepted'){
|
||||
window.location = options.currentLocation;
|
||||
}else{
|
||||
if(options.effect=='slide'){
|
||||
$('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();});
|
||||
}else if(options.effect=='fade'){
|
||||
$('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();});
|
||||
}else{
|
||||
$('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
//Sets the cookie preference to declined if disable/decline button pressed
|
||||
$('#cookie-bar .cb-disable').click(function(){
|
||||
var deleteDate = new Date();
|
||||
deleteDate.setTime(deleteDate.getTime()-(864000000));
|
||||
deleteDate = deleteDate.toGMTString();
|
||||
aCookies=document.cookie.split('; ');
|
||||
for (i=0;i<aCookies.length;i++){
|
||||
aCookie = aCookies[i].split('=');
|
||||
if(aCookie[0].indexOf('_')>=0){
|
||||
document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/';
|
||||
}else{
|
||||
document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/';
|
||||
}
|
||||
}
|
||||
document.cookie = cookieEntry.replace('{value}','declined');
|
||||
if(cookieValue=='enabled' && cookieValue!='accepted'){
|
||||
window.location = options.currentLocation;
|
||||
}else{
|
||||
if(options.effect=='slide'){
|
||||
$('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();});
|
||||
}else if(options.effect=='fade'){
|
||||
$('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();});
|
||||
}else{
|
||||
$('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
@ -88,6 +88,7 @@
|
||||
<script src="{% get_static_prefix %}js/jquery-ui.min.js"></script>
|
||||
<script src="{% get_static_prefix %}js/jquery.cookie.js"></script>
|
||||
<script src="{% get_static_prefix %}js/jquery.blockUI.js"></script>
|
||||
<script src="{% get_static_prefix %}js/jquery.cookiebar.js"></script>
|
||||
<script src="{% get_static_prefix %}js/bootstrap.min.js"></script>
|
||||
<script src="{% get_static_prefix %}js/bootstrap-switch.min.js"></script>
|
||||
<script src="{% get_static_prefix %}js/bootstrap-select.min.js"></script>
|
||||
@ -100,6 +101,19 @@
|
||||
<script>
|
||||
$(function(){
|
||||
$('.selectpicker').selectpicker();
|
||||
|
||||
$.cookieBar({
|
||||
fixed: true,
|
||||
zindex: 10000,
|
||||
message: '{% trans "We use cookies to track usage and preferences" %}',
|
||||
acceptText: '{% trans "I Understand" %}',
|
||||
policyButton: false,
|
||||
policyText: '{% trans "Privacy Policy" %}',
|
||||
policyURL: '/',
|
||||
forceShow: false,
|
||||
append: false
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endcompress %}
|
||||
|
Loading…
Reference in New Issue
Block a user