You are here: Home / Documentation / How To's / Custom login form for NetID

Custom login form for NetID

by nguyen — published Aug 16, 2016 10:49 AM, last modified Aug 16, 2016 10:49 AM
with NetID logo and help text

<pre>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
metal:use-macro="context/main_template/macros/master"
i18n:domain="plone"&gt;

&lt;head&gt;
&lt;metal:js fill-slot="javascript_head_slot"&gt;
&lt;script type="text/javascript" src=""
tal:attributes="src string:${context/portal_url}/login.js"&gt;
&lt;/script&gt;
&lt;/metal:js&gt;
&lt;metal:block fill-slot="top_slot"
tal:define="dummy python:request.set('disable_border',1);
disable_column_one python:request.set('disable_plone.leftcolumn',1);
disable_column_two python:request.set('disable_plone.rightcolumn',1);" /&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;metal:main fill-slot="main"&gt;

&lt;div id="content-core"&gt;
&lt;metal:login define-macro="login"
tal:define="auth nocall:context/acl_users/credentials_cookie_auth|context/cookie_authentication|nothing;
isURLInPortal nocall:context/portal_url/isURLInPortal;
login_template_ids python:'login login_success login_password login_failed login_form logged_in logout logged_out registered mail_password mail_password_form register require_login member_search_results pwreset_finish localhost'.split();
came_from request/came_from|request/HTTP_REFERER|nothing;
came_from_template_id python:came_from and context.plone_utils.urlparse(came_from)[2].split('/')[-1];
came_from python:test(came_from is not None and isURLInPortal(came_from) and came_from_template_id not in login_template_ids, came_from, None);
next request/next|nothing;
next python:test(next is not None and isURLInPortal(next), next, None);
errors options/state/getErrors;
ac_name auth/name_cookie|string:__ac_name;
ac_password auth/pw_cookie|string:__ac_password;
ac_persist auth/persist_cookie|nothing;
login_name python:request.get('login_name', request.get(ac_name, ''));
checkPermission nocall: context/portal_membership/checkPermission;
site_properties context/portal_properties/site_properties;
use_email_as_login site_properties/use_email_as_login|nothing;
external_login_url site_properties/external_login_url|nothing;
external_login_iframe site_properties/external_login_iframe|nothing;
mail_password python:test(checkPermission('Mail forgotten password', context), portal_url + '/mail_password_form', '');
mail_password_url request/mail_password_url|nothing;
mail_password_url python:test(mail_password_url is not None and isURLInPortal(mail_password_url), mail_password_url, mail_password);
join_actions python:context.portal_actions.listActionInfos('user/join', object=context) or [{}];
join python:join_actions[0].get('url');
join python:test(join and checkPermission('Add portal member', context), join, '');
join_url request/join_url|nothing;
join_url python:test(join_url is not None and isURLInPortal(join_url), join_url, join);
use_normal python:auth and not external_login_url;
use_iframe python:auth and external_login_url and external_login_iframe;
use_external python:auth and external_login_url and not external_login_iframe;
target request/target|nothing;
target python:test(target in ('_parent', '_top', '_blank', '_self'), target, None);
ztu modules/ZTUtils;"&gt;

&lt;dl class="portalMessage error"
id="enable_cookies_message"
style="display:none"&gt;
&lt;dt i18n:translate=""&gt;
Error
&lt;/dt&gt;
&lt;dd i18n:translate="enable_cookies_message_before_login"&gt;
Cookies are not enabled. You must enable cookies before you can log in.
&lt;/dd&gt;
&lt;/dl&gt;

&lt;div tal:condition="python: not auth" i18n:translate="login_form_disabled"&gt;
Since cookie authentication is disabled, cookie-based login is not available.
&lt;/div&gt;

&lt;div id="netID"&gt;

&lt;div id="netIDHeader" style="text-align:center; margin-bottom:10px;"&gt;
&lt;img src="http://plonedev.uwosh.edu/static/netid300.png" id="netIDLogo"&gt;
&lt;/div&gt;

&lt;form tal:define="normal_url python:context.absolute_url()+'/'+template.id;
uses_plonedev_internal_address python:normal_url.count('http://plonedev.uwosh.edu:') and normal_url.count(':80') == 0;
uses_webcluster_internal_address python:normal_url.count('http://plone') and normal_url.count('.webcluster.uwosh.edu:');
uses_internal_address python:uses_plonedev_internal_address or uses_webcluster_internal_address;
"
tal:attributes="action python:normal_url if uses_internal_address else normal_url.replace('http:','https:')"
class="enableAutoFocus"
method="post"
id="login_form"
tal:condition="use_normal"&gt;

&lt;div id="login-form"&gt;

&lt;input type="hidden"
name="came_from"
value=""
tal:attributes="value came_from|nothing" /&gt;

&lt;input type="hidden"
name="next"
value=""
tal:attributes="value next|nothing" /&gt;

&lt;input type="hidden"
name="ajax_load"
value=""
tal:attributes="value request/ajax_load|nothing" /&gt;

&lt;input type="hidden"
name="ajax_include_head"
value=""
tal:attributes="value request/ajax_include_head|nothing" /&gt;

&lt;input type="hidden"
name="target"
value=""
tal:attributes="value request/target|nothing" /&gt;

&lt;input type="hidden"
name="mail_password_url"
value=""
tal:attributes="value request/mail_password_url|nothing" /&gt;

&lt;input type="hidden"
name="join_url"
value=""
tal:attributes="value request/join_url|nothing" /&gt;

&lt;input type="hidden" name="form.submitted" value="1" /&gt;
&lt;input type="hidden" name="js_enabled" id="js_enabled" value="0" /&gt;
&lt;input type="hidden" name="cookies_enabled" id="cookies_enabled" value="" /&gt;
&lt;input type="hidden" name="login_name" id="login_name" value="" /&gt;
&lt;input type="hidden" name="pwd_empty" id="pwd_empty" value="0" /&gt;

&lt;div class="field"
tal:define="error python:errors.get(ac_name, None);"
tal:attributes="class python:test(error, 'field error', 'field')"&gt;

&lt;label i18n:translate="label_login_name"
tal:condition="not:use_email_as_login"
tal:attributes="for ac_name"&gt;NetID Username&lt;/label&gt;

&lt;label i18n:translate="label_email"
tal:condition="use_email_as_login"
tal:attributes="for ac_name"&gt;E-mail&lt;/label&gt;

&lt;div tal:condition="error"
tal:content="error"&gt;Validation error output&lt;/div&gt;

&lt;input type="text"
size="19"
tal:attributes="name ac_name;
id ac_name;
value login_name;"
/&gt;
&lt;!-- &lt;span id="uwoEmail"&gt; @uwosh.edu&lt;/span&gt; --&gt;

&lt;/div&gt;

&lt;div class="field" style="margin-left: -25px;"
tal:define="error python:errors.get(ac_password, None);"
tal:attributes="class python:test(error, 'field error', 'field')"&gt;

&lt;label i18n:translate="label_password"
tal:attributes="for ac_password"&gt;NetID Password&lt;/label&gt;

&lt;div tal:condition="error"
tal:content="error"&gt;Validation error output&lt;/div&gt;

&lt;input type="password" style="font: 17px arial,sans-serif;"
size="19"
tal:attributes="name ac_password;
id ac_password;"
/&gt;
&lt;/div&gt;

&lt;div class="field" tal:condition="ac_persist"&gt;

&lt;input type="checkbox"
class="noborder formRememberName"
value="1"
checked="checked"
id="cb_remember"
tal:attributes="name ac_persist;
checked python:request.get(ac_name, '') and 'checked' or None;"
/&gt;

&lt;tal:username tal:condition="not:use_email_as_login"&gt;
&lt;label for="cb_remember" i18n:translate="label_remember_my_name"&gt;Remember my name.&lt;/label&gt;

&lt;div i18n:translate="help_remember_my_name"
class="formHelp"&gt;
Check this to have your user name filled in automatically when you log in later.
&lt;/div&gt;
&lt;/tal:username&gt;

&lt;tal:email tal:condition="use_email_as_login"&gt;
&lt;label for="cb_remember" i18n:translate="label_remember_my_email"&gt;Remember my email address.&lt;/label&gt;

&lt;div i18n:translate="help_remember_my_email"
class="formHelp"&gt;
Check this to have your email address filled in automatically when you log in later.
&lt;/div&gt;
&lt;/tal:email&gt;

&lt;/div&gt;

&lt;div class="formControls" tal:condition="uses_internal_address"&gt;

&lt;input class="context"
type="submit"
name="submit"
value="Log in (not secure)"
i18n:attributes="value label_log_in;"
/&gt;
&lt;div tal:replace="structure here/nolock_icon.png"/&gt;

&lt;/div&gt;
&lt;div class="formControls" tal:condition="not:uses_internal_address"&gt;

&lt;input class="context"
type="submit"
name="submit"
value="Log in securely"
i18n:attributes="value label_log_in;"
/&gt;
&lt;div tal:replace="structure here/lock_icon.png"/&gt;

&lt;/div&gt;

&lt;/div&gt;

&lt;/form&gt;
&lt;/div&gt;

&lt;form tal:attributes="action external_login_url"
class="enableAutoFocus"
method="get"
id="login_form"
tal:condition="use_external"&gt;

&lt;div id="login-form"&gt;

&lt;input type="hidden"
name="next"
value=""
tal:attributes="value string:${request/URL1}/logged_in" /&gt;

&lt;div class="formControls"&gt;

&lt;input class="context"
type="submit"
name="submit"
value="Log in"
i18n:attributes="value label_log_in;"
/&gt;

&lt;/div&gt;

&lt;/div&gt;

&lt;/form&gt;

&lt;tal:use_iframe condition="use_iframe"&gt;

&lt;form action="#"
method="get"
id="login_form"
name="login_form"
class="iframe-wrapper"
tal:define="params python:dict(next=request.URL1+'/logged_in', target='_parent', ajax_load=True, ajax_include_head=True, mail_password_url=mail_password, join_url=join);
dummy python:came_from and params.update(dict(came_from=came_from));
src external_login_url"
tal:attributes="action src"&gt;

&lt;div id="login-form"&gt;

&lt;iframe name="login-form-iframe"
id="login-form-iframe"
tal:attributes="src python:external_login_url+test(join_url.find('?')==-1, '?', '&amp;amp;')+ztu.make_query(params);"
&gt;

&lt;input tal:replace="structure python:ztu.make_hidden_input(params)" /&gt;

&lt;div class="formControls"&gt;

&lt;input class="context"
type="submit"
name="submit"
value="Log in"
i18n:attributes="value label_log_in;"
/&gt;

&lt;/div&gt;

&lt;/iframe&gt;

&lt;/div&gt;

&lt;/form&gt;

&lt;/tal:use_iframe&gt;

&lt;div id="login-forgotten-password"
tal:condition="python:mail_password_url and use_normal"&gt;
&lt;strong i18n:translate="box_forgot_password_option"&gt;
Forgot your password?
&lt;/strong&gt;
&lt;p class="discreet"
i18n:translate="help_password_retrieval"&gt;
If you have forgotten your password,
&lt;span i18n:name="click_here"&gt;
&lt;a tal:define="mail_password_url python:mail_password_url+test(mail_password_url.find('?')==-1, '?', '&amp;amp;')+ztu.make_query(userid=login_name)"
tal:attributes="href mail_password_url; target target;"
i18n:translate="label_click_here_to_retrieve"&gt;we can send you a new one&lt;/a&gt;&lt;/span&gt;.
&lt;/p&gt;
&lt;/div&gt;

&lt;div id="uwosh-password-help"&gt;
&lt;strong &gt;
Trouble logging in?
&lt;/strong&gt;
&lt;p &gt;
Your user name is the portion of your uwosh.edu email address that comes before the '@' sign. &lt;br&gt;
Use your NetID password (&lt;a href="http://www.uwosh.edu/acs/services/account-services/netid-account" target="_blank"&gt;more about NetID&lt;/a&gt;)&lt;br&gt;&lt;/p&gt;
&lt;p&gt;If you make several unsuccessful attempts to log in, your account will be locked.&lt;br&gt;
To unlock it, please call the Academic Computing help desk at (920) 424-3020.&lt;/p&gt;

&lt;/div&gt;

&lt;div id="login-new-user"
tal:condition="python:join_url and use_normal"&gt;
&lt;h3 i18n:translate="heading_new_user"&gt;
New user?
&lt;/h3&gt;

&lt;p i18n:translate="description_no_account"&gt;
If you do not have an account here, head over to the
&lt;span i18n:name="registration_form"&gt;
&lt;a href=""
tal:define="join_url python:test(came_from, join_url+test(join_url.find('?')==-1, '?', '&amp;amp;')+ztu.make_query(came_from=came_from), join_url);"
tal:attributes="href join_url; target target;"
i18n:translate="description_no_account_registration_linktext"
&gt;registration form&lt;/a&gt;&lt;/span&gt;.
&lt;/p&gt;

&lt;/div&gt;

&lt;/metal:login&gt;
&lt;/div&gt;

&lt;/metal:main&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>

Navigation