将管理员重置验证方式改为编号列表
Some checks are pending
Security Checks / security (push) Waiting to run

This commit is contained in:
smail 2026-09-19 22:07:00 +08:00
parent f67ee65aea
commit f10dc342f7
3 changed files with 7 additions and 3 deletions

View File

@ -52,10 +52,11 @@ func SendVerifiedReset(ctx context.Context, conn net.Conn, input func(string) (s
return ErrInvalidRequest
}
var prompt strings.Builder
prompt.WriteString("请选择安全验证方式(输入序号;选择邮箱即发送验证码):")
prompt.WriteString("请选择安全验证方式\n\n")
for i, method := range challenge.Methods {
fmt.Fprintf(&prompt, " %d.%s", i+1, method.Label)
fmt.Fprintf(&prompt, "%d. %s\n", i+1, method.Label)
}
prompt.WriteString("\n选项:")
choice, err := input(prompt.String())
if err != nil {
return err

View File

@ -6,6 +6,7 @@ import (
"errors"
"io"
"os/exec"
"strings"
"git.pcux.cn/xuans/Smail/utils/password"
)
@ -45,6 +46,8 @@ func ReadVisibleInput(prompt string) (string, error) {
}
func readSystemdInput(prompt, echo string) (string, error) {
// systemd 代理把提示保存在单行配置中,用终端换行控制显示列表,避免配置被拆行。
prompt = strings.ReplaceAll(strings.ReplaceAll(prompt, "\r\n", "\n"), "\n", "\x1bE")
command := exec.Command("systemd-ask-password", "--no-tty", "--echo="+echo, prompt)
command.Stderr = io.Discard
output, err := command.Output()

View File

@ -60,7 +60,7 @@ func ReadVisibleInput(prompt string) (string, error) {
if !term.IsTerminal(int(os.Stdin.Fd())) {
return "", errors.New("安全验证需要交互式控制台")
}
fmt.Fprint(os.Stderr, prompt+": ")
fmt.Fprint(os.Stderr, strings.TrimRight(prompt, ":: ")+": ")
value, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return "", errors.New("读取安全验证输入失败")