Class: UI::PasswordDialog

Inherits:
Dialog
  • Object
show all
Extended by:
Yast::I18n, Yast::UIShortcuts
Defined in:
library/general/src/lib/ui/password_dialog.rb

Overview

Dialog that asks for password. It returns String password or nil if aborted.

Instance Method Summary collapse

Methods inherited from Dialog

#close_dialog, #create_dialog, #dialog_options, #run, run

Methods included from EventDispatcher

#cancel_handler, #event_loop, #finish_dialog, #user_input

Constructor Details

#initialize(label, confirm: false) ⇒ PasswordDialog

Returns a new instance of PasswordDialog.

Parameters:

  • label (String)

    intention of password e.g. "Encrypted autoyast profile."

  • confirm (Boolean) (defaults to: false)

    if double password entry is required. Usually when new password is specified.



39
40
41
42
43
44
45
# File 'library/general/src/lib/ui/password_dialog.rb', line 39

def initialize(label, confirm: false)
  textdomain "autoinst"
  @confirm = confirm
  @label = label

  super()
end

Instance Method Details

#abort_handlerObject



62
63
64
# File 'library/general/src/lib/ui/password_dialog.rb', line 62

def abort_handler
  finish_dialog(nil)
end

#dialog_contentObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'library/general/src/lib/ui/password_dialog.rb', line 47

def dialog_content
  res = VBox(
    Left(Heading(@label)),
    Password(Id(:password), Yast::Label.Password, "")
  )
  res << Password(Id(:password2), Yast::Label.ConfirmPassword, "") if @confirm

  res << HBox(
    PushButton(Id(:ok), Yast::Label.OKButton),
    PushButton(Id(:abort), Yast::Label.AbortButton)
  )

  res
end

#ok_handlerObject



66
67
68
69
70
71
72
73
74
75
76
# File 'library/general/src/lib/ui/password_dialog.rb', line 66

def ok_handler
  password = Yast::UI.QueryWidget(:password, :Value)
  if @confirm
    password2 = Yast::UI.QueryWidget(:password2, :Value)
    if password != password2
      Yast2::Popup.show(_("Passwords does not match."), headline: :error)
      return
    end
  end
  finish_dialog(password)
end