Drop settings in PostToken -- it isn't needed

This commit is contained in:
Ben Schumacher 2015-05-18 12:42:00 -06:00
parent f9f2fdc2c8
commit a5c62fc572

View file

@ -6,23 +6,15 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding" "github.com/gin-gonic/gin/binding"
"github.com/drone/drone/pkg/server/session"
common "github.com/drone/drone/pkg/types" common "github.com/drone/drone/pkg/types"
) )
// POST /api/user/tokens // POST /api/user/tokens
func PostToken(c *gin.Context) { func PostToken(c *gin.Context) {
settings := ToSettings(c) sess := ToSession(c)
store := ToDatastore(c) store := ToDatastore(c)
user := ToUser(c) user := ToUser(c)
// if a session secret is not defined there is no way to
// generate jwt user tokens, so we must throw an error
if settings.Session == nil || len(settings.Session.Secret) == 0 {
c.String(500, "User tokens are not configured")
return
}
in := &common.Token{} in := &common.Token{}
if !c.BindWith(in, binding.JSON) { if !c.BindWith(in, binding.JSON) {
return return
@ -43,14 +35,6 @@ func PostToken(c *gin.Context) {
return return
} }
var sess session.Session
val, _ := c.Get("session")
if val != nil {
sess = val.(session.Session)
} else {
sess = session.New(settings.Session)
}
jwt, err := sess.GenerateToken(token) jwt, err := sess.GenerateToken(token)
if err != nil { if err != nil {
c.Fail(400, err) c.Fail(400, err)