Improve ping,logout commands.

This commit is contained in:
Otto Hollmann 2022-04-02 23:59:47 +02:00
parent c7fb0d0ed5
commit 3f6b714506
No known key found for this signature in database
GPG Key ID: 101D022F467ECE22
3 changed files with 20 additions and 1 deletions

View File

@ -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`

View File

@ -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

View File

@ -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)
}