Skip to content

Commit

Permalink
added Account Admin tab with change password form
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 15, 2011
1 parent 51e044f commit 76cad9b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/main/scala/scala/tools/colladoc/page/Profile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ class Profile(rootPack: Package) extends scala.tools.colladoc.page.Template(root
<div id="template">
<div id="profile_tabs">
<ul>
<li><a href="#profile_tab">Profile</a></li>
<li><a href="#profile_tab">Public Profile</a></li>
<li><a href="#account_admin_tab">Account Admin</a></li>
<li><a href="#comments_tab">Comments</a></li>
</ul>
<div id="profile_tab">
<profile:form />
</div>
<div id="account_admin_tab">
<profile:change_password />
</div>
<div id="comments_tab">
<profile:comments />
</div>
Expand Down
62 changes: 60 additions & 2 deletions src/main/scala/scala/tools/colladoc/snippet/ProfileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import net.liftweb.util.BindHelpers._
import net.liftweb.util.DefaultDateTimeConverter._
import net.liftweb.http.{SHtml, S, RequestVar}
import net.liftweb.mapper.By
import net.liftweb.widgets.gravatar.Gravatar
import lib.js.JqUI.SubmitFormWithValidation
import net.liftweb.http.js.JsCmds.SetValById
import net.liftweb.http.js.JE.Str
Expand Down Expand Up @@ -63,7 +62,7 @@ class ProfileOps {
}

val form =
<lift:form class="profile_form">
<lift:form class="form profile_form">
<fieldset>
<p>
<label for="username">Username</label>
Expand Down Expand Up @@ -116,6 +115,64 @@ class ProfileOps {
)
}

def changePasswordForm(user: User) = {
var oldPass, newPass, confirm: String = ""

def doSave(): JsCmd = {
if (user.password.match_?(oldPass)) {
if (newPass == confirm) {
user.password(newPass)
user.validate match {
case Nil =>
S.notice("User successfully saved")
user.save()
case n =>
S.error(n)
}
} else {
S.error("Password doesn't match the confirmation")
}
} else {
S.error("Old password isn't valid")
}
JsCmds.Noop
}

val form =
<lift:form class="form change_password_form">
<fieldset>
<p>
<label for="old">Enter your old password:</label>
<change:old class="text required ui-widget-content ui-corner-all" />
</p>
<p>
<label for="new">Enter your new password:</label>
<change:new class="text required ui-widget-content ui-corner-all" />
</p>
<p>
<label for="confirm">Confirm it:</label>
<change:confirm class="text required ui-widget-content ui-corner-all" />
</p>
<change:submit />
<change:save />
<change:reset />
</fieldset>
</lift:form>

bind("change", form,
"old" -%> SHtml.password("", oldPass = _, ("id", "old")),
"new" -%> SHtml.password("", newPass = _, ("id", "new")),
"confirm" -%> SHtml.password("", confirm = _, ("id", "confirm")),
"submit" -> SHtml.hidden(doSave _),
"save" -> SHtml.a(Text("Save"), SubmitFormWithValidation(".change_password_form"), ("class", "button")),
"reset" -> SHtml.a(Text("Reset"),
SetValById("old", Str(oldPass)) &
SetValById("new", Str(newPass)) &
SetValById("confirm", Str(confirm)),
("class", "button"))
)
}

def body(xhtml: NodeSeq): NodeSeq = {
val user = getUser

Expand Down Expand Up @@ -144,6 +201,7 @@ class ProfileOps {

bind("profile", profile.body,
"form" -> userForm(user),
"change_password" -> changePasswordForm(user),
"fullname" -> Text(fullname),
"comments" -> comments
)
Expand Down
16 changes: 8 additions & 8 deletions src/main/webapp/coprofile.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@
margin-bottom: 7px;
}

.profile_form {
.form {
width: 400px;
}

.profile_form label {
.form label {
display: block;
font-weight: bold;
}

.profile_form input {
.form input {
display: block;
}

.profile_form fieldset {
.form fieldset {
padding: 0;
border: 0;
margin-top: 8px;
}

.profile_form p {
.form p {
margin-bottom: 12px;
}

.profile_form input[readonly] {
.form input[readonly] {
background: #DDD;
}

.profile_form input.text {
.form input.text {
width: 95%;
padding: .4em;
}
Expand All @@ -63,7 +63,7 @@
padding: 4px 10px;
}

.profile_form .error {
.form .error {
color: #666666;
display: block;
font-size: 8pt;
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/scripts/coprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
$(document).ready(function() {
$("#profile_tabs").tabs();
$(".profile_form").validate();
$(".change_password_form").validate();
$(".datetime").prettyDate();
});

0 comments on commit 76cad9b

Please sign in to comment.