1
0
Fork 0
forked from goffee/core

Compare commits

..

No commits in common. "8eb14bd2da594aa1b038e6306a815a1be8fb0936" and "bf84e14bb12060a12d9e6581a39b26547823a92c" have entirely different histories.

4 changed files with 15 additions and 48 deletions

View file

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

View file

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

View file

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

View file

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