Skip to content

Commit

Permalink
Fix mixed case usernames in Matrix auth
Browse files Browse the repository at this point in the history
  • Loading branch information
devplayer0 committed Oct 16, 2020
1 parent db781f2 commit 5d37b6a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/ma1sd/ma1sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (m *MA1SD) apiAuth(w http.ResponseWriter, r *http.Request) {
}

var user models.User
if err := m.DB.First(&user, "username = ?", req.Auth.LocalPart).Error; err != nil {
if err := m.DB.First(&user, "LOWER(username) = ?", req.Auth.LocalPart).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
util.JSONResponse(w, authReponse{}, http.StatusNotFound)
return
Expand Down Expand Up @@ -147,7 +147,7 @@ func (m *MA1SD) apiAuth(w http.ResponseWriter, r *http.Request) {
Success: true,
ID: id{
Type: "localpart",
Value: user.Username,
Value: strings.ToLower(user.Username),
},
Profile: authProfile{
DisplayName: displayName(&user),
Expand Down Expand Up @@ -208,7 +208,7 @@ func (m *MA1SD) apiDirectory(w http.ResponseWriter, r *http.Request) {

results = append(results, directoryResult{
DisplayName: displayName(&u),
UserID: u.Username,
UserID: strings.ToLower(u.Username),
})
}

Expand Down Expand Up @@ -248,7 +248,7 @@ func (m *MA1SD) identityLookup(lookup threePid) (identityLookupItem, error) {
Address: user.Email,
ID: id{
Type: "localpart",
Value: user.Username,
Value: strings.ToLower(user.Username),
},
}, nil
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (m *MA1SD) apiProfile(field string) http.HandlerFunc {
}

var user models.User
if err := m.DB.First(&user, "username = ?", req.LocalPart).Error; err != nil {
if err := m.DB.First(&user, "LOWER(username) = ?", req.LocalPart).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
util.JSONResponse(w, emptyProfileResponse, http.StatusNotFound)
return
Expand Down

0 comments on commit 5d37b6a

Please sign in to comment.