From c93716ca4f9a13e35650a53d05e67df1edcf87d9 Mon Sep 17 00:00:00 2001 From: Rob Archibald Date: Tue, 31 Jan 2017 01:21:50 -0800 Subject: [PATCH] Fix homedirectory logic --- authStore.go | 18 +++++++++++++++++- backend_test.go | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/authStore.go b/authStore.go index 89869ce..ea70851 100644 --- a/authStore.go +++ b/authStore.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -367,7 +368,13 @@ func (s *authStore) createLogin(userID, dbUserID int, email, fullName, password uidNumber := 10000 // vmail user gidNumber := 10000 // vmail user - homeDirectory := "/home" + sepIndex := strings.Index(email, "@") + if sepIndex == -1 { + return nil, errors.New("invalid email address") + } + domain := email[sepIndex+1:] + user := email[:sepIndex] + homeDirectory := fmt.Sprintf("/srv/vmail/%s/%s", domain, user) mQuota := fmt.Sprintf("%dGB", mailQuota) fQuota := fmt.Sprintf("%dGB", fileQuota) login, err := s.backend.CreateSubscriber(userID, dbUserID, email, passwordHash, fullName, homeDirectory, uidNumber, gidNumber, mQuota, fQuota) @@ -577,3 +584,12 @@ func getJSON(r *http.Request, result interface{}) error { func isValidEmail(email string) bool { return len(email) <= 254 && len(email) >= 6 && emailRegex.MatchString(email) == true } + +func substringAfter(source, find string) string { + fromIndex := strings.Index(source, find) + if fromIndex == -1 { + return source + } + fromIndex += len(find) + return source[fromIndex:] +} diff --git a/backend_test.go b/backend_test.go index b0ed05b..ba3e8bf 100644 --- a/backend_test.go +++ b/backend_test.go @@ -416,7 +416,7 @@ func sessionRememberErr() *SessionRememberReturn { } func getEmailSessionSuccess() *getEmailSessionReturn { - return &getEmailSessionReturn{&emailSession{Email: "email", EmailVerifyHash: "hash", DestinationURL: "destinationURL"}, nil} + return &getEmailSessionReturn{&emailSession{Email: "email@test.com", EmailVerifyHash: "hash", DestinationURL: "destinationURL"}, nil} } func getEmailSessionErr() *getEmailSessionReturn { return &getEmailSessionReturn{nil, errors.New("failed")}