#3320 code cleanup

This commit is contained in:
Unknwon 2016-08-07 11:01:47 -07:00
parent 90dd0657b5
commit 99385db0c4
12 changed files with 52 additions and 33 deletions

View file

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.65 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) ##### Current tip version: 0.9.66 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|
@ -45,7 +45,7 @@ The goal of this project is to make the easiest, fastest, and most painless way
- Repository Git hooks/deploy keys - Repository Git hooks/deploy keys
- Repository issues, pull requests and wiki - Repository issues, pull requests and wiki
- Add/Remove repository collaborators - Add/Remove repository collaborators
- Gravatar and custom source - Gravatar and Federated avatar with custom source
- Mail service - Mail service
- Administration panel - Administration panel
- Supports MySQL, PostgreSQL, SQLite3 and [TiDB](https://github.com/pingcap/tidb) (experimental) - Supports MySQL, PostgreSQL, SQLite3 and [TiDB](https://github.com/pingcap/tidb) (experimental)
@ -87,6 +87,7 @@ There are 5 ways to install Gogs:
### Screencasts ### Screencasts
- [How to install Gogs on a Linux Server (DigitalOcean)](https://www.youtube.com/watch?v=deSfX0gqefE)
- [Instalando Gogs no Ubuntu](https://www.youtube.com/watch?v=4UkHAR1F7ZA) (Português) - [Instalando Gogs no Ubuntu](https://www.youtube.com/watch?v=4UkHAR1F7ZA) (Português)
### Deploy to Cloud ### Deploy to Cloud

View file

@ -26,7 +26,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自
- 支持仓库 Git 钩子和部署密钥 - 支持仓库 Git 钩子和部署密钥
- 支持仓库工单Issue、合并请求Pull Request以及 Wiki - 支持仓库工单Issue、合并请求Pull Request以及 Wiki
- 支持添加和删除仓库协作者 - 支持添加和删除仓库协作者
- 支持 Gravatar 以及自定义源 - 支持自定义源的 Gravatar 和 Federated Avatar
- 支持邮件服务 - 支持邮件服务
- 支持后台管理面板 - 支持后台管理面板
- 支持 MySQL、PostgreSQL、SQLite3 和 [TiDB](https://github.com/pingcap/tidb)(实验性支持) 数据库 - 支持 MySQL、PostgreSQL、SQLite3 和 [TiDB](https://github.com/pingcap/tidb)(实验性支持) 数据库

View file

@ -229,9 +229,11 @@ AVATAR_UPLOAD_PATH = data/avatars
; Chinese users can choose "duoshuo" ; Chinese users can choose "duoshuo"
; or a custom avatar source, like: http://cn.gravatar.com/avatar/ ; or a custom avatar source, like: http://cn.gravatar.com/avatar/
GRAVATAR_SOURCE = gravatar GRAVATAR_SOURCE = gravatar
; This value will be forced to be true in offline mode.
DISABLE_GRAVATAR = false DISABLE_GRAVATAR = false
; Federated avatar lookup uses DNS to discover avatar associated ; Federated avatar lookup uses DNS to discover avatar associated
; with emails, see http://www.libravatar.org ; with emails, see http://www.libravatar.org
; This value will be forced to be false in offline mode or Gravatar is disbaled.
ENABLE_FEDERATED_AVATAR = false ENABLE_FEDERATED_AVATAR = false
[attachment] [attachment]

View file

@ -97,6 +97,7 @@ offline_mode_popup = Disable CDN even in production mode, all resource files wil
disable_gravatar = Disable Gravatar Service disable_gravatar = Disable Gravatar Service
disable_gravatar_popup = Disable Gravatar and custom sources, all avatars are uploaded by users or default. disable_gravatar_popup = Disable Gravatar and custom sources, all avatars are uploaded by users or default.
federated_avatar_lookup = Enable Federated Avatars Lookup federated_avatar_lookup = Enable Federated Avatars Lookup
federated_avatar_lookup_popup = Enable federated avatars lookup to use federated open source service based on libravatar.
disable_registration = Disable Self-registration disable_registration = Disable Self-registration
disable_registration_popup = Disable user self-registration, only admin can create accounts. disable_registration_popup = Disable user self-registration, only admin can create accounts.
enable_captcha = Enable Captcha enable_captcha = Enable Captcha

View file

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.65.0806" const APP_VER = "0.9.66.0806"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View file

@ -204,26 +204,23 @@ func HashEmail(email string) string {
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))
} }
// AvatarLink returns avatar link by given email. // AvatarLink returns relative avatar link to the site domain by given email,
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func AvatarLink(email string) (url string) { func AvatarLink(email string) (url string) {
if setting.EnableFederatedAvatar && setting.LibravatarService != nil {
if !setting.OfflineMode { var err error
if setting.EnableFederatedAvatar && setting.LibravatarService != nil { url, err = setting.LibravatarService.FromEmail(email)
var err error if err != nil {
url, err = setting.LibravatarService.FromEmail(email) log.Error(1, "LibravatarService.FromEmail: %v", err)
if err != nil {
log.Error(1, "LibravatarService.FromEmail:: %v", err)
}
}
if len(url) == 0 && !setting.DisableGravatar {
url = setting.GravatarSource + HashEmail(email)
} }
} }
if len(url) == 0 && !setting.DisableGravatar {
url = setting.GravatarSource + HashEmail(email)
}
if len(url) == 0 { if len(url) == 0 {
url = setting.AppSubUrl + "/img/avatar_default.png" url = setting.AppSubUrl + "/img/avatar_default.png"
} }
return url return url
} }

File diff suppressed because one or more lines are too long

View file

@ -20,8 +20,8 @@ import (
_ "github.com/go-macaron/cache/redis" _ "github.com/go-macaron/cache/redis"
"github.com/go-macaron/session" "github.com/go-macaron/session"
_ "github.com/go-macaron/session/redis" _ "github.com/go-macaron/session/redis"
"gopkg.in/ini.v1"
"github.com/strk/go-libravatar" "github.com/strk/go-libravatar"
"gopkg.in/ini.v1"
"github.com/gogits/gogs/modules/bindata" "github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
@ -141,11 +141,11 @@ var (
} }
// Picture settings // Picture settings
AvatarUploadPath string AvatarUploadPath string
GravatarSource string GravatarSource string
DisableGravatar bool DisableGravatar bool
EnableFederatedAvatar bool EnableFederatedAvatar bool
LibravatarService *libravatar.Libravatar LibravatarService *libravatar.Libravatar
// Log settings // Log settings
LogRootPath string LogRootPath string
@ -470,8 +470,11 @@ func NewContext() {
DisableGravatar = true DisableGravatar = true
EnableFederatedAvatar = false EnableFederatedAvatar = false
} }
if DisableGravatar {
EnableFederatedAvatar = false
}
if !DisableGravatar && EnableFederatedAvatar { if EnableFederatedAvatar {
LibravatarService = libravatar.New() LibravatarService = libravatar.New()
parts := strings.Split(GravatarSource, "/") parts := strings.Split(GravatarSource, "/")
if len(parts) >= 3 { if len(parts) >= 3 {

View file

@ -187,9 +187,24 @@ function initInstall() {
} }
}); });
// TODO: better handling of exclusive relations.
$('#offline-mode input').change(function () { $('#offline-mode input').change(function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#disable-gravatar').checkbox('check'); $('#disable-gravatar').checkbox('check');
$('#federated-avatar-lookup').checkbox('uncheck');
}
});
$('#disable-gravatar input').change(function () {
if ($(this).is(':checked')) {
$('#federated-avatar-lookup').checkbox('uncheck');
} else {
$('#offline-mode').checkbox('uncheck');
}
});
$('#federated-avatar-lookup input').change(function () {
if ($(this).is(':checked')) {
$('#disable-gravatar').checkbox('uncheck');
$('#offline-mode').checkbox('uncheck');
} }
}); });
$('#disable-registration input').change(function () { $('#disable-registration input').change(function () {

View file

@ -1 +1 @@
0.9.65.0806 0.9.66.0806

View file

@ -179,7 +179,7 @@
</div> </div>
<div class="inline field"> <div class="inline field">
<div class="ui checkbox" id="federated-avatar-lookup"> <div class="ui checkbox" id="federated-avatar-lookup">
<label class="poping up" data-content="{{.i18n.Tr "install.federated_avatar_lookup"}}"><strong>{{.i18n.Tr "install.federated_avatar_lookup"}}</strong></label> <label class="poping up" data-content="{{.i18n.Tr "install.federated_avatar_lookup_popup"}}"><strong>{{.i18n.Tr "install.federated_avatar_lookup"}}</strong></label>
<input name="enable_federated_avatar" type="checkbox" {{if .enable_federated_avatar}}checked{{end}}> <input name="enable_federated_avatar" type="checkbox" {{if .enable_federated_avatar}}checked{{end}}>
</div> </div>
</div> </div>

View file

@ -14,7 +14,7 @@
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
{{if not DisableGravatar}} {{if not DisableGravatar}}
<div class="inline field"> <div class="inline field">
<div class="ui radio"> <div class="ui radio checkbox">
<input name="source" value="lookup" type="radio" {{if not .SignedUser.UseCustomAvatar}}checked{{end}}> <input name="source" value="lookup" type="radio" {{if not .SignedUser.UseCustomAvatar}}checked{{end}}>
<label>{{.i18n.Tr "settings.lookup_avatar_by_mail"}}</label> <label>{{.i18n.Tr "settings.lookup_avatar_by_mail"}}</label>
</div> </div>
@ -26,7 +26,7 @@
{{end}} {{end}}
<div class="inline field"> <div class="inline field">
<div class="ui radio"> <div class="ui radio checkbox">
<input name="source" value="local" type="radio" {{if .SignedUser.UseCustomAvatar}}checked{{end}}> <input name="source" value="local" type="radio" {{if .SignedUser.UseCustomAvatar}}checked{{end}}>
<label>{{.i18n.Tr "settings.enable_custom_avatar"}}</label> <label>{{.i18n.Tr "settings.enable_custom_avatar"}}</label>
</div> </div>