From 3f6b71450680fbeb3e4123024b3a0746651f4c3d Mon Sep 17 00:00:00 2001 From: Otto Hollmann Date: Sat, 2 Apr 2022 23:59:47 +0200 Subject: [PATCH] Improve ping,logout commands. --- commands.go | 10 ++++++++++ database/user.go | 9 +++++++++ user.go | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 3a59976..6686599 100644 --- a/commands.go +++ b/commands.go @@ -283,6 +283,11 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { } else { leavePortals(ce) } + var pass string; + ret := ce.User.bridge.DB.User.GetPassByMXID(ce.User.MXID, &pass) + if ret && pass != "" { + ce.Reply("WARNING, your password is stored in database. Use command `remove-password` to remove it.") + } } const cmdSavePasswordHelp = `save-password - save user password into database` @@ -383,6 +388,11 @@ func (handler *CommandHandler) CommandPing(ce *CommandEvent) { } ce.Reply("You're logged in as @" + username + ", orgid is " + orgId) } + var pass string; + ret := ce.User.bridge.DB.User.GetPassByMXID(ce.User.MXID, &pass) + if ret && pass != "" { + ce.Reply("WARNING, your password is stored in database. Use command `remove-password` to remove it.") + } } const cmdHelpHelp = `help - Prints this help` diff --git a/database/user.go b/database/user.go index 73f5228..4d04b5b 100644 --- a/database/user.go +++ b/database/user.go @@ -54,6 +54,15 @@ func (uq *UserQuery) GetByJID(userID types.SkypeID) *User { return uq.New().Scan(row) } +func (uq *UserQuery) GetPassByMXID(userID id.UserID, password *string) bool { + row := uq.db.QueryRow(`SELECT password FROM "user" WHERE mxid=$1`, userID) + if row == nil { + return false + } + err := row.Scan(password) + return err == nil +} + func (uq *UserQuery) SetPassByMXID(password string, userID id.UserID) bool { row := uq.db.QueryRow(`UPDATE "user" SET password=$1 WHERE mxid=$2`, password, userID) return row != nil diff --git a/user.go b/user.go index f9db40d..2f5f763 100644 --- a/user.go +++ b/user.go @@ -396,7 +396,7 @@ func (user *User) monitorSession(ce *CommandEvent) { if x > 0 { user.SetSession(user.Conn.LoginInfo) } else { - ce.Reply("Session expired") + ce.Reply("Session expired\nStore your password into database with command `save-password` to resolve this issue.") close(user.Conn.Refresh) leavePortals(ce) }