"User" relation interface: normalizing form styles and such to be consistent

with the rest of the application.
This commit is contained in:
James Taylor
2007-03-08 17:31:28 +00:00
parent 4ac180091e
commit e20cf00c91
2 changed files with 45 additions and 60 deletions
+30 -31
View File
@@ -27,20 +27,20 @@ class User( common.Root ):
old_pass_err = new_pass_err = conf_pass_err = ''
user = trans.get_user()
if not user:
trans.response.send_redirect("/user/login")
if not user.check_password( old_pass ):
old_pass_err = "Invalid password"
elif len( new_pass ) < 6:
new_pass_err = "Please use a password of at least 6 characters"
elif new_pass != conf_pass:
conf_pass_err = "New passwords do not match."
else:
user.set_password_cleartext( new_pass )
user.flush()
trans.log_event( "User change password" )
return trans.show_ok_message( "Password has been changed for " + user.email)
trans.response.send_redirect( "/user/login" )
if trans.request.method == 'POST':
if not user.check_password( old_pass ):
old_pass_err = "Invalid password"
elif len( new_pass ) < 6:
new_pass_err = "Please use a password of at least 6 characters"
elif new_pass != conf_pass:
conf_pass_err = "New passwords do not match."
else:
user.set_password_cleartext( new_pass )
user.flush()
trans.log_event( "User change password" )
return trans.show_ok_message( "Password has been changed for " + user.email)
# Generate input form
return trans.show_form(
web.FormBuilder( "/user/change_password", "Change Password", submit_text="Submit" )
.add_password( "old_pass", "Old Password", value='', error=old_pass_err )
@@ -53,23 +53,22 @@ class User( common.Root ):
user = trans.get_user()
if not user:
trans.response.send_redirect("/user/login")
if not user.check_password( password ):
pass_err = "Invalid password"
elif len( email ) == 0 or "@" not in email or "." not in email:
email_err = "Please enter a real email address"
elif len( email) > 255:
email_err = "Email address exceeds maximum allowable length"
elif len( trans.app.model.User.select_by( email=email ) ) > 0:
email_err = "User with that email already exists"
elif email != conf_email:
conf_email_err = "Email addresses do not match."
else:
user.email = email
user.flush()
trans.log_event( "User change email" )
return trans.show_ok_message( "Email has been changed to: " + user.email, refresh_frames=['masthead', 'history'] )
if trans.request.method == "POST":
if not user.check_password( password ):
pass_err = "Invalid password"
elif len( email ) == 0 or "@" not in email or "." not in email:
email_err = "Please enter a real email address"
elif len( email) > 255:
email_err = "Email address exceeds maximum allowable length"
elif len( trans.app.model.User.select_by( email=email ) ) > 0:
email_err = "User with that email already exists"
elif email != conf_email:
conf_email_err = "Email addresses do not match."
else:
user.email = email
user.flush()
trans.log_event( "User change email" )
return trans.show_ok_message( "Email has been changed to: " + user.email, refresh_frames=['masthead', 'history'] )
return trans.show_form(
web.FormBuilder( "/user/change_email", "Change Email", submit_text="Submit" )
.add_text( "email", "Email", value=email, error=email_err )
+15 -29
View File
@@ -11,38 +11,24 @@
<body onLoad="frame_dw();">
<div class="toolForm">
<div class="toolFormTitle">User settings for $user.email</div>
<h2>User settings for $user.email</h2>
#if $msg:
<p class="ok_bgr">$msg</p>
#end if
<div class="toolFormBody">
<form action="/user/change_password" method="post" >
<table>
<tr><th colspan="2" align="center">Change Your Password</th></tr>
<tr><td>Current Password:</td><td><input type="password" name="old_pass" value="" size="40"></td></tr>
<tr><td>New Password:</td><td><input type="password" name="new_pass" value="" size="40"></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="conf_pass" value="" size="40"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="change_pass_btn" value="Submit"></td></tr>
</form>
<form action="/user/change_email" method="post" >
<tr><th colspan="2" align="center">Update Your Email</th></tr>
<tr><td>New Email:</td><td><input type="text" name="email" value="" size="40"></td></tr>
<tr><td>Confirm Email:</td><td><input type="text" name="conf_email" value="" size="40"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" value="" size="40"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="change_email_btn" value="Submit"></td></tr>
</form>
<tr><th colspan="2" align="center">Actions</a></th></tr>
<tr><td colspan="2">
<ul>
<li><a href="/history_available">View</a> your available histories</li>
<li><a href="/history_store">Store</a> your current history</li>
<li><a href="/history_delete?id=$history.id" onclick="confirm_click('/history_delete?id=$history.id');return false;">Delete</a> your current history</li>
<br>
<li><a href="/user/logout">Logout</a></li>
</ul>
</td></tr>
</table>
</div>
<h3>Account settings</h3>
<ul>
<li><a href="${h.url_for( action='change_password' )}">Change your password</a></li>
<li><a href="${h.url_for( action='change_email' )}">Update your email address</a></li>
<li><a href="${h.url_for( action='logout' )}">Logout</a></li>
</ul>
<h3>Histories</h3>
<ul>
<li><a href="/history_available">View</a> your available histories</li>
<li><a href="/history_store">Store</a> your current history</li>
<li><a href="/history_delete?id=$history.id" onclick="confirm_click('/history_delete?id=$history.id');return false;">Delete</a> your current history</li>
</ul>
</div>
</body>
</html>