Skip to content

Commit

Permalink
include db login id in CreateLogin. Fix LDAP syntax in create
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Archibald committed Jan 24, 2017
1 parent 7f3cef6 commit 1b5a41f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions authStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (s *authStore) createProfile(fullName, organization, password, picturePath
return newLoggedError("Error while creating profile", err)
}

_, err = s.createLogin(session.UserID, session.Email, fullName, password, mailQuota, fileQuota)
_, err = s.createLogin(session.UserID, session.UserID, session.Email, fullName, password, mailQuota, fileQuota)
if err != nil {
return newLoggedError("Unable to create login", err)
}
Expand All @@ -365,7 +365,7 @@ func (s *authStore) createProfile(fullName, organization, password, picturePath
}

/**************** TODO: send 0 for UID and GID numbers and empty quotas if mailQuota and fileQuota are 0 **********************/
func (s *authStore) createLogin(userID int, email, fullName, password string, mailQuota, fileQuota int) (*userLogin, error) {
func (s *authStore) createLogin(userID, dbUserID int, email, fullName, password string, mailQuota, fileQuota int) (*userLogin, error) {
passwordHash, err := cryptoHash(password)
if err != nil {
return nil, newLoggedError("Unable to create login", err)
Expand All @@ -376,7 +376,7 @@ func (s *authStore) createLogin(userID int, email, fullName, password string, ma
homeDirectory := "/home"
mQuota := fmt.Sprintf("%dGB", mailQuota)
fQuota := fmt.Sprintf("%dGB", fileQuota)
login, err := s.backend.CreateLogin(userID, email, passwordHash, fullName, homeDirectory, uidNumber, gidNumber, mQuota, fQuota)
login, err := s.backend.CreateLogin(userID, dbUserID, email, passwordHash, fullName, homeDirectory, uidNumber, gidNumber, mQuota, fQuota)
if err != nil {
return nil, newLoggedError("Unable to create login", err)
}
Expand Down
8 changes: 4 additions & 4 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type backender interface {
UpdateUser(email, fullname string, company string, pictureURL string) error

// LoginBackender. Write out since it contains duplicate BackendCloser
CreateLogin(userID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error)
CreateLogin(userID, dbUserID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error)
Login(email, password string) (*userLogin, error)
UpdateEmail(email string, password string, newEmail string) (*loginSession, error)
UpdatePassword(email string, oldPassword string, newPassword string) (*loginSession, error)
Expand All @@ -47,7 +47,7 @@ type userBackender interface {
}

type loginBackender interface {
CreateLogin(userID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error)
CreateLogin(userID, dbUserID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error)
Login(email, password string) (*userLogin, error)
UpdateEmail(email string, password string, newEmail string) (*loginSession, error)
UpdatePassword(email string, oldPassword string, newPassword string) (*loginSession, error)
Expand Down Expand Up @@ -212,8 +212,8 @@ func (b *backend) UpdateUser(email, fullname string, company string, pictureURL
return b.u.UpdateUser(email, fullname, company, pictureURL)
}

func (b *backend) CreateLogin(userID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
return b.l.CreateLogin(userID, email, passwordHash, fullName, homeDirectory, uidNumber, gidNumber, mailQuota, fileQuota)
func (b *backend) CreateLogin(userID, dbUserID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
return b.l.CreateLogin(userID, dbUserID, email, passwordHash, fullName, homeDirectory, uidNumber, gidNumber, mailQuota, fileQuota)
}

func (b *backend) UpdateEmail(email string, password string, newEmail string) (*loginSession, error) {
Expand Down
13 changes: 7 additions & 6 deletions backendLDAPLogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ldapData struct {

func (l *backendLDAPLogin) Login(email, password string) (*userLogin, error) {
// check credentials
err := l.db.Execute(ldap.NewSimpleBindRequest(email, password, nil))
err := l.db.Execute(ldap.NewSimpleBindRequest(fmt.Sprintf("uid=%s,%s", email, l.baseDn), password, nil))
if err != nil {
return nil, err
}
Expand All @@ -48,17 +48,18 @@ func (l *backendLDAPLogin) Login(email, password string) (*userLogin, error) {
}

/**************** TODO: create different type of user if not using file and mail quotas **********************/
func (l *backendLDAPLogin) CreateLogin(userID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
func (l *backendLDAPLogin) CreateLogin(userID, dbUserID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
req := ldap.NewAddRequest("uid=" + email + ",ou=Users,dc=endfirst,dc=com")
req.Attribute("objectClass", []string{"posixAccount", "account", "ownCloud", "systemQuotas"})
req.Attribute("objectClass", []string{"endfirstAccount", "endfirstSubscriber"})
req.Attribute("uid", []string{email})
req.Attribute("dbUserId", []string{strconv.Itoa(dbUserID)})
req.Attribute("cn", []string{fullName})
req.Attribute("userPassword", []string{passwordHash})
req.Attribute("uidNumber", []string{strconv.Itoa(uidNumber)})
req.Attribute("gidNumber", []string{strconv.Itoa(gidNumber)})
req.Attribute("homeDirectory", []string{homeDirectory})
req.Attribute("quota", []string{mailQuota})
req.Attribute("ownCloudQuota", []string{fileQuota})
req.Attribute("mailFolder", []string{homeDirectory})
req.Attribute("mailQuota", []string{mailQuota})
req.Attribute("fileQuota", []string{fileQuota})
err := l.db.Execute(req)
return &userLogin{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion backendLDAPLogin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestLdapLogin(t *testing.T) {
func TestLdapCreateLogin(t *testing.T) {
m := onedb.NewMock(nil, nil, nil)
l := backendLDAPLogin{db: m}
_, err := l.CreateLogin(1, "email", "hash", "name", "homeDir", 1, 1, "mailQuota", "fileQuota")
_, err := l.CreateLogin(1, 1, "email", "hash", "name", "homeDir", 1, 1, "mailQuota", "fileQuota")
if err != nil {
t.Error("expected success")
}
Expand Down
2 changes: 1 addition & 1 deletion backendMemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (m *backendMemory) UpdateUser(email, fullname string, company string, pictu
return nil
}

func (m *backendMemory) CreateLogin(userID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
func (m *backendMemory) CreateLogin(userID, dbUserID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
login := userLoginMemory{userID, email, fullName, passwordHash}
m.Logins = append(m.Logins, &login)

Expand Down
2 changes: 1 addition & 1 deletion backendMemory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestMemoryUpdateUser(t *testing.T) {

func TestMemoryCreateLogin(t *testing.T) {
backend := newBackendMemory().(*backendMemory)
if login, err := backend.CreateLogin(1, "email", "passwordHash", "fullName", "homeDirectory", 1, 1, "mailQuota", "fileQuota"); err != nil || login.Email != "email" {
if login, err := backend.CreateLogin(1, 1, "email", "passwordHash", "fullName", "homeDirectory", 1, 1, "mailQuota", "fileQuota"); err != nil || login.Email != "email" {
t.Error("expected valid login", login)
}
}
Expand Down
4 changes: 2 additions & 2 deletions backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestBackendUpdateUser(t *testing.T) {
func TestBackendCreateLogin(t *testing.T) {
m := &mockBackend{CreateLoginReturn: loginErr()}
b := backend{u: m, l: m, s: m}
b.CreateLogin(1, "email", "hash", "name", "homeDir", 1, 1, "quota", "fileQuota")
b.CreateLogin(1, 1, "email", "hash", "name", "homeDir", 1, 1, "quota", "fileQuota")
if len(m.MethodsCalled) != 1 || m.MethodsCalled[0] != "CreateLogin" {
t.Error("Expected it would call backend", m.MethodsCalled)
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func (b *mockBackend) UpdateUser(email, fullname, company, pictureURL string) er
return b.ErrReturn
}

func (b *mockBackend) CreateLogin(userID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
func (b *mockBackend) CreateLogin(userID, dbUserID int, email, passwordHash, fullName, homeDirectory string, uidNumber, gidNumber int, mailQuota, fileQuota string) (*userLogin, error) {
b.MethodsCalled = append(b.MethodsCalled, "CreateLogin")
if b.CreateLoginReturn == nil {
return nil, errors.New("CreateLoginReturn not initialized")
Expand Down

0 comments on commit 1b5a41f

Please sign in to comment.