Merge branch 'master' of https://github.com/gogits/gogs
commit
78097a2c5a
@ -0,0 +1,7 @@ |
|||||||
|
filesets: |
||||||
|
includes: |
||||||
|
- templates |
||||||
|
- public |
||||||
|
- conf |
||||||
|
- LICENSE |
||||||
|
- README.md |
@ -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