1
0
Fork 0
forked from goffee/core

Compare commits

..

4 commits

Author SHA1 Message Date
8eb14bd2da Merge pull request 'develop' (#3) from goffee/core:develop into develop
Reviewed-on: #3
2024-10-21 18:16:44 -04:00
00b8012edf fix conflict 2024-10-15 22:18:32 -05:00
be138b2fb4 add middle line 2024-10-15 22:15:20 -05:00
cc74165659 add cookie secret as env, fix components 2024-10-15 22:00:46 -05:00
4 changed files with 48 additions and 15 deletions

View file

@ -5,10 +5,9 @@
package core
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"bytes"
"crypto/rand"
"encoding/base64"
"encoding/gob"
@ -17,6 +16,8 @@ import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
)
@ -39,9 +40,24 @@ func GetCookie(r *http.Request) (UserCookie, error) {
// Create a new instance of a User type.
var user UserCookie
secretcookie, err = hex.DecodeString("13d6b4dff8f84a10851021ec8608f814570d562c92fe6b5ec4c9f595bcb3234b")
if err != nil {
return user, err
// check if template engine is enable
TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE")
if TemplateEnableStr == "" {
TemplateEnableStr = "false"
}
TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr)
// if enabled,
if TemplateEnable {
cookie_secret := os.Getenv("COOKIE_SECRET")
if cookie_secret == "" {
panic("cookie secret key is not set")
}
secretcookie, err = hex.DecodeString(cookie_secret)
if err != nil {
return user, err
}
} else {
panic("Templates are disabled")
}
gobEncodedValue, err := CookieReadEncrypted(r, "goffee", secretcookie)
@ -67,7 +83,26 @@ func SetCookie(w http.ResponseWriter, email string, token string) error {
// cookie.
var err error
secretcookie, err = hex.DecodeString("13d6b4dff8f84a10851021ec8608f814570d562c92fe6b5ec4c9f595bcb3234b")
// check if template engine is enable
TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE")
if TemplateEnableStr == "" {
TemplateEnableStr = "false"
}
TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr)
// if enabled,
if TemplateEnable {
cookie_secret := os.Getenv("COOKIE_SECRET")
if cookie_secret == "" {
panic("cookie secret key is not set")
}
secretcookie, err = hex.DecodeString(cookie_secret)
if err != nil {
return err
}
} else {
panic("Templates are disabled")
}
if err != nil {
return err
}
@ -101,8 +136,6 @@ func SetCookie(w http.ResponseWriter, email string, token string) error {
return err
}
fmt.Printf("Cookie set %v\n", email)
return nil
}

View file

@ -6,7 +6,7 @@
</tr>
</thead>
<tbody>
{{range .AllTD}}<tr scope="row">
{{- range .AllTD}}<tr scope="row">
{{range $index, $item := .}}<td {{ if $item.ID }}id="{{$item.ID}}"{{end}}>
{{ with $x := index $.AllTH $index }}
{{ if eq $x.ValueType "href"}}
@ -19,7 +19,7 @@
{{end}}
</td>
{{end}}</tr>
{{end}}
{{- end}}
</tbody>
</table>
{{end}}
{{end}}

View file

@ -1,7 +1,7 @@
package components
type FormTextarea struct {
ID string
Label string
AllOptions []FormSelectOption
ID string
Label string
Value string
}

View file

@ -1,6 +1,6 @@
{{define "form_textarea"}}
<div class="input-container">
<label for="{{.ID}}" class="form-label">{{.Label}}</label>
<textarea class="form-control" id="{{.ID}}" name="{{.ID}}" rows="3"></textarea>
<textarea class="form-control" id="{{.ID}}" name="{{.ID}}" rows="3">{{.Value}}</textarea>
</div>
{{end}}