mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
This is the first iteration of the registration of devices and authentication for a couple of endpoints. This needs to be refactored, the code is a bit of a mess. Also because of testing some endpoints are available for remotes that shouldn't be.
46 lines
837 B
Go
46 lines
837 B
Go
package helper
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func TempPinFile(Uuid string, pin string) bool {
|
|
log.Println("temp pin file", Uuid, pin)
|
|
err := os.WriteFile("devices/"+Uuid+".tmp", []byte(pin), 0644)
|
|
if err != nil {
|
|
log.Println(err)
|
|
return false
|
|
}
|
|
|
|
time.AfterFunc(1*time.Minute, func() {
|
|
log.Println("deleting", Uuid, pin)
|
|
os.Remove("devices/" + Uuid + ".tmp")
|
|
})
|
|
|
|
return true
|
|
}
|
|
|
|
func CheckPinFile(Uuid string) bool {
|
|
_, err := os.Stat("devices/" + Uuid + ".tmp")
|
|
return err == nil
|
|
}
|
|
|
|
func SaveDeviceKey(Uuid string, key string) error {
|
|
err := os.WriteFile("devices/"+Uuid+".key", []byte(key), 0644)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func GetKeyByUuid(Uuid string) (string, error) {
|
|
data, err := os.ReadFile("devices/" + Uuid + ".key")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(data), nil
|
|
}
|