You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: loginserver.go
    path of file: ./repos/erda/internal/core/openapi/legacy
    
    the code of the file until where you have to start completion: // Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
    
func (s *LoginServer) PwdLogin(rw http.ResponseWriter, req *http.Request) {
	var request PwdLoginRequest
	switch contentType := req.Header.Get("content-type"); strings.ToLower(contentType) {
	case "application/json":
		if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
			logrus.Errorf("failed to Decode request body, err: %v", err)
			http.Error(rw, "invalid request body", http.StatusUnauthorized)
			return
		}
	default:
		request.Username = req.FormValue("username")
		request.Password = req.FormValue("password")
	}

	if request.Username == "" || request.Password == "" {
		errStr := "empty username or passwd"
		logrus.Error(errStr)
		http.Error(rw, errStr, http.StatusUnauthorized)
		return
	}
	user := auth.NewUser(s.auth.RedisCli)
	sessionID, err := user.PwdLogin(request.Username, request.Password)
	if err != nil {
		errStr := fmt.Sprintf("pwdlogin fail: %v", err)
		logrus.Error(errStr)
		http.Error(rw, errStr, http.StatusUnauthorized)
		return
	}
	info, authr := user.GetInfo(nil)
	if authr.Code != auth.AuthSucc {
		errStr := fmt.Sprintf("pwdlogin getInfo fail: %v", authr.Detail)
		logrus.Error(errStr)
		http.Error(rw, errStr, authr.Code)
		return
	}
	rw.WriteHeader(http.StatusOK)
	res := PwdLoginResponse{
		SessionID: sessionID,
		UserInfo:  info,
	}
	resJson, err := json.Marshal(res)
	if err != nil {
		errStr := fmt.Sprintf("marshal PwdLoginResponse fail: %v", err)
		logrus.Error(errStr)
		http.Error(rw, errStr, http.StatusUnauthorized)
		return
	}
	rw.Write(resJson)
}