aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/base/template.go4
-rw-r--r--modules/base/tool.go10
-rw-r--r--modules/mailer/mail.go22
-rw-r--r--modules/oauth2/oauth2.go61
4 files changed, 65 insertions, 32 deletions
diff --git a/modules/base/template.go b/modules/base/template.go
index dfcae931..56b77a5d 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -67,6 +67,10 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"DateFormat": DateFormat,
"List": List,
"Mail2Domain": func(mail string) string {
+ if !strings.Contains(mail, "@") {
+ return "try.gogits.org"
+ }
+
suffix := strings.SplitN(mail, "@", 2)[1]
domain, ok := mailDomains[suffix]
if !ok {
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 6876da76..3946c4b5 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -494,6 +494,8 @@ func ActionIcon(opType int) string {
return "arrow-circle-o-right"
case 6: // Create issue.
return "exclamation-circle"
+ case 8: // Transfer repository.
+ return "share"
default:
return "invalid type"
}
@@ -503,8 +505,9 @@ const (
TPL_CREATE_REPO = `<a href="/user/%s">%s</a> created repository <a href="/%s">%s</a>`
TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>%s`
TPL_COMMIT_REPO_LI = `<div><img src="%s?s=16" alt="user-avatar"/> <a href="/%s/commit/%s">%s</a> %s</div>`
- TPL_CREATE_Issue = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a>
+ TPL_CREATE_ISSUE = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a>
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
+ TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>`
)
type PushCommit struct {
@@ -547,8 +550,11 @@ func ActionDesc(act Actioner) string {
buf.String())
case 6: // Create issue.
infos := strings.SplitN(content, "|", 2)
- return fmt.Sprintf(TPL_CREATE_Issue, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
+ return fmt.Sprintf(TPL_CREATE_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
AvatarLink(email), infos[1])
+ case 8: // Transfer repository.
+ newRepoLink := content + "/" + repoName
+ return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
default:
return "invalid type"
}
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go
index b99fc8fd..eee6b916 100644
--- a/modules/mailer/mail.go
+++ b/modules/mailer/mail.go
@@ -86,7 +86,27 @@ func SendActiveMail(r *middleware.Render, user *models.User) {
}
msg := NewMailMessage([]string{user.Email}, subject, body)
- msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id)
+ msg.Info = fmt.Sprintf("UID: %d, send active mail", user.Id)
+
+ SendAsync(&msg)
+}
+
+// Send reset password email.
+func SendResetPasswdMail(r *middleware.Render, user *models.User) {
+ code := CreateUserActiveCode(user, nil)
+
+ subject := "Reset your password"
+
+ data := GetMailTmplData(user)
+ data["Code"] = code
+ body, err := r.HTMLString("mail/auth/reset_passwd", data)
+ if err != nil {
+ log.Error("mail.SendResetPasswdMail(fail to render): %v", err)
+ return
+ }
+
+ msg := NewMailMessage([]string{user.Email}, subject, body)
+ msg.Info = fmt.Sprintf("UID: %d, send reset password email", user.Id)
SendAsync(&msg)
}
diff --git a/modules/oauth2/oauth2.go b/modules/oauth2/oauth2.go
index 088d65dd..6612b95a 100644
--- a/modules/oauth2/oauth2.go
+++ b/modules/oauth2/oauth2.go
@@ -26,7 +26,10 @@ import (
"code.google.com/p/goauth2/oauth"
"github.com/go-martini/martini"
- "github.com/martini-contrib/sessions"
+
+ "github.com/gogits/session"
+
+ "github.com/gogits/gogs/modules/middleware"
)
const (
@@ -142,23 +145,23 @@ func NewOAuth2Provider(opts *Options) martini.Handler {
Transport: http.DefaultTransport,
}
- return func(s sessions.Session, c martini.Context, w http.ResponseWriter, r *http.Request) {
- if r.Method == "GET" {
- switch r.URL.Path {
+ return func(c martini.Context, ctx *middleware.Context) {
+ if ctx.Req.Method == "GET" {
+ switch ctx.Req.URL.Path {
case PathLogin:
- login(transport, s, w, r)
+ login(transport, ctx)
case PathLogout:
- logout(transport, s, w, r)
+ logout(transport, ctx)
case PathCallback:
- handleOAuth2Callback(transport, s, w, r)
+ handleOAuth2Callback(transport, ctx)
}
}
- tk := unmarshallToken(s)
+ tk := unmarshallToken(ctx.Session)
if tk != nil {
// check if the access token is expired
if tk.IsExpired() && tk.Refresh() == "" {
- s.Delete(keyToken)
+ ctx.Session.Delete(keyToken)
tk = nil
}
}
@@ -172,49 +175,49 @@ func NewOAuth2Provider(opts *Options) martini.Handler {
// Sample usage:
// m.Get("/login-required", oauth2.LoginRequired, func() ... {})
var LoginRequired martini.Handler = func() martini.Handler {
- return func(s sessions.Session, c martini.Context, w http.ResponseWriter, r *http.Request) {
- token := unmarshallToken(s)
+ return func(c martini.Context, ctx *middleware.Context) {
+ token := unmarshallToken(ctx.Session)
if token == nil || token.IsExpired() {
- next := url.QueryEscape(r.URL.RequestURI())
- http.Redirect(w, r, PathLogin+"?next="+next, codeRedirect)
+ next := url.QueryEscape(ctx.Req.URL.RequestURI())
+ ctx.Redirect(PathLogin+"?next="+next, codeRedirect)
}
}
}()
-func login(t *oauth.Transport, s sessions.Session, w http.ResponseWriter, r *http.Request) {
- next := extractPath(r.URL.Query().Get(keyNextPage))
- if s.Get(keyToken) == nil {
+func login(t *oauth.Transport, ctx *middleware.Context) {
+ next := extractPath(ctx.Req.URL.Query().Get(keyNextPage))
+ if ctx.Session.Get(keyToken) == nil {
// User is not logged in.
- http.Redirect(w, r, t.Config.AuthCodeURL(next), codeRedirect)
+ ctx.Redirect(t.Config.AuthCodeURL(next), codeRedirect)
return
}
// No need to login, redirect to the next page.
- http.Redirect(w, r, next, codeRedirect)
+ ctx.Redirect(next, codeRedirect)
}
-func logout(t *oauth.Transport, s sessions.Session, w http.ResponseWriter, r *http.Request) {
- next := extractPath(r.URL.Query().Get(keyNextPage))
- s.Delete(keyToken)
- http.Redirect(w, r, next, codeRedirect)
+func logout(t *oauth.Transport, ctx *middleware.Context) {
+ next := extractPath(ctx.Req.URL.Query().Get(keyNextPage))
+ ctx.Session.Delete(keyToken)
+ ctx.Redirect(next, codeRedirect)
}
-func handleOAuth2Callback(t *oauth.Transport, s sessions.Session, w http.ResponseWriter, r *http.Request) {
- next := extractPath(r.URL.Query().Get("state"))
- code := r.URL.Query().Get("code")
+func handleOAuth2Callback(t *oauth.Transport, ctx *middleware.Context) {
+ next := extractPath(ctx.Req.URL.Query().Get("state"))
+ code := ctx.Req.URL.Query().Get("code")
tk, err := t.Exchange(code)
if err != nil {
// Pass the error message, or allow dev to provide its own
// error handler.
- http.Redirect(w, r, PathError, codeRedirect)
+ ctx.Redirect(PathError, codeRedirect)
return
}
// Store the credentials in the session.
val, _ := json.Marshal(tk)
- s.Set(keyToken, val)
- http.Redirect(w, r, next, codeRedirect)
+ ctx.Session.Set(keyToken, val)
+ ctx.Redirect(next, codeRedirect)
}
-func unmarshallToken(s sessions.Session) (t *token) {
+func unmarshallToken(s session.SessionStore) (t *token) {
if s.Get(keyToken) == nil {
return
}