From d3767302266fe6ef73aa89bc9466f15daf13cbb1 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 22 Oct 2015 16:36:43 -0700 Subject: [PATCH] adding full support for Gogs including private repositories --- controller/pages.go | 4 + docs/setup/README.md | 1 + docs/setup/gitlab.md | 2 + docs/setup/gogs.md | 30 ++++ docs/setup/mysql.md | 2 + docs/setup/setup-agents.md | 34 ----- remote/gogs/gogs.go | 233 ++++++++++++++++++++++++++++++ remote/gogs/helper.go | 100 +++++++++++++ remote/gogs/helper_test.go | 127 ++++++++++++++++ remote/gogs/testdata/hook_push.go | 46 ++++++ remote/gogs/types.go | 38 +++++ remote/remote.go | 3 + router/router.go | 1 + static/styles/pages/login.sass | 33 +++++ static/styles_gen/style.css | 14 +- template/amber/login.amber | 2 +- template/amber/login_form.amber | 24 +++ template/template.go | 1 + 18 files changed, 659 insertions(+), 36 deletions(-) create mode 100644 docs/setup/gogs.md delete mode 100644 docs/setup/setup-agents.md create mode 100644 remote/gogs/gogs.go create mode 100644 remote/gogs/helper.go create mode 100644 remote/gogs/helper_test.go create mode 100644 remote/gogs/testdata/hook_push.go create mode 100644 remote/gogs/types.go create mode 100644 template/amber/login_form.amber diff --git a/controller/pages.go b/controller/pages.go index b691d4fe2..7b39cd7bb 100644 --- a/controller/pages.go +++ b/controller/pages.go @@ -59,6 +59,10 @@ func ShowLogin(c *gin.Context) { c.HTML(200, "login.html", gin.H{"Error": c.Query("error")}) } +func ShowLoginForm(c *gin.Context) { + c.HTML(200, "login_form.html", gin.H{}) +} + func ShowUser(c *gin.Context) { user := session.User(c) token, _ := token.New( diff --git a/docs/setup/README.md b/docs/setup/README.md index 30da995a4..971ed6206 100644 --- a/docs/setup/README.md +++ b/docs/setup/README.md @@ -9,6 +9,7 @@ * [GitHub](github.md) * [GitLab](gitlab.md) * [Bitbucket](bitbucket.md) + * [Gogs](gogs.md) * Database * [SQLite](sqlite.md) * [MySQL](mysql.md) diff --git a/docs/setup/gitlab.md b/docs/setup/gitlab.md index 6166074c1..705b90783 100644 --- a/docs/setup/gitlab.md +++ b/docs/setup/gitlab.md @@ -1,5 +1,7 @@ # Gitlab +> GitLab support is experimental and unstable due to high variation in GitLab configurations and versions. We highly recommend using [Gogs](https://github.com/gogits/gogs) as an alternative to GitLab. + Drone comes with built-in support for GitLab version 8.0 and higher. To enable Gitlab you should configure the Gitlab driver using the following environment variables: ```bash diff --git a/docs/setup/gogs.md b/docs/setup/gogs.md new file mode 100644 index 000000000..e0d8db7cb --- /dev/null +++ b/docs/setup/gogs.md @@ -0,0 +1,30 @@ +# Gogs + +Drone comes with built-in support for Gogs version `0.6` and higher. To enable Gogs you should configure the Gogs driver using the following environment variables: + +```bash +REMOTE_DRIVER=gogs +REMOTE_CONFIG=https://gogs.hooli.com?open=false +``` + +## Gogs configuration + +The following is the standard URI connection scheme: + +``` +scheme://host[:port][?options] +``` + +The components of this string are: + +* `scheme` server protocol `http` or `https`. +* `host` server address to connect to. The default value is github.com if not specified. +* `:port` optional. The default value is :80 if not specified. +* `?options` connection specific options. + +## Gogs options + +This section lists all connection options used in the connection string format. Connection options are pairs in the following form: `name=value`. The value is always case sensitive. Separate options with the ampersand (i.e. &) character: + +* `open=false` allows users to self-register. Defaults to false for security reasons. +* `skip_verify=false` skip ca verification if self-signed certificate. Defaults to false for security reasons. diff --git a/docs/setup/mysql.md b/docs/setup/mysql.md index c6ffbb950..384a614fb 100644 --- a/docs/setup/mysql.md +++ b/docs/setup/mysql.md @@ -32,6 +32,8 @@ This is an example connection string: root:pa55word@tcp(localhost:3306)/drone?parseTime=true ``` +Please note that `parseTime` is a **required** paramter. + ## MySQL options See the official [driver documentation](https://github.com/go-sql-driver/mysql#parameters) for a full list of driver options. Note that the `parseTime=true` is required. diff --git a/docs/setup/setup-agents.md b/docs/setup/setup-agents.md deleted file mode 100644 index fdff9b1f7..000000000 --- a/docs/setup/setup-agents.md +++ /dev/null @@ -1,34 +0,0 @@ -> **NOTE** this is an advanced feature and should not be required for most installs - -If you are running a large build cluster (25+ servers) we recommend using build agents. A build agent is a daemon that is installed on each build server that polls the central Drone server for work. You can add and remove build agents at any time, without having to configure and re-start the central Drone server. This is a great option if you need to frequently scale your build infrastrucutre up or down by adding or removing servers. - -You will need to configure the `/etc/drone/drone.toml` to enable build agents. This includes specifying a secret token (ie password) that will allow agents to authenticate to the central Drone server to poll for builds: - -```ini -[agents] -secret = "c0aaff74c060ff4a950d" -``` - -And then on each build server, pull the Drone agent image: - -```bash -docker pull drone/drone-agent -``` - -And start the Drone agent: - -```bash -docker run -d - -v /var/run/docker.sock:/var/run/docker.sock - -p 1991:1991 drone/drone-agent \ - --addr=http://localhost:8000 \ - --token=c0aaff74c060ff4a950d \ -``` - -The Drone agent is started with port `1991` exposed allowing the central Drone server to communicate directly with the agent. We also mount the Docker socket, `/var/run/docker.sock`, allowing the agent to spawn build containers. - -The Drone agent also requires the following command line arguments: - -* **addr** address of the running Drone server -* **token** token used to authorize requestests to the Drone server - diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go new file mode 100644 index 000000000..821aafcb3 --- /dev/null +++ b/remote/gogs/gogs.go @@ -0,0 +1,233 @@ +package gogs + +import ( + "fmt" + "net/http" + "net/url" + "strconv" + + "github.com/drone/drone/model" + "github.com/drone/drone/shared/envconfig" + "github.com/gogits/go-gogs-client" + + log "github.com/Sirupsen/logrus" +) + +type Gogs struct { + URL string + Open bool + PrivateMode bool + SkipVerify bool +} + +func Load(env envconfig.Env) *Gogs { + config := env.String("REMOTE_CONFIG", "") + + // parse the remote DSN configuration string + url_, err := url.Parse(config) + if err != nil { + log.Fatalln("unable to parse remote dsn. %s", err) + } + params := url_.Query() + url_.Path = "" + url_.RawQuery = "" + + // create the Githbub remote using parameters from + // the parsed DSN configuration string. + gogs := Gogs{} + gogs.URL = url_.String() + gogs.PrivateMode, _ = strconv.ParseBool(params.Get("private_mode")) + gogs.SkipVerify, _ = strconv.ParseBool(params.Get("skip_verify")) + gogs.Open, _ = strconv.ParseBool(params.Get("open")) + + return &gogs +} + +// Login authenticates the session and returns the +// remote user details. +func (g *Gogs) Login(res http.ResponseWriter, req *http.Request) (*model.User, bool, error) { + var ( + username = req.FormValue("username") + password = req.FormValue("password") + ) + + // if the username or password doesn't exist we re-direct + // the user to the login screen. + if len(username) == 0 || len(password) == 0 { + http.Redirect(res, req, "/login/form", http.StatusSeeOther) + return nil, false, nil + } + + client := gogs.NewClient(g.URL, "") + + // try to fetch drone token if it exists + var accessToken string + tokens, err := client.ListAccessTokens(username, password) + if err != nil { + return nil, false, err + } + for _, token := range tokens { + if token.Name == "drone" { + accessToken = token.Sha1 + break + } + } + + // if drone token not found, create it + if accessToken == "" { + token, err := client.CreateAccessToken(username, password, gogs.CreateAccessTokenOption{Name: "drone"}) + if err != nil { + return nil, false, err + } + accessToken = token.Sha1 + } + + client = gogs.NewClient(g.URL, accessToken) + userInfo, err := client.GetUserInfo(username) + if err != nil { + return nil, false, err + } + + user := model.User{} + user.Token = accessToken + user.Login = userInfo.UserName + user.Email = userInfo.Email + user.Avatar = userInfo.AvatarUrl + return &user, g.Open, nil +} + +// Auth authenticates the session and returns the remote user +// login for the given token and secret +func (g *Gogs) Auth(token, secret string) (string, error) { + return "", fmt.Errorf("Method not supported") +} + +// Repo fetches the named repository from the remote system. +func (g *Gogs) Repo(u *model.User, owner, name string) (*model.Repo, error) { + client := gogs.NewClient(g.URL, u.Token) + repos_, err := client.ListMyRepos() + if err != nil { + return nil, err + } + + fullName := owner + "/" + name + for _, repo := range repos_ { + if repo.FullName == fullName { + return toRepo(repo), nil + } + } + + return nil, fmt.Errorf("Not Found") +} + +// Repos fetches a list of repos from the remote system. +func (g *Gogs) Repos(u *model.User) ([]*model.RepoLite, error) { + repos := []*model.RepoLite{} + + client := gogs.NewClient(g.URL, u.Token) + repos_, err := client.ListMyRepos() + if err != nil { + return repos, err + } + + for _, repo := range repos_ { + repos = append(repos, toRepoLite(repo)) + } + + return repos, err +} + +// Perm fetches the named repository permissions from +// the remote system for the specified user. +func (g *Gogs) Perm(u *model.User, owner, name string) (*model.Perm, error) { + client := gogs.NewClient(g.URL, u.Token) + repos_, err := client.ListMyRepos() + if err != nil { + return nil, err + } + + fullName := owner + "/" + name + for _, repo := range repos_ { + if repo.FullName == fullName { + return toPerm(repo.Permissions), nil + } + } + + return nil, fmt.Errorf("Not Found") + +} + +// Script fetches the build script (.drone.yml) from the remote +// repository and returns in string format. +func (g *Gogs) Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error) { + client := gogs.NewClient(g.URL, u.Token) + cfg, err := client.GetFile(r.Owner, r.Name, b.Commit, ".drone.yml") + sec, _ := client.GetFile(r.Owner, r.Name, b.Commit, ".drone.sec") + return cfg, sec, err +} + +// Status sends the commit status to the remote system. +// An example would be the GitHub pull request status. +func (g *Gogs) Status(u *model.User, r *model.Repo, b *model.Build, link string) error { + return fmt.Errorf("Not Implemented") +} + +// Netrc returns a .netrc file that can be used to clone +// private repositories from a remote system. +func (g *Gogs) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) { + url_, err := url.Parse(g.URL) + if err != nil { + return nil, err + } + return &model.Netrc{ + Login: u.Token, + Password: "x-oauth-basic", + Machine: url_.Host, + }, nil +} + +// Activate activates a repository by creating the post-commit hook and +// adding the SSH deploy key, if applicable. +func (g *Gogs) Activate(u *model.User, r *model.Repo, k *model.Key, link string) error { + config := map[string]string{ + "url": link, + "secret": r.Hash, + "content_type": "json", + } + hook := gogs.CreateHookOption{ + Type: "gogs", + Config: config, + Active: true, + } + + client := gogs.NewClient(g.URL, u.Token) + _, err := client.CreateRepoHook(r.Owner, r.Name, hook) + return err +} + +// Deactivate removes a repository by removing all the post-commit hooks +// which are equal to link and removing the SSH deploy key. +func (g *Gogs) Deactivate(u *model.User, r *model.Repo, link string) error { + return fmt.Errorf("Not Implemented") +} + +// Hook parses the post-commit hook from the Request body +// and returns the required data in a standard format. +func (g *Gogs) Hook(r *http.Request) (*model.Repo, *model.Build, error) { + var ( + err error + repo *model.Repo + build *model.Build + ) + + switch r.Header.Get("X-Gogs-Event") { + case "push": + var push *PushHook + push, err = parsePush(r.Body) + if err == nil { + repo = repoFromPush(push) + build = buildFromPush(push) + } + } + return repo, build, err +} diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go new file mode 100644 index 000000000..9b1c6be14 --- /dev/null +++ b/remote/gogs/helper.go @@ -0,0 +1,100 @@ +package gogs + +import ( + "encoding/json" + "fmt" + "io" + "strings" + "time" + + "github.com/drone/drone/model" + "github.com/gogits/go-gogs-client" +) + +// helper function that converts a Gogs repository +// to a Drone repository. +func toRepoLite(from *gogs.Repository) *model.RepoLite { + name := strings.Split(from.FullName, "/")[1] + return &model.RepoLite{ + Name: name, + Owner: from.Owner.UserName, + FullName: from.FullName, + Avatar: from.Owner.AvatarUrl, + } +} + +// helper function that converts a Gogs repository +// to a Drone repository. +func toRepo(from *gogs.Repository) *model.Repo { + name := strings.Split(from.FullName, "/")[1] + return &model.Repo{ + Name: name, + Owner: from.Owner.UserName, + FullName: from.FullName, + Avatar: from.Owner.AvatarUrl, + Link: from.HtmlUrl, + IsPrivate: from.Private, + Clone: from.CloneUrl, + Branch: "master", + } +} + +// helper function that converts a Gogs permission +// to a Drone permission. +func toPerm(from gogs.Permission) *model.Perm { + return &model.Perm{ + Pull: from.Pull, + Push: from.Push, + Admin: from.Admin, + } +} + +// helper function that extracts the Build data +// from a Gogs push hook +func buildFromPush(hook *PushHook) *model.Build { + return &model.Build{ + Event: model.EventPush, + Commit: hook.After, + Ref: hook.Ref, + Link: hook.Compare, + Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"), + Message: hook.Commits[0].Message, + Avatar: fixMalformedAvatar(hook.Sender.Avatar), + Author: hook.Sender.Login, + Timestamp: time.Now().UTC().Unix(), + } +} + +// helper function that extracts the Repository data +// from a Gogs push hook +func repoFromPush(hook *PushHook) *model.Repo { + fullName := fmt.Sprintf( + "%s/%s", + hook.Repo.Owner.Username, + hook.Repo.Name, + ) + return &model.Repo{ + Name: hook.Repo.Name, + Owner: hook.Repo.Owner.Username, + FullName: fullName, + Link: hook.Repo.Url, + } +} + +// helper function that parses a push hook from +// a read closer. +func parsePush(r io.Reader) (*PushHook, error) { + push := new(PushHook) + err := json.NewDecoder(r).Decode(push) + return push, err +} + +// fixMalformedAvatar is a helper function that fixes +// an avatar url if malformed (known bug with gogs) +func fixMalformedAvatar(url string) string { + index := strings.Index(url, "///") + if index != -1 { + return url[index+1:] + } + return url +} diff --git a/remote/gogs/helper_test.go b/remote/gogs/helper_test.go new file mode 100644 index 000000000..92d86215e --- /dev/null +++ b/remote/gogs/helper_test.go @@ -0,0 +1,127 @@ +package gogs + +import ( + "bytes" + "testing" + + "github.com/drone/drone/model" + "github.com/drone/drone/remote/gogs/testdata" + + "github.com/franela/goblin" + "github.com/gogits/go-gogs-client" +) + +func Test_parse(t *testing.T) { + + g := goblin.Goblin(t) + g.Describe("Gogs", func() { + + g.It("Should parse push hook payload", func() { + buf := bytes.NewBufferString(testdata.PushHook) + hook, err := parsePush(buf) + g.Assert(err == nil).IsTrue() + g.Assert(hook.Ref).Equal("refs/heads/master") + g.Assert(hook.After).Equal("ef98532add3b2feb7a137426bba1248724367df5") + g.Assert(hook.Before).Equal("4b2626259b5a97b6b4eab5e6cca66adb986b672b") + g.Assert(hook.Compare).Equal("http://gogs.golang.org/gordon/hello-world/compare/4b2626259b5a97b6b4eab5e6cca66adb986b672b...ef98532add3b2feb7a137426bba1248724367df5") + g.Assert(hook.Repo.Name).Equal("hello-world") + g.Assert(hook.Repo.Url).Equal("http://gogs.golang.org/gordon/hello-world") + g.Assert(hook.Repo.Owner.Name).Equal("gordon") + g.Assert(hook.Repo.Owner.Email).Equal("gordon@golang.org") + g.Assert(hook.Repo.Owner.Username).Equal("gordon") + g.Assert(hook.Repo.Private).Equal(true) + g.Assert(hook.Pusher.Name).Equal("gordon") + g.Assert(hook.Pusher.Email).Equal("gordon@golang.org") + g.Assert(hook.Pusher.Username).Equal("gordon") + g.Assert(hook.Sender.Login).Equal("gordon") + g.Assert(hook.Sender.Avatar).Equal("http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") + }) + + g.It("Should return a Build struct from a push hook", func() { + buf := bytes.NewBufferString(testdata.PushHook) + hook, _ := parsePush(buf) + build := buildFromPush(hook) + g.Assert(build.Event).Equal(model.EventPush) + g.Assert(build.Commit).Equal(hook.After) + g.Assert(build.Ref).Equal(hook.Ref) + g.Assert(build.Link).Equal(hook.Compare) + g.Assert(build.Branch).Equal("master") + g.Assert(build.Message).Equal(hook.Commits[0].Message) + g.Assert(build.Avatar).Equal("//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") + g.Assert(build.Author).Equal(hook.Sender.Login) + + }) + + g.It("Should return a Repo struct from a push hook", func() { + buf := bytes.NewBufferString(testdata.PushHook) + hook, _ := parsePush(buf) + repo := repoFromPush(hook) + g.Assert(repo.Name).Equal(hook.Repo.Name) + g.Assert(repo.Owner).Equal(hook.Repo.Owner.Username) + g.Assert(repo.FullName).Equal("gordon/hello-world") + g.Assert(repo.Link).Equal(hook.Repo.Url) + }) + + g.It("Should return a Perm struct from a Gogs Perm", func() { + perms := []gogs.Permission{ + {true, true, true}, + {true, true, false}, + {true, false, false}, + } + for _, from := range perms { + perm := toPerm(from) + g.Assert(perm.Pull).Equal(from.Pull) + g.Assert(perm.Push).Equal(from.Push) + g.Assert(perm.Admin).Equal(from.Admin) + } + }) + + g.It("Should return a Repo struct from a Gogs Repo", func() { + from := gogs.Repository{ + FullName: "gophers/hello-world", + Owner: gogs.User{ + UserName: "gordon", + AvatarUrl: "//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + }, + CloneUrl: "http://gogs.golang.org/gophers/hello-world.git", + HtmlUrl: "http://gogs.golang.org/gophers/hello-world", + Private: true, + } + repo := toRepo(&from) + g.Assert(repo.FullName).Equal(from.FullName) + g.Assert(repo.Owner).Equal(from.Owner.UserName) + g.Assert(repo.Name).Equal("hello-world") + g.Assert(repo.Branch).Equal("master") + g.Assert(repo.Link).Equal(from.HtmlUrl) + g.Assert(repo.Clone).Equal(from.CloneUrl) + g.Assert(repo.Avatar).Equal(from.Owner.AvatarUrl) + g.Assert(repo.IsPrivate).Equal(from.Private) + }) + + g.It("Should return a RepoLite struct from a Gogs Repo", func() { + from := gogs.Repository{ + FullName: "gophers/hello-world", + Owner: gogs.User{ + UserName: "gordon", + AvatarUrl: "//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + }, + } + repo := toRepoLite(&from) + g.Assert(repo.FullName).Equal(from.FullName) + g.Assert(repo.Owner).Equal(from.Owner.UserName) + g.Assert(repo.Name).Equal("hello-world") + g.Assert(repo.Avatar).Equal(from.Owner.AvatarUrl) + }) + + g.It("Should correct a malformed avatar url", func() { + var urls = []string{ + "http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + "//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + } + for _, url := range urls { + url = fixMalformedAvatar(url) + g.Assert(url).Equal("//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") + } + }) + }) +} diff --git a/remote/gogs/testdata/hook_push.go b/remote/gogs/testdata/hook_push.go new file mode 100644 index 000000000..868f1db6f --- /dev/null +++ b/remote/gogs/testdata/hook_push.go @@ -0,0 +1,46 @@ +package testdata + +var PushHook = ` +{ + "ref": "refs/heads/master", + "before": "4b2626259b5a97b6b4eab5e6cca66adb986b672b", + "after": "ef98532add3b2feb7a137426bba1248724367df5", + "compare_url": "http://gogs.golang.org/gordon/hello-world/compare/4b2626259b5a97b6b4eab5e6cca66adb986b672b...ef98532add3b2feb7a137426bba1248724367df5", + "commits": [ + { + "id": "ef98532add3b2feb7a137426bba1248724367df5", + "message": "bump\n", + "url": "http://gogs.golang.org/gordon/hello-world/commit/ef98532add3b2feb7a137426bba1248724367df5", + "author": { + "name": "Gordon the Gopher", + "email": "gordon@golang.org", + "username": "gordon" + } + } + ], + "repository": { + "id": 1, + "name": "hello-world", + "url": "http://gogs.golang.org/gordon/hello-world", + "description": "", + "website": "", + "watchers": 1, + "owner": { + "name": "gordon", + "email": "gordon@golang.org", + "username": "gordon" + }, + "private": true + }, + "pusher": { + "name": "gordon", + "email": "gordon@golang.org", + "username": "gordon" + }, + "sender": { + "login": "gordon", + "id": 1, + "avatar_url": "http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87" + } +} +` diff --git a/remote/gogs/types.go b/remote/gogs/types.go new file mode 100644 index 000000000..ac1947357 --- /dev/null +++ b/remote/gogs/types.go @@ -0,0 +1,38 @@ +package gogs + +type PushHook struct { + Ref string `json:"ref"` + Before string `json:"before"` + After string `json:"after"` + Compare string `json:"compare_url"` + + Pusher struct { + Name string `json:"name"` + Email string `json:"email"` + Username string `json:"username"` + } `json:"pusher"` + + Repo struct { + ID int64 `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Private bool `json:"private"` + Owner struct { + Name string `json:"name"` + Email string `json:"email"` + Username string `json:"username"` + } `json:"owner"` + } `json:"repository"` + + Commits []struct { + ID string `json:"id"` + Message string `json:"message"` + Url string `json:"url"` + } `json:"commits"` + + Sender struct { + ID int64 `json:"id"` + Login string `json:"login"` + Avatar string `json:"avatar_url"` + } `json:"sender"` +} diff --git a/remote/remote.go b/remote/remote.go index 65805ebd7..c143a0a34 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -7,6 +7,7 @@ import ( "github.com/drone/drone/remote/bitbucket" "github.com/drone/drone/remote/github" "github.com/drone/drone/remote/gitlab" + "github.com/drone/drone/remote/gogs" "github.com/drone/drone/shared/envconfig" log "github.com/Sirupsen/logrus" @@ -22,6 +23,8 @@ func Load(env envconfig.Env) Remote { return github.Load(env) case "gitlab": return gitlab.Load(env) + case "gogs": + return gogs.Load(env) default: log.Fatalf("unknown remote driver %s", driver) diff --git a/router/router.go b/router/router.go index b1d3be577..5e1c54d8c 100644 --- a/router/router.go +++ b/router/router.go @@ -32,6 +32,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler { e.GET("/", cache.Repos, controller.ShowIndex) e.GET("/login", controller.ShowLogin) + e.GET("/login/form", controller.ShowLoginForm) e.GET("/logout", controller.GetLogout) settings := e.Group("/settings") diff --git a/static/styles/pages/login.sass b/static/styles/pages/login.sass index cde93f97c..796d3d50c 100644 --- a/static/styles/pages/login.sass +++ b/static/styles/pages/login.sass @@ -38,6 +38,7 @@ body.login animation-duration: 1.5s; animation-timing-function: ease-in; + input[type="submit"], a background: #2b303b; color: #FFF; @@ -50,6 +51,7 @@ body.login min-width: 150px; text-align: center; padding: 5px; + border:none; animation-name: fadein; animation-duration: 1.5s; animation-timing-function: ease-in; @@ -68,6 +70,37 @@ body.login height:auto; border-radius:0px; +body.login.login-form + &> div + width: 300px; + height: 100px; + display: flex; + div.logo + width:65px; + position:relative; + background-position: left center; + animation-name: none; + form + flex: 1 1 auto; + + input[type="text"], + input[type="password"] + display:block; + width:100%; + padding: 5px 10px; + background-color: #eff1f5; + border: none; + color: #747C84; + + input[type="password"] + margin-top:1px; + + input[type="submit"] + position: relative; + width:100%; + margin-top: 20px; + animation-name: none; + @keyframes flyin 0% left:-3000px; diff --git a/static/styles_gen/style.css b/static/styles_gen/style.css index 378bfc01b..2d4d5e617 100644 --- a/static/styles_gen/style.css +++ b/static/styles_gen/style.css @@ -262,10 +262,22 @@ body.login div { position: relative; width: 220px; height: 30px; } body.login div div.logo { background-image: url(/static/images/logo_dark.svg); background-size: 35px; background-repeat: no-repeat; background-position: center center; position: absolute; top: 0px; left: 0px; height: 30px; width: 35px; animation-name: fadein; animation-duration: 1.5s; animation-timing-function: ease-in; } -body.login div a { background: #2b303b; color: #FFF; text-decoration: none; position: absolute; top: 0px; right: 0px; text-transform: uppercase; font-size: 13px; min-width: 150px; text-align: center; padding: 5px; animation-name: fadein; animation-duration: 1.5s; animation-timing-function: ease-in; } +body.login div input[type="submit"], body.login div a { background: #2b303b; color: #FFF; text-decoration: none; position: absolute; top: 0px; right: 0px; text-transform: uppercase; font-size: 13px; min-width: 150px; text-align: center; padding: 5px; border: none; animation-name: fadein; animation-duration: 1.5s; animation-timing-function: ease-in; } body.login div.alert { position: fixed; top: 0px; left: 0px; right: 0px; line-height: 25px; padding: 20px; width: 100%; border: none; text-align: center; vertical-align: middle; height: auto; border-radius: 0px; } +body.login.login-form > div { width: 300px; height: 100px; display: flex; } + +body.login.login-form > div div.logo { width: 65px; position: relative; background-position: left center; animation-name: none; } + +body.login.login-form > div form { flex: 1 1 auto; } + +body.login.login-form > div input[type="text"], body.login.login-form > div input[type="password"] { display: block; width: 100%; padding: 5px 10px; background-color: #eff1f5; border: none; color: #747C84; } + +body.login.login-form > div input[type="password"] { margin-top: 1px; } + +body.login.login-form > div input[type="submit"] { position: relative; width: 100%; margin-top: 20px; animation-name: none; } + @keyframes flyin { 0% { left: -3000px; } 100% { left: 0px; } } diff --git a/template/amber/login.amber b/template/amber/login.amber index a736df090..716ac88fb 100644 --- a/template/amber/login.amber +++ b/template/amber/login.amber @@ -13,7 +13,7 @@ html link[rel="stylesheet"][href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css"] link[rel="stylesheet"][href="/static/styles_gen/style.css"] style - html { height: 100%; overflow: hidden; } + html { height: 100%; overflow: hidden; } body.login div diff --git a/template/amber/login_form.amber b/template/amber/login_form.amber new file mode 100644 index 000000000..c74eacf6f --- /dev/null +++ b/template/amber/login_form.amber @@ -0,0 +1,24 @@ +doctype 5 +html + head + title Login + meta[charset="utf-8"] + meta[name="viewport"][content="width=device-width, initial-scale=1"] + meta[http-equiv="x-ua-compatible"][content="ie=edge"] + link[rel="icon"][type="image/x-icon"][href="/static/images/favicon.ico"] + + link[rel="stylesheet"][href="https://fonts.googleapis.com/icon?family=Material+Icons"] + link[rel="stylesheet"][href="https://fonts.googleapis.com/css?family=Roboto+Mono"] + link[rel="stylesheet"][href="https://fonts.googleapis.com/css?family=Roboto"] + link[rel="stylesheet"][href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css"] + link[rel="stylesheet"][href="/static/styles_gen/style.css"] + style + html { height: 100%; overflow: hidden; } + + body.login.login-form + div + div.logo + form[action="/authorize"][method="post"] + input[type="text"][placeholder="Username"][name="username"] + input[type="password"][placeholder="Password"][name="password"] + input[type="submit"][value="Login"] diff --git a/template/template.go b/template/template.go index cb6c755a7..ac55ec032 100644 --- a/template/template.go +++ b/template/template.go @@ -7,6 +7,7 @@ package template //go:generate sh -c "amberc amber/500.amber > amber_gen/500.html" //go:generate sh -c "amberc amber/build.amber > amber_gen/build.html" //go:generate sh -c "amberc amber/login.amber > amber_gen/login.html" +//go:generate sh -c "amberc amber/login_form.amber > amber_gen/login_form.html" //go:generate sh -c "amberc amber/repos.amber > amber_gen/repos.html" //go:generate sh -c "amberc amber/repo.amber > amber_gen/repo.html" //go:generate sh -c "amberc amber/repo_badge.amber > amber_gen/repo_badge.html"