diff options
| author | horus_arch | 2015-03-20 01:01:30 +0100 |
|---|---|---|
| committer | horus_arch | 2015-03-20 01:01:30 +0100 |
| commit | 039fb0ce71d132a1dfe93b516bc5953dcb61285e (patch) | |
| tree | 0680bf2d0d42a7c8f4f5dfe0b579277edfc38198 /server.go | |
| parent | 77b167ceae8904d827571a0ba7bfa13fac28a40e (diff) | |
| download | freemail-039fb0ce71d132a1dfe93b516bc5953dcb61285e.tar.gz | |
Bundling functionality in server.go and improving code flow.
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 +} |
