diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-29 22:37:05 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-29 22:37:05 +0200 |
commit | 61f137d2cc8ae0199c99493701023b4d862a34ad (patch) | |
tree | 5a77a1beb16cfd508486fabf6419f37fc348fc34 /formdec.go | |
parent | 8ecfe7a2fc61caf890e319e7a2f298b71dc90826 (diff) | |
download | mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.tar.gz mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.tar.bz2 mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.zip |
Registering accounts is working
Diffstat (limited to 'formdec.go')
-rw-r--r-- | formdec.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/formdec.go b/formdec.go new file mode 100644 index 0000000..d554696 --- /dev/null +++ b/formdec.go @@ -0,0 +1,39 @@ +package main + +import ( + "github.com/gorilla/schema" + "reflect" + "regexp" + "time" +) + +type EMail string + +var emailRegex = regexp.MustCompile(`^.+@.+$`) + +func EMailConvert(s string) reflect.Value { + if emailRegex.MatchString(s) { + return reflect.ValueOf(EMail(s)) + } + return reflect.Value{} +} + +type timelocForm struct { + Loc *time.Location +} + +func locationConverter(s string) reflect.Value { + loc, err := time.LoadLocation(s) + if err != nil { + return reflect.Value{} + } + return reflect.ValueOf(timelocForm{loc}) +} + +var formdec *schema.Decoder + +func init() { + formdec = schema.NewDecoder() + formdec.RegisterConverter(EMail(""), EMailConvert) + formdec.RegisterConverter(timelocForm{}, locationConverter) +} |