Skip to content

Commit

Permalink
Fix homedirectory logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Archibald committed Jan 31, 2017
1 parent 3ca9112 commit c93716c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion authStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:]
}
2 changes: 1 addition & 1 deletion backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down

0 comments on commit c93716c

Please sign in to comment.