PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/templates/user/register.mako

https://bitbucket.org/cistrome/cistrome-harvard/
Mako | 171 lines | 151 code | 18 blank | 2 comment | 4 complexity | b0af4b096aa2c0af96f4aff5e8cfbdb8 MD5 | raw file
  1<%inherit file="/base.mako"/>
  2<%namespace file="/message.mako" import="render_msg" />
  3
  4%if redirect_url:
  5    <script type="text/javascript">  
  6        top.location.href = '${redirect_url | h}';
  7    </script>
  8%endif
  9
 10<%def name="javascripts()">
 11    ${parent.javascripts()}
 12</%def>
 13
 14%if not redirect_url and message:
 15    ${render_msg( message, status )}
 16%endif
 17
 18## An admin user may be creating a new user account, in which case we want to display the registration form.
 19## But if the current user is not an admin user, then don't display the registration form.
 20%if trans.user_is_admin() or not trans.user:
 21    ${render_registration_form()}
 22
 23    %if trans.app.config.get( 'terms_url', None ) is not None:
 24        <br/>
 25        <p>
 26            <a href="${trans.app.config.get('terms_url', None)}">Terms and Conditions for use of this service</a>
 27        </p>
 28    %endif
 29%endif
 30
 31<%def name="render_registration_form( form_action=None )">
 32
 33    <%
 34        if form_action is None:
 35            form_action = h.url_for( controller='user', action='create', cntrller=cntrller )
 36        from galaxy.web.form_builder import CheckboxField
 37        subscribe_check_box = CheckboxField( 'subscribe' )
 38    %>
 39
 40<script type="text/javascript">
 41	$(document).ready(function() {
 42
 43		function validateString(test_string, type) { 
 44			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,}))$/;
 45			//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))*$/;
 46			var username_re = /^[a-z0-9\-]{3,255}$/;
 47			if (type === 'email') {
 48				return mail_re.test(test_string);
 49			} else if (type === 'username'){
 50				return username_re.test(test_string);
 51			}
 52		} 
 53
 54		function renderError(message) {
 55		if ($(".errormessage").length === 1) {
 56			$(".errormessage").html(message)
 57		} else {
 58			var div = document.createElement("div");
 59			div.className = "errormessage";
 60			div.innerHTML = message;
 61			document.body.insertBefore(div, document.body.firstChild);
 62			}
 63		}
 64
 65		$('#registration').bind('submit', function(e) {
 66			$('#send').attr('disabled', 'disabled');
 67            
 68            // we need this value to detect submitting at backend
 69			var hidden_input = '<input type="hidden" id="create_user_button" name="create_user_button" value="Submit"/>';
 70			$("#email_input").before(hidden_input);
 71
 72			var error_text_email= 'Please enter your valid email address';
 73			var error_text_email_long= 'Email cannot be more than 255 characters in length';
 74			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.';
 75			var error_text_password_short = 'Please use a password of at least 6 characters';
 76			var error_text_password_match = "Passwords don't match";
 77
 78		    var validForm = true;
 79		    
 80		    var email = $('#email_input').val();
 81		    var name = $('#name_input').val();
 82		    if (email.length > 255){ renderError(error_text_email_long); validForm = false;}
 83		    else if (!validateString(email,"email")){ renderError(error_text_email); validForm = false;}
 84		    else if (!($('#password_input').val() === $('#password_check_input').val())){ renderError(error_text_password_match); validForm = false;}
 85		    else if ($('#password_input').val().length < 6 ){ renderError(error_text_password_short); validForm = false;}
 86		    else if (name && !(validateString(name,"username"))){ renderError(error_text_username_characters); validForm = false;}
 87
 88	   		if (!validForm) { 
 89		        e.preventDefault();
 90		        // reactivate the button if the form wasn't submitted
 91		        $('#send').removeAttr('disabled');
 92		        }
 93			});
 94	});
 95
 96</script>
 97    <div class="toolForm">
 98        <form name="registration" id="registration" action="${form_action}" method="post" >
 99            <div class="toolFormTitle">Create account</div>
100            <div class="form-row">
101                <label>Email address:</label>
102                <input id="email_input" type="text" name="email" value="${email | h}" size="40"/>
103                <input type="hidden" name="redirect" value="${redirect | h}" size="40"/>
104            </div>
105            <div class="form-row">
106                <label>Password:</label>
107                <input id="password_input" type="password" name="password" value="" size="40"/>
108            </div>
109            <div class="form-row">
110                <label>Confirm password:</label>
111                <input id="password_check_input" type="password" name="confirm" value="" size="40"/>
112            </div>
113            <div class="form-row">
114                <label>Public name:</label>
115                <input id="name_input" type="text" name="username" size="40" value="${username |h}"/>
116                %if t.webapp.name == 'galaxy':
117                    <div class="toolParamHelp" style="clear: both;">
118                        Your public name is an identifier that will be used to generate addresses for information
119                        you share publicly. Public names must be at least four characters in length and contain only lower-case
120                        letters, numbers, and the '-' character.
121                    </div>
122                %else:
123                    <div class="toolParamHelp" style="clear: both;">
124                        Your public name provides a means of identifying you publicly within this tool shed. Public
125                        names must be at least four characters in length and contain only lower-case letters, numbers,
126                        and the '-' character.  You cannot change your public name after you have created a repository
127                        in this tool shed.
128                    </div>
129                %endif
130            </div>
131                <div class="form-row">
132                    <label>Join Our Cistrome Google Group:</label>
133                    <a href="http://groups.google.com/group/cistrome">http://groups.google.com/group/cistrome</a>
134                </div>
135            %if user_type_fd_id_select_field and len( user_type_fd_id_select_field.options ) > 1:
136                <div class="form-row">
137                    <label>User type</label>
138                    ${user_type_fd_id_select_field.get_html()}
139                </div>
140            %endif
141            %if user_type_form_definition:
142                %for field in widgets:
143                    <div class="form-row">
144                        <label>${field['label']}</label>
145                        ${field['widget'].get_html()}
146                        <div class="toolParamHelp" style="clear: both;">
147                            ${field['helptext']}
148                        </div>
149                        <div style="clear: both"></div>
150                    </div>
151                %endfor
152                %if not user_type_fd_id_select_field:
153                    <input type="hidden" name="user_type_fd_id" value="${trans.security.encode_id( user_type_form_definition.id )}"/>
154                %endif   
155            %endif
156            <div id="for_bears">
157            If you see this, please leave following field blank. 
158            <input type="text" name="bear_field" size="1" value=""/>
159            </div>
160            <div class="form-row">
161                <input type="submit" id="send" name="create_user_button" value="Submit"/>
162            </div>
163        </form>
164        %if registration_warning_message:
165        <div class="alert alert-danger" style="margin: 30px 12px 12px 12px;">
166            ${registration_warning_message}           
167        </div>
168        %endif
169    </div>
170
171</%def>