diff options
Diffstat (limited to 'server.go')
| -rw-r--r-- | server.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/server.go b/server.go new file mode 100644 index 0000000..a0146b9 --- /dev/null +++ b/server.go @@ -0,0 +1,37 @@ +package main + +import ( + "errors" +) + +func CreateNewEntry(email, password string) error { + if !ValidateEmail(email) { + return errors.New("This doesn't look like a mail adress.") + } + + vU := VirtualUser{Email: email, Password: password} + + if vU.EmailExists() { + return errors.New("Mail adress already exists.") + } + + vD := VirtualDomain{} + vD.Name = GetDomain(vU.Email) + + if !vD.ValidateDomain() { + return errors.New("This doesn't look like a good domain. Host not found.") + } + + if !vD.DomainExists() { + if !vD.CreateDomain() { + return errors.New("There was an error.") + } + } + + vU.DomainId = vD.GetPrimaryKey() + + if !vU.CreateEmail() { + return errors.New("There was an error.") + } + return nil +} |
