mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-23 04:52:40 +00:00
fix: gitea config url for avatar (#61)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
3366cde385
commit
98c85de3d6
1 changed files with 8 additions and 17 deletions
|
@ -6,6 +6,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/markbates/goth"
|
"github.com/markbates/goth"
|
||||||
"github.com/markbates/goth/gothic"
|
"github.com/markbates/goth/gothic"
|
||||||
|
@ -17,10 +22,6 @@ import (
|
||||||
"golang.org/x/text/cases"
|
"golang.org/x/text/cases"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var title = cases.Title(language.English)
|
var title = cases.Title(language.English)
|
||||||
|
@ -46,7 +47,7 @@ func processRegister(ctx echo.Context) error {
|
||||||
|
|
||||||
sess := getSession(ctx)
|
sess := getSession(ctx)
|
||||||
|
|
||||||
var dto = new(models.UserDTO)
|
dto := new(models.UserDTO)
|
||||||
if err := ctx.Bind(dto); err != nil {
|
if err := ctx.Bind(dto); err != nil {
|
||||||
return errorRes(400, "Cannot bind data", err)
|
return errorRes(400, "Cannot bind data", err)
|
||||||
}
|
}
|
||||||
|
@ -206,7 +207,7 @@ func oauthCallback(ctx echo.Context) error {
|
||||||
case "github":
|
case "github":
|
||||||
resp, err = http.Get("https://github.com/" + user.NickName + ".keys")
|
resp, err = http.Get("https://github.com/" + user.NickName + ".keys")
|
||||||
case "gitea":
|
case "gitea":
|
||||||
resp, err = http.Get(trimGiteaUrl() + "/" + user.NickName + ".keys")
|
resp, err = http.Get(urlJoin(config.C.GiteaUrl, user.NickName+".keys"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -326,16 +327,6 @@ func logout(ctx echo.Context) error {
|
||||||
return redirect(ctx, "/all")
|
return redirect(ctx, "/all")
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimGiteaUrl() string {
|
|
||||||
giteaUrl := config.C.GiteaUrl
|
|
||||||
// remove trailing slash
|
|
||||||
if giteaUrl[len(giteaUrl)-1] == '/' {
|
|
||||||
giteaUrl = giteaUrl[:len(giteaUrl)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
return giteaUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
func urlJoin(base string, elem ...string) string {
|
func urlJoin(base string, elem ...string) string {
|
||||||
joined, err := url.JoinPath(base, elem...)
|
joined, err := url.JoinPath(base, elem...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -351,7 +342,7 @@ func getAvatarUrlFromProvider(provider string, identifier string) string {
|
||||||
case "github":
|
case "github":
|
||||||
return "https://avatars.githubusercontent.com/u/" + identifier + "?v=4"
|
return "https://avatars.githubusercontent.com/u/" + identifier + "?v=4"
|
||||||
case "gitea":
|
case "gitea":
|
||||||
resp, err := http.Get("https://gitea.com/api/v1/users/" + identifier)
|
resp, err := http.Get(urlJoin(config.C.GiteaUrl, "/api/v1/users/", identifier))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Cannot get user from Gitea")
|
log.Error().Err(err).Msg("Cannot get user from Gitea")
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in a new issue