Skip to content

Commit

Permalink
"Create new form for password changing (needs for superusers)" closed…
Browse files Browse the repository at this point in the history
… [#129 state: resolved]
  • Loading branch information
ignatov committed Aug 12, 2011
1 parent 785eee1 commit e39a6ed
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/main/scala/scala/tools/colladoc/snippet/ProfileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import xml.{NodeSeq, Text}
import net.liftweb.util.BindHelpers._
import net.liftweb.http.{SHtml, S, RequestVar}
import net.liftweb.mapper.{Ascending, By, OrderBy}
import lib.js.JqUI.{ColladocConfirm, SubmitFormWithValidation}
import lib.js.JqUI.{ColladocConfirm, SubmitFormWithValidation, SubmitForm}
import net.liftweb.http.js.JE.Str
import page.{Template, History, Profile}
import net.liftweb.common.Full
Expand Down Expand Up @@ -243,6 +243,41 @@ class ProfileOps {
)
}

def changePasswordFormForSuperuser(user: User) = {
var newPass = ""

def doSave(): JsCmd = {
user.password(newPass)
user.validate match {
case Nil =>
S.notice("User successfully saved")
user.save()
case n =>
S.error(n)
}

JsCmds.Noop
}

val form =
<lift:form class="form change_password_form_for_superuser">
<fieldset>
<p>
<label for="new">Enter new password:</label>
<change:new class="text required ui-widget-content ui-corner-all" />
</p>
<change:submit />
<change:save />
</fieldset>
</lift:form>

bind("change", form,
"new" -%> SHtml.password("", newPass = _),
"submit" -> SHtml.hidden(doSave _),
"save" -> SHtml.a(Text("Save"), SubmitForm(".change_password_form_for_superuser"), ("class", "button"))
)
}

def deleteProfile(user: User) = {
if (!user.deleted_?)
<div id="delete_account">
Expand Down Expand Up @@ -365,7 +400,15 @@ class ProfileOps {
bind("profile",
profile.body,
"form" -> { if (!public_?) userForm(user) else publicProfile(user) },
"change_password" -> { if (!public_?) changePasswordForm(user) else NodeSeq.Empty },
"change_password" -> {
if (User.validSuperUser_?)
changePasswordFormForSuperuser(user)
else {
if (!public_?)
changePasswordForm(user)
else
NodeSeq.Empty
} },
"delete_profile" -> { if (!public_?) deleteProfile(user) else NodeSeq.Empty },
"superuser" -> { if (User.validSuperUser_?) superuser(user) else NodeSeq.Empty },
"available" -> { if (User.validSuperUser_?) available(user) else NodeSeq.Empty },
Expand Down

0 comments on commit e39a6ed

Please sign in to comment.