mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #340)Add public key validation
This commit is contained in:
@@ -5,6 +5,7 @@ import util._
|
|||||||
import util.StringUtil._
|
import util.StringUtil._
|
||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
|
import ssh.SshUtil
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
@@ -49,7 +50,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val sshKeyForm = mapping(
|
val sshKeyForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"publicKey" -> trim(label("Key" , text(required)))
|
"publicKey" -> trim(label("Key" , text(required, validPublicKey)))
|
||||||
)(SshKeyForm.apply)
|
)(SshKeyForm.apply)
|
||||||
|
|
||||||
case class NewGroupForm(groupName: String, url: Option[String], fileId: Option[String], members: String)
|
case class NewGroupForm(groupName: String, url: Option[String], fileId: Option[String], members: String)
|
||||||
@@ -435,4 +436,11 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}) None else Some("Must select one manager at least.")
|
}) None else Some("Must select one manager at least.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def validPublicKey: Constraint = new Constraint(){
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] = SshUtil.str2PublicKey(value) match {
|
||||||
|
case Some(_) => None
|
||||||
|
case None => Some("Key is invalid.")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user