Fix user registration to respect use_panels when in the Galaxy app

This commit is contained in:
Carl Eberhard
2015-03-03 16:11:44 -05:00
parent 83cc4361b7
commit 7ac86312e4
+94 -71
View File
@@ -1,32 +1,59 @@
<%inherit file="/base.mako"/>
<%!
#This is a hack, we should restructure templates to avoid this.
def inherit(context):
print 'context:', context
if context.get('trans').webapp.name == 'galaxy' and context.get( 'use_panels', True ):
return '/webapps/galaxy/base_panels.mako'
else:
return '/base.mako'
%>
<%inherit file="${inherit(context)}"/>
<%def name="init()">
<%
self.has_left_panel=False
self.has_right_panel=False
self.active_view="user"
self.message_box_visible=False
%>
</%def>
<%namespace file="/message.mako" import="render_msg" />
%if redirect_url:
<script type="text/javascript">
top.location.href = '${redirect_url | h}';
</script>
%endif
<%def name="center_panel()">
${body()}
</%def>
<%def name="javascripts()">
${parent.javascripts()}
</%def>
%if not redirect_url and message:
${render_msg( message, status )}
%endif
<%def name="body()">
<div style="${ 'margin: 1em;' if context.get( 'use_panels', True ) else '' }">
## An admin user may be creating a new user account, in which case we want to display the registration form.
## But if the current user is not an admin user, then don't display the registration form.
%if ( cntrller=='admin' and trans.user_is_admin() ) or not trans.user:
${render_registration_form()}
%if redirect_url:
<script type="text/javascript">
top.location.href = '${redirect_url | h}';
</script>
%elif message:
${render_msg( message, status )}
%endif
%if trans.app.config.get( 'terms_url', None ) is not None:
<br/>
<p>
<a href="${trans.app.config.get('terms_url', None)}">Terms and Conditions for use of this service</a>
</p>
%endif
%endif
## An admin user may be creating a new user account, in which case we want to display the registration form.
## But if the current user is not an admin user, then don't display the registration form.
%if ( cntrller=='admin' and trans.user_is_admin() ) or not trans.user:
${render_registration_form()}
%if trans.app.config.get( 'terms_url', None ) is not None:
<br/>
<p>
<a href="${trans.app.config.get('terms_url', None)}">Terms and Conditions for use of this service</a>
</p>
%endif
%endif
</div>
</%def>
<%def name="render_registration_form( form_action=None )">
@@ -37,64 +64,60 @@
subscribe_check_box = CheckboxField( 'subscribe' )
%>
<script type="text/javascript">
$(document).ready(function() {
<script type="text/javascript">
$(document).ready(function() {
function validateString(test_string, type) {
var mail_re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
//var mail_re_RFC822 = /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/;
var username_re = /^[a-z0-9\-]{3,255}$/;
if (type === 'email') {
return mail_re.test(test_string);
} else if (type === 'username'){
return username_re.test(test_string);
}
}
function validateString(test_string, type) {
var mail_re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
//var mail_re_RFC822 = /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/;
var username_re = /^[a-z0-9\-]{3,255}$/;
if (type === 'email') {
return mail_re.test(test_string);
} else if (type === 'username'){
return username_re.test(test_string);
}
}
function renderError(message) {
if ($(".errormessage").length === 1) {
$(".errormessage").html(message)
} else {
var div = document.createElement("div");
div.className = "errormessage";
div.innerHTML = message;
document.body.insertBefore(div, document.body.firstChild);
}
}
function renderError(message) {
if (!$(".errormessage").size()) {
$('<div/>').addClass('errormessage').insertBefore('#registrationForm');
}
$(".errormessage").html(message);
}
$('#registration').bind('submit', function(e) {
$('#send').attr('disabled', 'disabled');
// we need this value to detect submitting at backend
var hidden_input = '<input type="hidden" id="create_user_button" name="create_user_button" value="Submit"/>';
$("#email_input").before(hidden_input);
$('#registration').bind('submit', function(e) {
$('#send').attr('disabled', 'disabled');
// we need this value to detect submitting at backend
var hidden_input = '<input type="hidden" id="create_user_button" name="create_user_button" value="Submit"/>';
$("#email_input").before(hidden_input);
var error_text_email= 'Please enter your valid email address';
var error_text_email_long= 'Email cannot be more than 255 characters in length';
var error_text_username_characters = 'Public name must contain only lowercase letters, numbers and "-". It also has to be shorter than 255 characters but longer than 3.';
var error_text_password_short = 'Please use a password of at least 6 characters';
var error_text_password_match = "Passwords don't match";
var error_text_email= 'Please enter your valid email address';
var error_text_email_long= 'Email cannot be more than 255 characters in length';
var error_text_username_characters = 'Public name must contain only lowercase letters, numbers and "-". It also has to be shorter than 255 characters but longer than 3.';
var error_text_password_short = 'Please use a password of at least 6 characters';
var error_text_password_match = "Passwords don't match";
var validForm = true;
var email = $('#email_input').val();
var name = $('#name_input').val();
if (email.length > 255){ renderError(error_text_email_long); validForm = false;}
else if (!validateString(email,"email")){ renderError(error_text_email); validForm = false;}
else if (!($('#password_input').val() === $('#password_check_input').val())){ renderError(error_text_password_match); validForm = false;}
else if ($('#password_input').val().length < 6 ){ renderError(error_text_password_short); validForm = false;}
else if (name && !(validateString(name,"username"))){ renderError(error_text_username_characters); validForm = false;}
var validForm = true;
var email = $('#email_input').val();
var name = $('#name_input').val();
if (email.length > 255){ renderError(error_text_email_long); validForm = false;}
else if (!validateString(email,"email")){ renderError(error_text_email); validForm = false;}
else if (!($('#password_input').val() === $('#password_check_input').val())){ renderError(error_text_password_match); validForm = false;}
else if ($('#password_input').val().length < 6 ){ renderError(error_text_password_short); validForm = false;}
else if (name && !(validateString(name,"username"))){ renderError(error_text_username_characters); validForm = false;}
if (!validForm) {
e.preventDefault();
// reactivate the button if the form wasn't submitted
$('#send').removeAttr('disabled');
}
});
});
if (!validForm) {
e.preventDefault();
// reactivate the button if the form wasn't submitted
$('#send').removeAttr('disabled');
}
});
});
</script>
</script>
<div class="toolForm">
<div id="registration-form" class="toolForm">
<form name="registration" id="registration" action="${form_action}" method="post" >
<div class="toolFormTitle">Create account</div>
<div class="form-row">