Fix shadows declaration

This commit is contained in:
jiafeng zheng 2021-06-16 15:34:36 +08:00
parent dc1b1bbfa4
commit 813205af9a

View file

@ -26,7 +26,6 @@ import (
"github.com/matrix-org/dendrite/clientapi/userutil" "github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/dendrite/userapi/api"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
@ -44,7 +43,7 @@ type LoginTypePassword struct {
GetAccountByPassword GetAccountByPassword GetAccountByPassword GetAccountByPassword
GetAccountByLocalpart GetAccountByLocalpart GetAccountByLocalpart GetAccountByLocalpart
Config *config.ClientAPI Config *config.ClientAPI
UserAPI userapi.UserInternalAPI UserAPI api.UserInternalAPI
} }
func (t *LoginTypePassword) Name() string { func (t *LoginTypePassword) Name() string {
@ -79,7 +78,8 @@ func (t *LoginTypePassword) Login(ctx context.Context, req interface{}) (*Login,
addr = "ldap://" + t.Config.LDAP.Host + ":" + t.Config.LDAP.Port addr = "ldap://" + t.Config.LDAP.Host + ":" + t.Config.LDAP.Port
} }
conn, err := ldap.DialURL(addr) var conn *ldap.Conn
conn, err = ldap.DialURL(addr)
if err != nil { if err != nil {
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusUnauthorized, Code: http.StatusUnauthorized,
@ -97,7 +97,8 @@ func (t *LoginTypePassword) Login(ctx context.Context, req interface{}) (*Login,
} }
filter := fmt.Sprintf("(&%s(%s=%s))", t.Config.LDAP.Filter, "uid", localpart) filter := fmt.Sprintf("(&%s(%s=%s))", t.Config.LDAP.Filter, "uid", localpart)
searchRequest := ldap.NewSearchRequest(t.Config.LDAP.BaseDN, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, filter, []string{"uid"}, nil) searchRequest := ldap.NewSearchRequest(t.Config.LDAP.BaseDN, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, filter, []string{"uid"}, nil)
sr, err := conn.Search(searchRequest) var sr *ldap.SearchResult
sr, err = conn.Search(searchRequest)
if err != nil { if err != nil {
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusUnauthorized, Code: http.StatusUnauthorized,
@ -134,16 +135,16 @@ func (t *LoginTypePassword) Login(ctx context.Context, req interface{}) (*Login,
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
util.GetLogger(ctx).Debugf("registing user, %+v %+v", localpart, r.Password) util.GetLogger(ctx).Debugf("registing user, %+v %+v", localpart, r.Password)
var accRes userapi.PerformAccountCreationResponse var accRes api.PerformAccountCreationResponse
err := t.UserAPI.PerformAccountCreation(ctx, &userapi.PerformAccountCreationRequest{ err = t.UserAPI.PerformAccountCreation(ctx, &api.PerformAccountCreationRequest{
AppServiceID: "", AppServiceID: "",
Localpart: localpart, Localpart: localpart,
Password: r.Password, Password: r.Password,
AccountType: userapi.AccountTypeUser, AccountType: api.AccountTypeUser,
OnConflict: userapi.ConflictAbort, OnConflict: api.ConflictAbort,
}, &accRes) }, &accRes)
if err != nil { if err != nil {
if _, ok := err.(*userapi.ErrorConflict); ok { if _, ok := err.(*api.ErrorConflict); ok {
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UserInUse("Desired user ID is already taken."), JSON: jsonerror.UserInUse("Desired user ID is already taken."),