From ff0f6ba724748dbe340187fdd831a4d4f7f0ae5e Mon Sep 17 00:00:00 2001 From: raven Date: Wed, 22 Oct 2025 16:28:22 -0500 Subject: passwords --- server/user/command.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'server/user/command.go') diff --git a/server/user/command.go b/server/user/command.go index 47a3efb..b4c6d5f 100644 --- a/server/user/command.go +++ b/server/user/command.go @@ -51,6 +51,43 @@ func (u *User) SendRequest(r session.Request) { u.Stream.Event(r.Cmd) r.ReplyOk() + case "auth-update": + if r.From.UserId != u.Id() { + r.Reply(proto.Fail{"forbidden", "", nil}.Cmd()) + return + } + if !u.anonymous && !r.From.PasswordAuthed { + r.Reply(proto.Fail{"password-required", "", nil}.Cmd()) + return + } + if len(r.Cmd.Args) != 1 { + r.ReplyInvalid() + return + } + upd := r.Cmd.Args[0] + switch upd.Kind { + case "password": + var password string + for k, v := range upd.Fields { + switch k { + case "": + password = v + default: + r.ReplyInvalid() + } + } + if password == "" { + r.ReplyInvalid() + return + } + u.SetPassword(password) + r.From.PasswordAuthed = true + r.ReplyOk() + default: + r.ReplyInvalid() + return + } + case "i": r.Reply(proto.NewCmd("i", "", u.InfoFor(r.From.UserId))) -- cgit v1.2.3