diff --git a/api.go b/api.go index 1ebd7db..6dd10c7 100644 --- a/api.go +++ b/api.go @@ -361,7 +361,7 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc if app.config.Section("matrix").Key("required").MustBool(false) { f = func(gc *gin.Context) { app.debug.Printf("%s: New user failed: Matrix verification not completed", req.Code) - respond(401, "errorMatrixVerification") + respond(401, "errorMatrixVerification", gc) } success = false return @@ -565,12 +565,13 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc } } if matrixVerified { + matrixUser.Contact = req.MatrixContact delete(app.matrix.tokens, req.MatrixPIN) if app.storage.matrix == nil { app.storage.matrix = map[string]MatrixUser{} } app.storage.matrix[user.ID] = matrixUser - if err := app.storage.storeMatrixUsers; err != nil { + if err := app.storage.storeMatrixUsers(); err != nil { app.err.Printf("Failed to store Matrix users: %v", err) } } @@ -2300,7 +2301,7 @@ func (app *appContext) MatrixSendPIN(gc *gin.Context) { respondBool(200, true, gc) } -// @Summary Check whether a matrix PIN is valid. Requires invite code. +// @Summary Check whether a matrix PIN is valid, and mark the token as verified if so. Requires invite code. // @Produce json // @Success 200 {object} boolResponse // @Failure 401 {object} boolResponse @@ -2329,6 +2330,8 @@ func (app *appContext) MatrixCheckPIN(gc *gin.Context) { respondBool(200, false, gc) return } + user.Verified = true + app.matrix.tokens[pin] = user respondBool(200, true, gc) } diff --git a/main.go b/main.go index b9a1483..afaecc0 100644 --- a/main.go +++ b/main.go @@ -354,6 +354,10 @@ func start(asDaemon, firstCall bool) { if err := app.storage.loadDiscordUsers(); err != nil { app.err.Printf("Failed to load Discord users: %v", err) } + app.storage.matrix_path = app.config.Section("files").Key("matrix_users").String() + if err := app.storage.loadMatrixUsers(); err != nil { + app.err.Printf("Failed to load Matrix users: %v", err) + } app.storage.profiles_path = app.config.Section("files").Key("user_profiles").String() app.storage.loadProfiles()