mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-08 07:23:10 -06:00
Review comments
This commit is contained in:
parent
542fb36ae1
commit
9cae3887db
|
|
@ -1,6 +1,7 @@
|
||||||
package writers
|
package writers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
@ -12,6 +13,12 @@ import (
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
minPasswordLength = 8 // http://matrix.org/docs/spec/client_server/r0.2.0.html#password-based
|
||||||
|
maxPasswordLength = 512 // https://github.com/matrix-org/synapse/blob/v0.20.0/synapse/rest/client/v2_alpha/register.py#L161
|
||||||
|
maxUsernameLength = 254 // http://matrix.org/speculator/spec/HEAD/intro.html#user-identifiers TODO account for domain
|
||||||
|
)
|
||||||
|
|
||||||
// registerRequest represents the submitted registration request.
|
// registerRequest represents the submitted registration request.
|
||||||
// It can be broken down into 2 sections: the auth dictionary and registration parameters.
|
// It can be broken down into 2 sections: the auth dictionary and registration parameters.
|
||||||
// Registration parameters vary depending on the request, and will need to remembered across
|
// Registration parameters vary depending on the request, and will need to remembered across
|
||||||
|
|
@ -34,17 +41,19 @@ type authDict struct {
|
||||||
|
|
||||||
// http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#user-interactive-authentication-api
|
// http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#user-interactive-authentication-api
|
||||||
type userInteractiveResponse struct {
|
type userInteractiveResponse struct {
|
||||||
Flows []flow `json:"flows"`
|
Flows []authFlow `json:"flows"`
|
||||||
Completed []types.LoginType `json:"completed"`
|
Completed []types.LoginType `json:"completed"`
|
||||||
Params map[string]interface{} `json:"params"`
|
Params map[string]interface{} `json:"params"`
|
||||||
Session string `json:"session"`
|
Session string `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type flow struct {
|
// authFlow represents one possible way that the client can authenticate a request.
|
||||||
|
// http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#user-interactive-authentication-api
|
||||||
|
type authFlow struct {
|
||||||
Stages []types.LoginType `json:"stages"`
|
Stages []types.LoginType `json:"stages"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserInteractiveResponse(sessionID string, fs []flow) userInteractiveResponse {
|
func newUserInteractiveResponse(sessionID string, fs []authFlow) userInteractiveResponse {
|
||||||
return userInteractiveResponse{
|
return userInteractiveResponse{
|
||||||
fs, []types.LoginType{}, make(map[string]interface{}), sessionID,
|
fs, []types.LoginType{}, make(map[string]interface{}), sessionID,
|
||||||
}
|
}
|
||||||
|
|
@ -61,20 +70,20 @@ type registerResponse struct {
|
||||||
// Validate returns an error response if the request fails to validate.
|
// Validate returns an error response if the request fails to validate.
|
||||||
func (r *registerRequest) Validate() *util.JSONResponse {
|
func (r *registerRequest) Validate() *util.JSONResponse {
|
||||||
// https://github.com/matrix-org/synapse/blob/v0.20.0/synapse/rest/client/v2_alpha/register.py#L161
|
// https://github.com/matrix-org/synapse/blob/v0.20.0/synapse/rest/client/v2_alpha/register.py#L161
|
||||||
if len(r.Password) > 512 {
|
if len(r.Password) > maxPasswordLength {
|
||||||
return &util.JSONResponse{
|
return &util.JSONResponse{
|
||||||
Code: 400,
|
Code: 400,
|
||||||
JSON: jsonerror.BadJSON("'password' >512 characters"),
|
JSON: jsonerror.BadJSON(fmt.Sprintf("'password' >%d characters", maxPasswordLength)),
|
||||||
}
|
}
|
||||||
} else if len(r.Username) > 512 {
|
} else if len(r.Username) > maxUsernameLength {
|
||||||
return &util.JSONResponse{
|
return &util.JSONResponse{
|
||||||
Code: 400,
|
Code: 400,
|
||||||
JSON: jsonerror.BadJSON("'username' >512 characters"),
|
JSON: jsonerror.BadJSON(fmt.Sprintf("'username' >%d characters", maxUsernameLength)),
|
||||||
}
|
}
|
||||||
} else if len(r.Password) > 0 && len(r.Password) < 8 {
|
} else if len(r.Password) > 0 && len(r.Password) < minPasswordLength {
|
||||||
return &util.JSONResponse{
|
return &util.JSONResponse{
|
||||||
Code: 400,
|
Code: 400,
|
||||||
JSON: jsonerror.WeakPassword("password too weak: min 8 chars"),
|
JSON: jsonerror.WeakPassword(fmt.Sprintf("password too weak: min %d chars", minPasswordLength)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -109,8 +118,8 @@ func Register(req *http.Request, accountDB *storage.AccountDatabase) util.JSONRe
|
||||||
Code: 401,
|
Code: 401,
|
||||||
// TODO: Hard-coded 'dummy' auth for now with a bogus session ID.
|
// TODO: Hard-coded 'dummy' auth for now with a bogus session ID.
|
||||||
// Server admins should be able to change things around (eg enable captcha)
|
// Server admins should be able to change things around (eg enable captcha)
|
||||||
JSON: newUserInteractiveResponse("totallyuniquesessionid", []flow{
|
JSON: newUserInteractiveResponse("totallyuniquesessionid", []authFlow{
|
||||||
flow{[]types.LoginType{types.LoginTypeDummy}},
|
{[]types.LoginType{types.LoginTypeDummy}},
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +156,7 @@ func completeRegistration(accountDB *storage.AccountDatabase, username, password
|
||||||
UserID: acc.UserID,
|
UserID: acc.UserID,
|
||||||
AccessToken: acc.UserID, // FIXME
|
AccessToken: acc.UserID, // FIXME
|
||||||
HomeServer: acc.ServerName,
|
HomeServer: acc.ServerName,
|
||||||
DeviceID: "dendrite",
|
DeviceID: "kindauniquedeviceid",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue