mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 19:45:57 +01:00
Merge branch 'master' of https://github.com/takezoe/gitbucket.git
This commit is contained in:
@@ -70,7 +70,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map { account =>
|
||||
updateAccount(account.copy(
|
||||
password = form.password.map(encrypt).getOrElse(account.password),
|
||||
password = form.password.map(sha1).getOrElse(account.password),
|
||||
mailAddress = form.mailAddress,
|
||||
url = form.url))
|
||||
|
||||
@@ -93,7 +93,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
|
||||
|
||||
post("/register", newForm){ form =>
|
||||
if(loadSystemSettings().allowAccountRegistration){
|
||||
createAccount(form.userName, encrypt(form.password), form.mailAddress, false, form.url)
|
||||
createAccount(form.userName, sha1(form.password), form.mailAddress, false, form.url)
|
||||
updateImage(form.userName, form.fileId, false)
|
||||
redirect("/signin")
|
||||
} else NotFound
|
||||
|
||||
@@ -95,7 +95,23 @@ abstract class ControllerBase extends ScalatraFilter
|
||||
/**
|
||||
* Context object for the current request.
|
||||
*/
|
||||
case class Context(path: String, loginAccount: Option[Account], currentUrl: String, request: HttpServletRequest)
|
||||
case class Context(path: String, loginAccount: Option[Account], currentUrl: String, request: HttpServletRequest){
|
||||
|
||||
/**
|
||||
* Get object from cache.
|
||||
*
|
||||
* If object has not been cached with the specified key then retrieves by given action.
|
||||
* Cached object are available during a request.
|
||||
*/
|
||||
def cache[A](key: String)(action: => A): A = {
|
||||
Option(request.getAttribute("cache." + key).asInstanceOf[A]).getOrElse {
|
||||
val newObject = action
|
||||
request.setAttribute("cache." + key, newObject)
|
||||
newObject
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Base trait for controllers which manages account information.
|
||||
|
||||
@@ -213,11 +213,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
if(repository.commitCount == 0){
|
||||
repo.html.guide(repository)
|
||||
} else {
|
||||
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
|
||||
|
||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||
// get latest commit
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
||||
// get specified commit
|
||||
val (revCommit, revision) = try {
|
||||
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
|
||||
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
|
||||
} catch {
|
||||
case e: NullPointerException => {
|
||||
val revision = repository.branchList.head
|
||||
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
|
||||
}
|
||||
}
|
||||
// get files
|
||||
val files = JGitUtil.getFileList(git, revision, path)
|
||||
// process README.md
|
||||
@@ -225,20 +231,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8")
|
||||
}
|
||||
|
||||
repo.html.files(
|
||||
// current branch
|
||||
revision,
|
||||
// repository
|
||||
repository,
|
||||
// current path
|
||||
if(path == ".") Nil else path.split("/").toList,
|
||||
// latest commit
|
||||
new JGitUtil.CommitInfo(revCommit),
|
||||
// file list
|
||||
files,
|
||||
// readme
|
||||
readme
|
||||
)
|
||||
repo.html.files(revision, repository,
|
||||
if(path == ".") Nil else path.split("/").toList, // current path
|
||||
new JGitUtil.CommitInfo(revCommit), // latest commit
|
||||
files, readme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ trait SignInControllerBase extends ControllerBase { self: SystemSettingsService
|
||||
|
||||
post("/signin", form){ form =>
|
||||
val account = getAccountByUserName(form.userName)
|
||||
if(account.isEmpty || account.get.password != encrypt(form.password)){
|
||||
if(account.isEmpty || account.get.password != sha1(form.password)){
|
||||
redirect("/signin")
|
||||
} else {
|
||||
session.setAttribute("LOGIN_ACCOUNT", account.get)
|
||||
|
||||
@@ -47,7 +47,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
||||
})
|
||||
|
||||
post("/admin/users/_new", newForm)(adminOnly { form =>
|
||||
createAccount(form.userName, encrypt(form.password), form.mailAddress, form.isAdmin, form.url)
|
||||
createAccount(form.userName, sha1(form.password), form.mailAddress, form.isAdmin, form.url)
|
||||
updateImage(form.userName, form.fileId, false)
|
||||
redirect("/admin/users")
|
||||
})
|
||||
@@ -61,7 +61,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map { account =>
|
||||
updateAccount(getAccountByUserName(userName).get.copy(
|
||||
password = form.password.map(encrypt).getOrElse(account.password),
|
||||
password = form.password.map(sha1).getOrElse(account.password),
|
||||
mailAddress = form.mailAddress,
|
||||
isAdmin = form.isAdmin,
|
||||
url = form.url))
|
||||
|
||||
@@ -59,7 +59,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
|
||||
|
||||
private def isWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo): Boolean = {
|
||||
getAccountByUserName(username).map { account =>
|
||||
account.password == encrypt(password) && hasWritePermission(repository.owner, repository.name, Some(account))
|
||||
account.password == sha1(password) && hasWritePermission(repository.owner, repository.name, Some(account))
|
||||
} getOrElse false
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import scala.slick.driver.H2Driver.simple._
|
||||
* Provides some usable implicit conversions.
|
||||
*/
|
||||
object Implicits {
|
||||
|
||||
implicit def extendsSeq[A](seq: Seq[A]) = new {
|
||||
|
||||
implicit class RichSeq[A](seq: Seq[A]) {
|
||||
|
||||
def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition)
|
||||
|
||||
@@ -26,7 +26,7 @@ object Implicits {
|
||||
}
|
||||
|
||||
// TODO Should this implicit conversion move to model.Functions?
|
||||
implicit def extendsColumn(c1: Column[Boolean]) = new {
|
||||
implicit class RichColumn(c1: Column[Boolean]){
|
||||
def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package util
|
||||
|
||||
object StringUtil {
|
||||
|
||||
def encrypt(value: String): String = {
|
||||
def sha1(value: String): String = {
|
||||
val md = java.security.MessageDigest.getInstance("SHA-1")
|
||||
md.update(value.getBytes)
|
||||
md.digest.map(b => "%02x".format(b)).mkString
|
||||
|
||||
@@ -75,16 +75,14 @@ object helpers {
|
||||
// convert commit id to link
|
||||
.replaceAll("(^|\\W)([a-f0-9]{40})(\\W|$)", "$1<a href=\"%s/%s/%s/commit/$2\">$2</a>$3").format(context.path, repository.owner, repository.name))
|
||||
|
||||
|
||||
/**
|
||||
* Returns <img> which displays the avatar icon.
|
||||
* Looks up Gravatar if avatar icon has not been configured in user settings.
|
||||
*/
|
||||
def avatar(userName: String, size: Int, tooltip: Boolean = false)(implicit context: app.Context): Html = {
|
||||
val account = Option(context.request.getAttribute("cache.account." + userName).asInstanceOf[model.Account]).orElse {
|
||||
new AccountService {}.getAccountByUserName(userName).map { account =>
|
||||
context.request.setAttribute("cache.account." + userName, account)
|
||||
account
|
||||
}
|
||||
val account = context.cache(s"account.${userName}"){
|
||||
new AccountService {}.getAccountByUserName(userName)
|
||||
}
|
||||
val src = account.collect { case account if(account.image.isEmpty) =>
|
||||
s"""http://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress)}?s=${size}"""
|
||||
@@ -92,16 +90,16 @@ object helpers {
|
||||
s"""${context.path}/${userName}/_avatar"""
|
||||
}
|
||||
if(tooltip){
|
||||
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}:px" data-toggle="tooltip" title=${userName}/>""")
|
||||
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}px;" data-toggle="tooltip" title=${userName}/>""")
|
||||
} else {
|
||||
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}:px" />""")
|
||||
Html(s"""<img src=${src} class="avatar" style="width: ${size}px; height: ${size}px;" />""")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implicit conversion to add mkHtml() to Seq[Html].
|
||||
*/
|
||||
implicit def extendsHtmlSeq(seq: Seq[Html]) = new {
|
||||
implicit class RichHtmlSeq(seq: Seq[Html]) {
|
||||
def mkHtml(separator: String) = Html(seq.mkString(separator))
|
||||
def mkHtml(separator: scala.xml.Elem) = Html(seq.mkString(separator.toString))
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
<form action="@url(repository)/issues/new" method="POST" validate="true">
|
||||
<div class="row-fluid">
|
||||
<div class="span9">
|
||||
<div class="box">
|
||||
<div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div>
|
||||
<div class="box issue-box">
|
||||
<div class="box-content">
|
||||
<span id="error-title" class="error"></span>
|
||||
<input type="text" name="title" value="" placeholder="Title" style="width: 650px;"/>
|
||||
<input type="text" name="title" value="" placeholder="Title" style="width: 600px;"/>
|
||||
<div>
|
||||
<span id="label-assigned">No one is assigned</span>
|
||||
@if(hasWritePermission){
|
||||
@@ -42,10 +43,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
@helper.html.preview(repository, "", false, true, true, "width: 650px; height: 200px;")
|
||||
@helper.html.preview(repository, "", false, true, true, "width: 600px; height: 200px;")
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success" value="Submit new issue"/>
|
||||
<div class="pull-right">
|
||||
<input type="submit" class="btn btn-success" value="Submit new issue"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span3">
|
||||
@if(hasWritePermission){
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@(content: String, commentId: Int, owner: String, repository: String)(implicit context: app.Context)
|
||||
@import context._
|
||||
<span id="error-edit-content-@commentId" class="error"></span>
|
||||
<textarea style="width: 730px; height: 100px;" id="edit-content-@commentId">@content</textarea>
|
||||
<textarea style="width: 680px; height: 100px;" id="edit-content-@commentId">@content</textarea>
|
||||
<input type="button" class="btn btn-small" value="Update Comment"/>
|
||||
<span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span>
|
||||
<script>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
@(title: String, content: Option[String], issueId: Int, owner: String, repository: String)(implicit context: app.Context)
|
||||
@import context._
|
||||
<span id="error-edit-title" class="error"></span>
|
||||
<input type="text" style="width: 730px;" id="edit-title" value="@title"/>
|
||||
<textarea style="width: 730px; height: 100px;" id="edit-content">@content.getOrElse("")</textarea>
|
||||
<input type="text" style="width: 680px;" id="edit-title" value="@title"/>
|
||||
<textarea style="width: 680px; height: 100px;" id="edit-content">@content.getOrElse("")</textarea>
|
||||
<input type="button" class="btn btn-small" value="Update Issue"/>
|
||||
<span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span>
|
||||
<script>
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
</ul>
|
||||
<div class="row-fluid">
|
||||
<div class="span10">
|
||||
<div class="box">
|
||||
<div class="issue-avatar-image">@avatar(issue.openedUserName, 48)</div>
|
||||
<div class="box issue-box">
|
||||
<div class="box-content" style="padding: 0px;">
|
||||
<div class="issue-header">
|
||||
@if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){
|
||||
@@ -68,6 +69,7 @@
|
||||
</div>
|
||||
</div>
|
||||
@comments.map { comment =>
|
||||
<div class="issue-avatar-image">@avatar(comment.commentedUserName, 48)</div>
|
||||
<div class="box issue-comment-box" id="comment-@comment.commentId">
|
||||
<div class="box-header-small">
|
||||
<i class="icon-comment"></i>
|
||||
@@ -97,16 +99,19 @@
|
||||
}
|
||||
@if(loginAccount.isDefined){
|
||||
<form action="@url(repository)/issue_comments/new" method="POST" validate="true">
|
||||
<div class="box">
|
||||
<div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div>
|
||||
<div class="box issue-comment-box">
|
||||
<div class="box-content">
|
||||
@helper.html.preview(repository, "", false, true, true, "width: 730px; height: 100px;")
|
||||
@helper.html.preview(repository, "", false, true, true, "width: 680px; height: 100px;")
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="issueId" value="@issue.issueId"/>
|
||||
<input type="submit" class="btn btn-success" value="Comment"/>
|
||||
@if(hasWritePermission || issue.openedUserName == loginAccount.get.userName){
|
||||
<input type="submit" class="btn" value="@{if(issue.closed) "Reopen" else "Close"}" id="action"/>
|
||||
}
|
||||
<div class="pull-right">
|
||||
<input type="hidden" name="issueId" value="@issue.issueId"/>
|
||||
<input type="submit" class="btn btn-success" value="Comment"/>
|
||||
@if(hasWritePermission || issue.openedUserName == loginAccount.get.userName){
|
||||
<input type="submit" class="btn" value="@{if(issue.closed) "Reopen" else "Close"}" id="action"/>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
@(id: String, repository: service.RepositoryService.RepositoryInfo, active: String)(implicit context: app.Context)
|
||||
@(id: String, repository: service.RepositoryService.RepositoryInfo, active: String,
|
||||
hideBranchPulldown: Boolean = false)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
<ul class="nav nav-tabs">
|
||||
@if(!hideBranchPulldown){
|
||||
<li>
|
||||
<div class="btn-group" style="margin-right: 20px;">
|
||||
<button class="btn dropdown-toggle" data-toggle="dropdown">
|
||||
@if(id.length == 40){
|
||||
tree: <strong>@id.substring(0, 10)</strong>
|
||||
} else {
|
||||
}
|
||||
@if(repository.branchList.contains(id)){
|
||||
branch: <strong>@id</strong>
|
||||
}
|
||||
@if(repository.tags.exists(_.name == id)){
|
||||
tag: <strong>@id</strong>
|
||||
}
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
@@ -19,6 +25,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
<li@if(active=="files"){ class="active"}><a href="@url(repository)/tree/@id">Files</a></li>
|
||||
<li@if(active=="commits"){ class="active"}><a href="@url(repository)/commits/@id">Commits</a></li>
|
||||
<li@if(active=="tags"){ class="active"}><a href="@url(repository)/tags">Tags@if(repository.tags.length > 0){ <span class="badge">@repository.tags.length</span>}</a></li>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@import view.helpers._
|
||||
@html.main(repository.owner + "/" + repository.name) {
|
||||
@html.header("code", repository)
|
||||
@tab("master", repository, "tags") @* TODO DON'T display branch pulldown *@
|
||||
@tab(repository.repository.defaultBranch, repository, "tags", true)
|
||||
<h1>Tags</h1>
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<!-- Session configuration -->
|
||||
<!-- ===================================================================== -->
|
||||
<listener>
|
||||
<listener-class>servlet.SessionCleanipListener</listener-class>
|
||||
<listener-class>servlet.SessionCleanupListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- ===================================================================== -->
|
||||
|
||||
@@ -502,9 +502,18 @@ h4#issueTitle {
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
div.issue-avatar-image {
|
||||
float: left;
|
||||
}
|
||||
|
||||
div.issue-box {
|
||||
margin-bottom: 15px;
|
||||
margin-left: 50px;
|
||||
}
|
||||
|
||||
div.issue-comment-box {
|
||||
margin-bottom: 15px;
|
||||
margin-top: 25px;
|
||||
margin-left: 50px;
|
||||
}
|
||||
|
||||
div.issue-comment-action {
|
||||
|
||||
Reference in New Issue
Block a user