瀏覽代碼

[Doi] Encrypted doi token

cgars 7 年之前
父節點
當前提交
b92332e526
共有 3 個文件被更改,包括 33 次插入3 次删除
  1. 12 0
      conf/app.ini
  2. 9 0
      pkg/setting/setting.go
  3. 12 3
      routes/doi.go

+ 12 - 0
conf/app.ini

@@ -467,6 +467,7 @@ NAMES = English,简体中文,繁體中文(香港),繁體中文(台湾),D
 
 ; Used for datetimepicker
 [i18n.datelang]
+[i18n.datelang]
 en-US = en
 zh-CN = zh
 zh-HK = zh-TW
@@ -496,6 +497,17 @@ DO = false
 INDEX_URL = localhost/index
 SEACH_URL = localhost/search
 
+[search]
+DO = false
+INDEX_URL = localhost/index
+SEACH_URL = localhost/search
+
+[doi]
+DO = false
+DOI_URL = https://doi.gin.g-node.org/
+; AES key (eg. openssl enc -aes-128-cbc -k secret -P -md sha1)
+DOI_KEY = WONTWORK
+
 ; Extension mapping to highlight class
 ; e.g. .toml=ini
 [highlight.mapping]

+ 9 - 0
pkg/setting/setting.go

@@ -106,6 +106,7 @@ var (
 	ReverseProxyAuthUser    string
 	EnableLoginStatusCookie bool
 	LoginStatusCookieName   string
+	DoiKey                  string
 
 	// Database settings
 	UseSQLite3    bool
@@ -322,6 +323,12 @@ var (
 		IndexUrl  string
 		SearchUrl string
 	}
+
+	Doi struct {
+		Do     bool
+		DoiUrl string
+		DoiKey string
+	}
 )
 
 // DateLang transforms standard language locale name to corresponding value in datetime plugin.
@@ -670,6 +677,8 @@ func NewContext() {
 		log.Fatal(2, "Fail to map UI settings: %v", err)
 	} else if err = Cfg.Section("search").MapTo(&Search); err != nil {
 		log.Fatal(2, "Fail to map Search settings: %v", err)
+	} else if err = Cfg.Section("doi").MapTo(&Doi); err != nil {
+		log.Fatal(2, "Fail to map Doi settings: %v", err)
 	}
 
 	if Mirror.DefaultInterval <= 0 {

+ 12 - 3
routes/doi.go

@@ -5,6 +5,9 @@ import (
 	"github.com/G-Node/gogs/pkg/setting"
 	"fmt"
 	"net/http"
+	"github.com/G-Node/gin-doi/src"
+	log "gopkg.in/clog.v1"
+
 )
 
 func RequestDoi(c *context.Context) {
@@ -12,8 +15,14 @@ func RequestDoi(c *context.Context) {
 		c.Status(http.StatusUnauthorized)
 		return
 	}
-
 	token := c.GetCookie(setting.SessionConfig.CookieName)
-	c.Redirect(fmt.Sprintf("https://doi.gin.g-node.org/?repo=%s&user=%s&token=%s", c.Repo.Repository.FullName(),
-		c.User.Name, token))
+	token, err := ginDoi.Encrypt([]byte(setting.Doi.DoiKey), token)
+	if err != nil {
+		log.Error(0, "Could not encrypt Secret key:%s", err)
+		c.Status(http.StatusInternalServerError)
+		return
+	}
+	url := fmt.Sprintf("%s/?repo=%s&user=%s&token=%s", setting.Doi.DoiUrl, c.Repo.Repository.FullName(),
+		c.User.Name, token)
+	c.Redirect(url)
 }