mirror of https://github.com/gogits/gogs.git
FuXiaoHei
11 years ago
41 changed files with 867 additions and 193 deletions
@ -0,0 +1,7 @@ |
|||||||
|
filesets: |
||||||
|
includes: |
||||||
|
- templates |
||||||
|
- public |
||||||
|
- conf |
||||||
|
- LICENSE |
||||||
|
- README.md |
@ -1,28 +1,103 @@ |
|||||||
# App name that shows on every page title |
; App name that shows on every page title |
||||||
APP_NAME = Gogs: Go Git Service |
APP_NAME = Gogs: Go Git Service |
||||||
# !!MUST CHANGE TO YOUR USER NAME!! |
APP_LOGO = img/favicon.png |
||||||
|
; !!MUST CHANGE TO YOUR USER NAME!! |
||||||
RUN_USER = lunny |
RUN_USER = lunny |
||||||
|
; Either "dev", "prod" or "test", default is "dev" |
||||||
|
RUN_MODE = dev |
||||||
|
|
||||||
[repository] |
[repository] |
||||||
ROOT = /Users/%(RUN_USER)s/git/gogs-repositories |
ROOT = /Users/%(RUN_USER)s/git/gogs-repositories |
||||||
LANG_IGNS=Google Go|C|Python|Ruby|C Sharp |
LANG_IGNS = Google Go|C|Python|Ruby|C Sharp |
||||||
LICENSES=Apache v2 License|GPL v2|MIT License|Affero GPL|BSD (3-Clause) License |
LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|BSD (3-Clause) License |
||||||
|
|
||||||
[server] |
[server] |
||||||
DOMAIN = gogits.org |
DOMAIN = localhost |
||||||
|
ROOT_URL = http://%(DOMAIN)s:%(HTTP_PORT)s/ |
||||||
HTTP_ADDR = |
HTTP_ADDR = |
||||||
HTTP_PORT = 3000 |
HTTP_PORT = 3000 |
||||||
|
|
||||||
[database] |
[database] |
||||||
# Either "mysql" or "postgres", it's your choice |
; Either "mysql" or "postgres", it's your choice |
||||||
DB_TYPE = mysql |
DB_TYPE = mysql |
||||||
HOST = |
HOST = |
||||||
NAME = gogs |
NAME = gogs |
||||||
USER = root |
USER = root |
||||||
PASSWD = |
PASSWD = |
||||||
# For "postgres" only, either "disable" or "verify-full" |
; For "postgres" only, either "disable", "require" or "verify-full" |
||||||
SSL_MODE = disable |
SSL_MODE = disable |
||||||
|
|
||||||
[security] |
[security] |
||||||
# !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! |
; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! |
||||||
USER_PASSWD_SALT = !#@FDEWREWR&*( |
SECRET_KEY = !#@FDEWREWR&*( |
||||||
|
|
||||||
|
[service] |
||||||
|
ACTIVE_CODE_LIVE_MINUTES = 180 |
||||||
|
RESET_PASSWD_CODE_LIVE_MINUTES = 180 |
||||||
|
; User need to confirm e-mail for registration |
||||||
|
REGISTER_EMAIL_CONFIRM = false |
||||||
|
|
||||||
|
[mailer] |
||||||
|
ENABLED = false |
||||||
|
; Name displayed in mail title |
||||||
|
SUBJECT = %(APP_NAME)s |
||||||
|
; Mail server |
||||||
|
; Gmail: smtp.gmail.com:587 |
||||||
|
HOST = |
||||||
|
; Mail from address |
||||||
|
FROM = |
||||||
|
; Mailer user name and password |
||||||
|
USER = |
||||||
|
PASSWD = |
||||||
|
|
||||||
|
[log] |
||||||
|
; Either "console", "file", "conn" or "smtp", default is "console" |
||||||
|
MODE = console |
||||||
|
; Buffer length of channel, keep it as it is if you don't know what it is. |
||||||
|
BUFFER_LEN = 10000 |
||||||
|
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace" |
||||||
|
LEVEL = Trace |
||||||
|
|
||||||
|
; For "console" mode only |
||||||
|
[log.console] |
||||||
|
LEVEL = |
||||||
|
|
||||||
|
; For "file" mode only |
||||||
|
[log.file] |
||||||
|
LEVEL = |
||||||
|
FILE_NAME = log/gogs.log |
||||||
|
; This enables automated log rotate(switch of following options), default is true |
||||||
|
LOG_ROTATE = true |
||||||
|
; Max line number of single file, default is 1000000 |
||||||
|
MAX_LINES = 1000000 |
||||||
|
; Max size shift of single file, default is 28 means 1 << 28, 256MB |
||||||
|
MAX_SIZE_SHIFT = 28 |
||||||
|
; Segment log daily, default is true |
||||||
|
DAILY_ROTATE = true |
||||||
|
; Expired days of log file(delete after max days), default is 7 |
||||||
|
MAX_DAYS = 7 |
||||||
|
|
||||||
|
; For "conn" mode only |
||||||
|
[log.conn] |
||||||
|
LEVEL = |
||||||
|
; Reconnect host for every single message, default is false |
||||||
|
RECONNECT_ON_MSG = false |
||||||
|
; Try to reconnect when connection is lost, default is false |
||||||
|
RECONNECT = false |
||||||
|
; Either "tcp", "unix" or "udp", default is "tcp" |
||||||
|
PROTOCOL = tcp |
||||||
|
; Host address |
||||||
|
ADDR = |
||||||
|
|
||||||
|
; For "smtp" mode only |
||||||
|
[log.smtp] |
||||||
|
LEVEL = |
||||||
|
; Name displayed in mail title, default is "Diagnostic message from serve" |
||||||
|
SUBJECT = Diagnostic message from serve |
||||||
|
; Mail server |
||||||
|
HOST = |
||||||
|
; Mailer user name and password |
||||||
|
USER = |
||||||
|
PASSWD = |
||||||
|
; Receivers, can be one or more, e.g. ["1@example.com","2@example.com"] |
||||||
|
RECEIVERS = |
@ -0,0 +1,41 @@ |
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package auth |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/hex" |
||||||
|
"fmt" |
||||||
|
|
||||||
|
"github.com/gogits/gogs/models" |
||||||
|
"github.com/gogits/gogs/modules/base" |
||||||
|
"github.com/gogits/gogs/modules/mailer" |
||||||
|
) |
||||||
|
|
||||||
|
// create a time limit code for user active
|
||||||
|
func CreateUserActiveCode(user *models.User, startInf interface{}) string { |
||||||
|
hours := base.Service.ActiveCodeLives / 60 |
||||||
|
data := base.ToStr(user.Id) + user.Email + user.LowerName + user.Passwd + user.Rands |
||||||
|
code := base.CreateTimeLimitCode(data, hours, startInf) |
||||||
|
|
||||||
|
// add tail hex username
|
||||||
|
code += hex.EncodeToString([]byte(user.LowerName)) |
||||||
|
return code |
||||||
|
} |
||||||
|
|
||||||
|
// Send user register mail with active code
|
||||||
|
func SendRegisterMail(user *models.User) { |
||||||
|
code := CreateUserActiveCode(user, nil) |
||||||
|
subject := "Register success, Welcome" |
||||||
|
|
||||||
|
data := mailer.GetMailTmplData(user) |
||||||
|
data["Code"] = code |
||||||
|
body := base.RenderTemplate("mail/auth/register_success.html", data) |
||||||
|
|
||||||
|
msg := mailer.NewMailMessage([]string{user.Email}, subject, body) |
||||||
|
msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id) |
||||||
|
|
||||||
|
// async send mail
|
||||||
|
mailer.SendAsync(msg) |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package mailer |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/gogits/gogs/models" |
||||||
|
"github.com/gogits/gogs/modules/base" |
||||||
|
) |
||||||
|
|
||||||
|
// Create New mail message use MailFrom and MailUser
|
||||||
|
func NewMailMessage(To []string, subject, body string) Message { |
||||||
|
msg := NewHtmlMessage(To, base.MailService.User, subject, body) |
||||||
|
msg.User = base.MailService.User |
||||||
|
return msg |
||||||
|
} |
||||||
|
|
||||||
|
func GetMailTmplData(user *models.User) map[interface{}]interface{} { |
||||||
|
data := make(map[interface{}]interface{}, 10) |
||||||
|
data["AppName"] = base.AppName |
||||||
|
data["AppVer"] = base.AppVer |
||||||
|
data["AppUrl"] = base.AppUrl |
||||||
|
data["AppLogo"] = base.AppLogo |
||||||
|
data["ActiveCodeLives"] = base.Service.ActiveCodeLives |
||||||
|
data["ResetPwdCodeLives"] = base.Service.ResetPwdCodeLives |
||||||
|
if user != nil { |
||||||
|
data["User"] = user |
||||||
|
} |
||||||
|
return data |
||||||
|
} |
@ -0,0 +1,112 @@ |
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package mailer |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"net/smtp" |
||||||
|
"strings" |
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/base" |
||||||
|
"github.com/gogits/gogs/modules/log" |
||||||
|
) |
||||||
|
|
||||||
|
type Message struct { |
||||||
|
To []string |
||||||
|
From string |
||||||
|
Subject string |
||||||
|
Body string |
||||||
|
User string |
||||||
|
Type string |
||||||
|
Massive bool |
||||||
|
Info string |
||||||
|
} |
||||||
|
|
||||||
|
// create mail content
|
||||||
|
func (m Message) Content() string { |
||||||
|
// set mail type
|
||||||
|
contentType := "text/plain; charset=UTF-8" |
||||||
|
if m.Type == "html" { |
||||||
|
contentType = "text/html; charset=UTF-8" |
||||||
|
} |
||||||
|
|
||||||
|
// create mail content
|
||||||
|
content := "From: " + m.User + "<" + m.From + |
||||||
|
">\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body |
||||||
|
return content |
||||||
|
} |
||||||
|
|
||||||
|
// Direct Send mail message
|
||||||
|
func Send(msg Message) (int, error) { |
||||||
|
log.Trace("Sending mails to: %s", strings.Join(msg.To, "; ")) |
||||||
|
host := strings.Split(base.MailService.Host, ":") |
||||||
|
|
||||||
|
// get message body
|
||||||
|
content := msg.Content() |
||||||
|
|
||||||
|
auth := smtp.PlainAuth("", base.MailService.User, base.MailService.Passwd, host[0]) |
||||||
|
|
||||||
|
if len(msg.To) == 0 { |
||||||
|
return 0, fmt.Errorf("empty receive emails") |
||||||
|
} |
||||||
|
|
||||||
|
if len(msg.Body) == 0 { |
||||||
|
return 0, fmt.Errorf("empty email body") |
||||||
|
} |
||||||
|
|
||||||
|
if msg.Massive { |
||||||
|
// send mail to multiple emails one by one
|
||||||
|
num := 0 |
||||||
|
for _, to := range msg.To { |
||||||
|
body := []byte("To: " + to + "\r\n" + content) |
||||||
|
err := smtp.SendMail(base.MailService.Host, auth, msg.From, []string{to}, body) |
||||||
|
if err != nil { |
||||||
|
return num, err |
||||||
|
} |
||||||
|
num++ |
||||||
|
} |
||||||
|
return num, nil |
||||||
|
} else { |
||||||
|
body := []byte("To: " + strings.Join(msg.To, ";") + "\r\n" + content) |
||||||
|
|
||||||
|
// send to multiple emails in one message
|
||||||
|
err := smtp.SendMail(base.MailService.Host, auth, msg.From, msg.To, body) |
||||||
|
if err != nil { |
||||||
|
return 0, err |
||||||
|
} else { |
||||||
|
return 1, nil |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Async Send mail message
|
||||||
|
func SendAsync(msg Message) { |
||||||
|
// TODO may be need pools limit concurrent nums
|
||||||
|
go func() { |
||||||
|
num, err := Send(msg) |
||||||
|
tos := strings.Join(msg.To, "; ") |
||||||
|
info := "" |
||||||
|
if err != nil { |
||||||
|
if len(msg.Info) > 0 { |
||||||
|
info = ", info: " + msg.Info |
||||||
|
} |
||||||
|
// log failed
|
||||||
|
log.Error(fmt.Sprintf("Async sent email %d succeed, not send emails: %s%s err: %s", num, tos, info, err)) |
||||||
|
return |
||||||
|
} |
||||||
|
log.Trace(fmt.Sprintf("Async sent email %d succeed, sent emails: %s%s", num, tos, info)) |
||||||
|
}() |
||||||
|
} |
||||||
|
|
||||||
|
// Create html mail message
|
||||||
|
func NewHtmlMessage(To []string, From, Subject, Body string) Message { |
||||||
|
return Message{ |
||||||
|
To: To, |
||||||
|
From: From, |
||||||
|
Subject: Subject, |
||||||
|
Body: Body, |
||||||
|
Type: "html", |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package middleware |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"log" |
||||||
|
"net/http" |
||||||
|
"runtime" |
||||||
|
"time" |
||||||
|
|
||||||
|
"github.com/codegangsta/martini" |
||||||
|
) |
||||||
|
|
||||||
|
var isWindows bool |
||||||
|
|
||||||
|
func init() { |
||||||
|
isWindows = runtime.GOOS == "windows" |
||||||
|
} |
||||||
|
|
||||||
|
func Logger() martini.Handler { |
||||||
|
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) { |
||||||
|
start := time.Now() |
||||||
|
log.Printf("Started %s %s", req.Method, req.URL.Path) |
||||||
|
|
||||||
|
rw := res.(martini.ResponseWriter) |
||||||
|
ctx.Next() |
||||||
|
|
||||||
|
content := fmt.Sprintf("Completed %v %s in %v", rw.Status(), http.StatusText(rw.Status()), time.Since(start)) |
||||||
|
if !isWindows { |
||||||
|
switch rw.Status() { |
||||||
|
case 200: |
||||||
|
content = fmt.Sprintf("\033[1;32m%s\033[0m", content) |
||||||
|
case 304: |
||||||
|
content = fmt.Sprintf("\033[1;33m%s\033[0m", content) |
||||||
|
case 404: |
||||||
|
content = fmt.Sprintf("\033[1;31m%s\033[0m", content) |
||||||
|
case 500: |
||||||
|
content = fmt.Sprintf("\033[1;36m%s\033[0m", content) |
||||||
|
} |
||||||
|
} |
||||||
|
log.Println(content) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
{{template "base/head" .}} |
||||||
|
{{template "base/navbar" .}} |
||||||
|
<div id="gogs-body-nav"> |
||||||
|
<div class="container"> |
||||||
|
<h3>Help</h3> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div id="gogs-body" class="container" data-page="user"> |
||||||
|
{{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}} |
||||||
|
</div> |
||||||
|
{{template "base/footer" .}} |
@ -1,6 +1,6 @@ |
|||||||
{{template "base/head" .}} |
{{template "base/head" .}} |
||||||
{{template "base/navbar" .}} |
{{template "base/navbar" .}} |
||||||
<div id="gogs-body" class="container"> |
<div id="gogs-body" class="container"> |
||||||
Website is still in the progress of building...please come back later! |
Welcome to the land of Gogs! There will be some indroduction! |
||||||
</div> |
</div> |
||||||
{{template "base/footer" .}} |
{{template "base/footer" .}} |
@ -0,0 +1,9 @@ |
|||||||
|
{{template "base/head" .}} |
||||||
|
{{template "base/navbar" .}} |
||||||
|
{{template "repo/nav" .}} |
||||||
|
{{template "repo/toolbar" .}} |
||||||
|
<div id="gogs-body" class="container"> |
||||||
|
<div id="gogs-source"> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{{template "base/footer" .}} |
@ -0,0 +1,9 @@ |
|||||||
|
{{template "base/head" .}} |
||||||
|
{{template "base/navbar" .}} |
||||||
|
{{template "repo/nav" .}} |
||||||
|
{{template "repo/toolbar" .}} |
||||||
|
<div id="gogs-body" class="container"> |
||||||
|
<div id="gogs-source"> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
{{template "base/footer" .}} |
@ -0,0 +1,17 @@ |
|||||||
|
{{template "base/head" .}} |
||||||
|
{{template "base/navbar" .}} |
||||||
|
<div id="gogs-body-nav"> |
||||||
|
<div class="container"> |
||||||
|
<ul class="nav nav-pills pull-right"> |
||||||
|
<li><a href="/">Feed</a></li> |
||||||
|
<li class="active"><a href="/issues">Issues</a></li> |
||||||
|
<li><a href="/pulls">Pull Requests</a></li> |
||||||
|
<li><a href="/stars">Stars</a></li> |
||||||
|
</ul> |
||||||
|
<h3>Issues</h3> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div id="gogs-body" class="container" data-page="user"> |
||||||
|
{{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}} |
||||||
|
</div> |
||||||
|
{{template "base/footer" .}} |
@ -0,0 +1,17 @@ |
|||||||
|
{{template "base/head" .}} |
||||||
|
{{template "base/navbar" .}} |
||||||
|
<div id="gogs-body-nav"> |
||||||
|
<div class="container"> |
||||||
|
<ul class="nav nav-pills pull-right"> |
||||||
|
<li><a href="/">Feed</a></li> |
||||||
|
<li><a href="/issues">Issues</a></li> |
||||||
|
<li class="active"><a href="/pulls">Pull Requests</a></li> |
||||||
|
<li><a href="/stars">Stars</a></li> |
||||||
|
</ul> |
||||||
|
<h3>Pull Requests</h3> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div id="gogs-body" class="container" data-page="user"> |
||||||
|
{{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}} |
||||||
|
</div> |
||||||
|
{{template "base/footer" .}} |
@ -0,0 +1,11 @@ |
|||||||
|
<div id="gogs-user-setting-nav" class="col-md-3"> |
||||||
|
<h4>Account Setting</h4> |
||||||
|
<ul class="list-group"> |
||||||
|
<li class="list-group-item{{if .IsUserPageSetting}} list-group-item-success{{end}}"><a href="/user/setting">Account Profile</a></li> |
||||||
|
<li class="list-group-item{{if .IsUserPageSettingPasswd}} list-group-item-success{{end}}"><a href="/user/setting/password">Password</a></li> |
||||||
|
<li class="list-group-item{{if .IsUserPageSettingNotify}} list-group-item-success{{end}}"><a href="/user/setting/notification">Notifications</a></li> |
||||||
|
<li class="list-group-item{{if .IsUserPageSettingSSH}} list-group-item-success{{end}}"><a href="/user/setting/ssh/">SSH Keys</a></li> |
||||||
|
<li class="list-group-item{{if .IsUserPageSettingSecurity}} list-group-item-success{{end}}"><a href="/user/setting/security">Security</a></li> |
||||||
|
<li class="list-group-item{{if .IsUserPageSettingDelete}} list-group-item-success{{end}}"><a href="/user/delete">Delete Account</a></li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,17 @@ |
|||||||
|
{{template "base/head" .}} |
||||||
|
{{template "base/navbar" .}} |
||||||
|
<div id="gogs-body-nav"> |
||||||
|
<div class="container"> |
||||||
|
<ul class="nav nav-pills pull-right"> |
||||||
|
<li><a href="/">Feed</a></li> |
||||||
|
<li><a href="/issues">Issues</a></li> |
||||||
|
<li><a href="/pulls">Pull Requests</a></li> |
||||||
|
<li class="active"><a href="/stars">Stars</a></li> |
||||||
|
</ul> |
||||||
|
<h3>Stars</h3> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div id="gogs-body" class="container" data-page="user"> |
||||||
|
{{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}} |
||||||
|
</div> |
||||||
|
{{template "base/footer" .}} |
Loading…
Reference in new issue