Fix gitlab account re-link
This commit is contained in:
parent
c295776b87
commit
0d44a20c63
4 changed files with 23 additions and 13 deletions
|
@ -152,6 +152,7 @@ func setupHandlers() {
|
|||
|
||||
// handler for linking GitLab account
|
||||
m.Post("/link/gitlab", handler.UserHandler(gitlab.Link))
|
||||
m.Get("/link/gitlab", handler.UserHandler(gitlab.ReLink))
|
||||
|
||||
// handlers for dashboard pages
|
||||
m.Get("/dashboard/team/:team", handler.UserHandler(handler.TeamShow))
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/drone/drone/pkg/build/script"
|
||||
|
@ -48,24 +49,32 @@ func (g *GitlabHandler) Add(w http.ResponseWriter, r *http.Request, u *User) err
|
|||
}
|
||||
|
||||
func (g *GitlabHandler) Link(w http.ResponseWriter, r *http.Request, u *User) error {
|
||||
token := r.FormValue("token")
|
||||
u.GitlabToken = token
|
||||
token := strings.Trim(r.FormValue("token"), " \n\t")
|
||||
|
||||
if err := database.SaveUser(u); err != nil {
|
||||
return RenderError(w, err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
settings := database.SettingsMust()
|
||||
gl := gogitlab.NewGitlab(settings.GitlabApiUrl, g.apiPath, u.GitlabToken)
|
||||
_, err := gl.CurrentUser()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Private Token is not valid: %q", err)
|
||||
if len(u.GitlabToken) == 0 || token != u.GitlabToken && len(token) > 0 {
|
||||
u.GitlabToken = token
|
||||
settings := database.SettingsMust()
|
||||
gl := gogitlab.NewGitlab(settings.GitlabApiUrl, g.apiPath, u.GitlabToken)
|
||||
_, err := gl.CurrentUser()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Private Token is not valid: %q", err)
|
||||
}
|
||||
if err := database.SaveUser(u); err != nil {
|
||||
return RenderError(w, err, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/new/gitlab", http.StatusSeeOther)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GitlabHandler) ReLink(w http.ResponseWriter, r *http.Request, u *User) error {
|
||||
data := struct {
|
||||
User *User
|
||||
}{u}
|
||||
return RenderTemplate(w, "gitlab_link.html", &data)
|
||||
}
|
||||
|
||||
func (g *GitlabHandler) Create(w http.ResponseWriter, r *http.Request, u *User) error {
|
||||
teamName := r.FormValue("team")
|
||||
owner := r.FormValue("owner")
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<div class="col-xs-9" role="main">
|
||||
<div class="alert">
|
||||
Enter your repository details
|
||||
<a class="btn btn-default pull-right" href="/auth/login/github" style="font-size: 18px;background:#f4f4f4;">Re-Link Account</a>
|
||||
<a class="btn btn-default pull-right" href="/link/gitlab" style="font-size: 18px;background:#f4f4f4;">Re-Link Account</a>
|
||||
</div>
|
||||
<form class="form-repo" method="POST" action="/new/gitlab">
|
||||
<input type="hidden" name="domain" autocomplete="off" value="{{.Settings.GitlabDomain}}">
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<form class="form-repo" method="POST" action="/link/gitlab">
|
||||
<div class="field-group">
|
||||
<div><label>GitLab Private Token</label>
|
||||
<div><input class="form-control form-control-large" type="text" name="token" autocomplete="off"></div>
|
||||
<div><input class="form-control form-control-large" type="text" name="token" autocomplete="off" value="{{.User.GitlabToken}}"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
|
|
Loading…
Reference in a new issue