2016-05-02 21:21:25 +02:00
|
|
|
package server
|
2015-09-30 03:21:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
"github.com/drone/drone/router/middleware/session"
|
|
|
|
"github.com/drone/drone/shared/token"
|
|
|
|
)
|
|
|
|
|
2016-07-09 00:40:29 +02:00
|
|
|
// ShowIndex serves the main Drone application page.
|
2015-09-30 03:21:17 +02:00
|
|
|
func ShowIndex(c *gin.Context) {
|
|
|
|
user := session.User(c)
|
|
|
|
|
2016-07-09 00:40:29 +02:00
|
|
|
var csrf string
|
|
|
|
if user != nil {
|
|
|
|
csrf, _ = token.New(
|
|
|
|
token.CsrfToken,
|
|
|
|
user.Login,
|
|
|
|
).Sign(user.Hash)
|
2016-03-24 04:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
c.HTML(200, "index.html", gin.H{
|
2016-07-09 00:40:29 +02:00
|
|
|
"user": user,
|
|
|
|
"csrf": csrf,
|
2015-09-30 03:21:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-09 00:40:29 +02:00
|
|
|
// ShowLogin is a legacy endpoint that now redirects to
|
|
|
|
// initiliaze the oauth flow
|
2015-09-30 03:21:17 +02:00
|
|
|
func ShowLogin(c *gin.Context) {
|
2016-07-09 00:40:29 +02:00
|
|
|
c.Redirect(303, "/authorize")
|
2015-09-30 03:21:17 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 00:40:29 +02:00
|
|
|
// ShowLoginForm displays a login form for systems like Gogs that do not
|
|
|
|
// yet support oauth workflows.
|
2015-10-23 01:36:43 +02:00
|
|
|
func ShowLoginForm(c *gin.Context) {
|
2016-07-09 00:40:29 +02:00
|
|
|
c.HTML(200, "login.html", gin.H{})
|
2015-09-30 03:21:17 +02:00
|
|
|
}
|