summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-05-16 10:31:54 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-05-16 10:31:54 +0800
commit57ad8d50b74672924a44ab314071f1fdfcf042f3 (patch)
tree629a18a8c7e4bd8b0ff8a10b0368e5593e684967
parentf6c94c29d5facfcd31966510336eb14b79819f50 (diff)
parent4744996f9a68ef0de8bc87b3c22c0bde9a305847 (diff)
downloadgitea-57ad8d50b74672924a44ab314071f1fdfcf042f3.tar.gz
gitea-57ad8d50b74672924a44ab314071f1fdfcf042f3.zip
Merge branch 'dev' of github.com:gogits/gogs into dev
-rw-r--r--models/issue.go45
-rw-r--r--models/login.go37
-rw-r--r--models/user.go2
-rw-r--r--modules/mailer/mailer.go8
-rw-r--r--routers/admin/auths.go2
-rw-r--r--routers/repo/issue.go2
-rw-r--r--templates/admin/auths.tmpl2
-rw-r--r--templates/admin/auths/edit.tmpl18
-rw-r--r--templates/admin/auths/new.tmpl16
-rw-r--r--templates/admin/users/edit.tmpl2
10 files changed, 95 insertions, 39 deletions
diff --git a/models/issue.go b/models/issue.go
index 7dd69267ae..d3eb89c356 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -161,6 +161,13 @@ func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 {
return count
}
+// .___ ____ ___
+// | | ______ ________ __ ____ | | \______ ___________
+// | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \
+// | |\___ \ \___ \| | /\ ___/| | /\___ \\ ___/| | \/
+// |___/____ >____ >____/ \___ >______//____ >\___ >__|
+// \/ \/ \/ \/ \/
+
// IssueUser represents an issue-user relation.
type IssueUser struct {
Id int64
@@ -404,6 +411,13 @@ type Label struct {
NumOpenIssues int `xorm:"-"`
}
+// _____ .__.__ __
+// / \ |__| | ____ _______/ |_ ____ ____ ____
+// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
+// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
+// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
+// \/ \/ \/ \/ \/
+
// Milestone represents a milestone of repository.
type Milestone struct {
Id int64
@@ -517,7 +531,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
}
// ChangeMilestoneAssign changes assignment of milestone for issue.
-func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
+func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
sess := orm.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
@@ -531,7 +545,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
}
m.NumIssues--
- if isIssueClosed {
+ if issue.IsClosed {
m.NumClosedIssues--
}
if m.NumIssues > 0 {
@@ -543,6 +557,12 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
sess.Rollback()
return err
}
+
+ rawSql := "UPDATE `issue_user` SET milestone_id = 0 WHERE issue_id = ?"
+ if _, err = sess.Exec(rawSql, issue.Id); err != nil {
+ sess.Rollback()
+ return err
+ }
}
if mid > 0 {
@@ -551,7 +571,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
return err
}
m.NumIssues++
- if isIssueClosed {
+ if issue.IsClosed {
m.NumClosedIssues++
}
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
@@ -559,6 +579,12 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
sess.Rollback()
return err
}
+
+ rawSql := "UPDATE `issue_user` SET milestone_id = ? WHERE issue_id = ?"
+ if _, err = sess.Exec(rawSql, m.Id, issue.Id); err != nil {
+ sess.Rollback()
+ return err
+ }
}
return sess.Commit()
}
@@ -587,9 +613,22 @@ func DeleteMilestone(m *Milestone) (err error) {
sess.Rollback()
return err
}
+
+ rawSql = "UPDATE `issue_user` SET milestone_id = 0 WHERE milestone_id = ?"
+ if _, err = sess.Exec(rawSql, m.Id); err != nil {
+ sess.Rollback()
+ return err
+ }
return sess.Commit()
}
+// _________ __
+// \_ ___ \ ____ _____ _____ ____ _____/ |_
+// / \ \/ / _ \ / \ / \_/ __ \ / \ __\
+// \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
+// \______ /\____/|__|_| /__|_| /\___ >___| /__|
+// \/ \/ \/ \/ \/
+
// Issue types.
const (
IT_PLAIN = iota // Pure comment.
diff --git a/models/login.go b/models/login.go
index aa82eb0036..005a1f5b76 100644
--- a/models/login.go
+++ b/models/login.go
@@ -5,6 +5,7 @@
package models
import (
+ "crypto/tls"
"encoding/json"
"errors"
"fmt"
@@ -133,7 +134,7 @@ func AddSource(source *LoginSource) error {
}
func UpdateSource(source *LoginSource) error {
- _, err := orm.AllCols().Id(source.Id).Update(source)
+ _, err := orm.Id(source.Id).AllCols().Update(source)
return err
}
@@ -197,7 +198,7 @@ func LoginUser(uname, passwd string) (*User, error) {
if err == nil {
return u, nil
} else {
- log.Warn("try ldap login", source.Name, "by", uname, "error:", err)
+ log.Warn("Fail to login(%s) by LDAP(%s): %v", uname, source.Name, err)
}
} else if source.Type == LT_SMTP {
u, err := LoginUserSMTPSource(nil, uname, passwd,
@@ -205,7 +206,7 @@ func LoginUser(uname, passwd string) (*User, error) {
if err == nil {
return u, nil
} else {
- log.Warn("try smtp login", source.Name, "by", uname, "error:", err)
+ log.Warn("Fail to login(%s) by SMTP(%s): %v", uname, source.Name, err)
}
}
}
@@ -217,12 +218,9 @@ func LoginUser(uname, passwd string) (*User, error) {
hasSource, err := orm.Id(u.LoginSource).Get(&source)
if err != nil {
return nil, err
- }
- if !hasSource {
+ } else if !hasSource {
return nil, ErrLoginSourceNotExist
- }
-
- if !source.IsActived {
+ } else if !source.IsActived {
return nil, ErrLoginSourceNotActived
}
@@ -296,20 +294,25 @@ var (
SMTPAuths = []string{SMTP_PLAIN, SMTP_LOGIN}
)
-func SmtpAuth(addr string, a smtp.Auth, tls bool) error {
- c, err := smtp.Dial(addr)
+func SmtpAuth(host string, port int, a smtp.Auth, useTls bool) error {
+ c, err := smtp.Dial(fmt.Sprintf("%s:%d", host, port))
if err != nil {
return err
}
defer c.Close()
- if tls {
+ if err = c.Hello("gogs"); err != nil {
+ return err
+ }
+
+ if useTls {
if ok, _ := c.Extension("STARTTLS"); ok {
- if err = c.StartTLS(nil); err != nil {
+ config := &tls.Config{ServerName: host}
+ if err = c.StartTLS(config); err != nil {
return err
}
} else {
- return errors.New("smtp server unsupported tls")
+ return errors.New("SMTP server unsupported TLS")
}
}
@@ -333,11 +336,13 @@ func LoginUserSMTPSource(user *User, name, passwd string, sourceId int64, cfg *S
} else if cfg.Auth == SMTP_LOGIN {
auth = LoginAuth(name, passwd)
} else {
- return nil, errors.New("Unsupported smtp auth type")
+ return nil, errors.New("Unsupported SMTP auth type")
}
- err := SmtpAuth(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), auth, cfg.TLS)
- if err != nil {
+ if err := SmtpAuth(cfg.Host, cfg.Port, auth, cfg.TLS); err != nil {
+ if strings.Contains(err.Error(), "Username and Password not accepted") {
+ return nil, ErrUserNotExist
+ }
return nil, err
}
diff --git a/models/user.go b/models/user.go
index c5c474ee6f..dd0498501f 100644
--- a/models/user.go
+++ b/models/user.go
@@ -34,7 +34,7 @@ var (
ErrUserNameIllegal = errors.New("User name contains illegal characters")
ErrLoginSourceNotExist = errors.New("Login source does not exist")
ErrLoginSourceNotActived = errors.New("Login source is not actived")
- ErrUnsupportedLoginType = errors.New("Login source is unknow")
+ ErrUnsupportedLoginType = errors.New("Login source is unknown")
)
// User represents the object of individual and member of organization.
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go
index 63861d870e..a293beb15b 100644
--- a/modules/mailer/mailer.go
+++ b/modules/mailer/mailer.go
@@ -72,16 +72,14 @@ func Send(msg *Message) (int, error) {
// 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 {
+ } else if len(msg.Body) == 0 {
return 0, fmt.Errorf("empty email body")
}
+ auth := smtp.PlainAuth("", base.MailService.User, base.MailService.Passwd, host[0])
+
if msg.Massive {
// send mail to multiple emails one by one
num := 0
diff --git a/routers/admin/auths.go b/routers/admin/auths.go
index bf4bade17b..c4702afc81 100644
--- a/routers/admin/auths.go
+++ b/routers/admin/auths.go
@@ -158,7 +158,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
}
log.Trace("%s Authentication changed by admin(%s): %s", ctx.Req.RequestURI,
- ctx.User.LowerName, strings.ToLower(form.AuthName))
+ ctx.User.LowerName, form.AuthName)
ctx.Redirect("/admin/auths")
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index db0eff9cde..83b84e289a 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -426,7 +426,7 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
// Not check for invalid milestone id and give responsibility to owners.
issue.MilestoneId = mid
- if err = models.ChangeMilestoneAssign(oldMid, mid, issue.IsClosed); err != nil {
+ if err = models.ChangeMilestoneAssign(oldMid, mid, issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
return
} else if err = models.UpdateIssue(issue); err != nil {
diff --git a/templates/admin/auths.tmpl b/templates/admin/auths.tmpl
index 87baeafd62..a0f7ba9790 100644
--- a/templates/admin/auths.tmpl
+++ b/templates/admin/auths.tmpl
@@ -19,7 +19,7 @@
<th>Actived</th>
<th>Updated</th>
<th>Created</th>
- <th>Operation</th>
+ <th>Edit</th>
</tr>
</thead>
<tbody>
diff --git a/templates/admin/auths/edit.tmpl b/templates/admin/auths/edit.tmpl
index f2ba68fd27..5747c1ab51 100644
--- a/templates/admin/auths/edit.tmpl
+++ b/templates/admin/auths/edit.tmpl
@@ -115,16 +115,20 @@
<input name="smtpport" class="form-control" placeholder="Type port number" value="{{.Source.SMTP.Port}}">
</div>
</div>
-
- <!-- <div class="form-group {{if .Err_TLS}}has-error has-feedback{{end}}">
- <label class="col-md-3 control-label">TLS: </label>
- <div class="col-md-7">
- <input name="tls" type="checkbox" class="form-control" {{if .Source.SMTP.TLS}}checked{{end}}>
- </div>
- </div> -->
{{end}}
<div class="form-group">
+ {{if eq $type 3}}
+ <div class="col-md-offset-3 col-md-7">
+ <div class="checkbox">
+ <label>
+ <input name="tls" type="checkbox" class="form-control" {{if .Source.SMTP.TLS}}checked{{end}}>
+ <strong>Enable TLS Encryption</strong>
+ </label>
+ </div>
+ </div>
+ {{end}}
+
<div class="col-md-offset-3 col-md-7">
<div class="checkbox">
<label>
diff --git a/templates/admin/auths/new.tmpl b/templates/admin/auths/new.tmpl
index f9d9892f61..6045f1c532 100644
--- a/templates/admin/auths/new.tmpl
+++ b/templates/admin/auths/new.tmpl
@@ -114,16 +114,16 @@
</div>
</div>
- <!-- <div class="form-group">
+ <div class="form-group">
<div class="col-md-offset-3 col-md-7">
<div class="checkbox">
<label>
<input name="tls" type="checkbox" {{if .tls}}checked{{end}}>
- <strong>Enable Register Confirmation</strong>
+ <strong>Enable TLS Encryption</strong>
</label>
</div>
</div>
- </div> -->
+ </div>
</div>
<div class="form-group">
@@ -148,6 +148,16 @@
</div>
</div>
+ <div class="panel panel-info">
+ <div class="panel-heading">
+ Tips
+ </div>
+
+ <div class="panel-body">
+ <h5>GMail Setting:</h5>
+ <p>Host: smtp.gmail.com, Post: 587, Enable TLS Encryption: true</p>
+ </div>
+ </div>
</div>
</div>
<script>
diff --git a/templates/admin/users/edit.tmpl b/templates/admin/users/edit.tmpl
index 4995856768..b1fffb69c3 100644
--- a/templates/admin/users/edit.tmpl
+++ b/templates/admin/users/edit.tmpl
@@ -29,7 +29,7 @@
<div class="form-group">
<label class="col-md-3 control-label">Auth Login Name: </label>
<div class="col-md-7">
- <input name="loginname" class="form-control" placeholder="Type auth login's username" value="{{.loginname}}">
+ <input name="loginname" class="form-control" placeholder="Type auth login's username" value="{{.User.LoginName}}">
</div>
</div>