Class: AlLogin
- Inherits:
-
Object
- Object
- AlLogin
- Defined in:
- lib/al_login_main.rb
Overview
ログインマネージャ
Instance Attribute Summary collapse
-
#form ⇒ AlForm
readonly
ログイン用フォームオブジェクト.
-
#template_name ⇒ String
readonly
ログイン画面テンプレートファイル名.
-
#values ⇒ Hash
readonly
フォームから受け取った値.
Class Method Summary collapse
-
.logout ⇒ Object
ログアウト.
Instance Method Summary collapse
-
#confirm ⇒ True, False
認証.
-
#display_confirm_screen ⇒ Object
認証用画面の表示.
-
#gettext_message_uri ⇒ String
翻訳ファイルのパスを返す.
-
#initialize(template_name = nil) ⇒ AlLogin
constructor
constructor.
-
#login ⇒ True, False
ログインメイン処理.
Constructor Details
#initialize(template_name = nil) ⇒ AlLogin
constructor
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/al_login_main.rb', line 37 def initialize( template_name = nil ) @template_name = template_name || "./al_login.rhtml" @form = AlForm.new( [ AlText.new( 'user_id', :label=>p_("al", "User ID"), :required=>true, :validator=>/^[\w_-]+$/ ), AlText.new( 'password', :label=>p_("al", "Password"), :required=>true, :validator=>/^[\w_-]+$/ ), ] ) end |
Instance Attribute Details
#form ⇒ AlForm (readonly)
Returns ログイン用フォームオブジェクト.
24 25 26 |
# File 'lib/al_login_main.rb', line 24 def form @form end |
#template_name ⇒ String (readonly)
Returns ログイン画面テンプレートファイル名.
27 28 29 |
# File 'lib/al_login_main.rb', line 27 def template_name @template_name end |
#values ⇒ Hash (readonly)
Returns フォームから受け取った値.
30 31 32 |
# File 'lib/al_login_main.rb', line 30 def values @values end |
Class Method Details
Instance Method Details
#confirm ⇒ True, False
Note:
認証
サブクラスでオーバライドする。
141 142 143 |
# File 'lib/al_login_main.rb', line 141 def confirm() return false end |
#display_confirm_screen ⇒ Object
認証用画面の表示
52 53 54 55 56 |
# File 'lib/al_login_main.rb', line 52 def display_confirm_screen() Alone.add_http_header("X-Frame-Options: DENY") AlTemplate.run( @template_name, binding ) AlSession[:al_login_token] = 'DUMMY_ID_D0Sv3ebV32' end |
#gettext_message_uri ⇒ String
翻訳ファイルのパスを返す
154 155 156 157 |
# File 'lib/al_login_main.rb', line 154 def () @al_locale = $AlController.init_locale() if !@al_locale return "locale/#{@al_locale}/messages.js" end |
#login ⇒ True, False
Note:
ログインメイン処理
ログインの一連の処理を実施し、ログインが成功したら trueを返す。ログイン前にリクエストされたURIは保存されるが、POSTデータは保存されないので、必要なら自分で処理するか、当システム内へ内包する方法を立案すべき。
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/al_login_main.rb', line 69 def login() # 初めてのアクセスならフォームを表示して終了。 if ! @form.fetch_request( 'POST' ) display_confirm_screen() return false end # セッションが使えるか確認。NGならあきらめる。 if ! AlSession[:al_user_id] && AlSession[:al_login_token] != 'DUMMY_ID_D0Sv3ebV32' puts "You must enable cookie. <br>" puts "And click bellow, jump login page.<br>" puts "<a href=\"#{AL_LOGIN_URI}\">To Login page.</a><br>" exit end # テンポラリログアウト AlSession::delete( :al_user_id ) AlSession::delete( :al_login_token ) # バリデーション。NGなら、フォーム表示して終了。 if ! @form.validate() display_confirm_screen() return false end @values = @form.values.dup # 認証。ユーザコードでオーバライドされた confirm()が呼び出される。 # NGなら、フォームを表示して終了。 if ! confirm() @form.( p_("al", "Invalid User ID or password.")) display_confirm_screen() return false end # 認証成功。 # セッションへユーザIDを保存して、ログイン済みであることを明示する。 AlSession::change_session_id() AlSession[:al_user_id] = @values[:user_id] # ログイン前にリクエストされていたURIがあれば、そこへリダイレクトし、 # 呼び出し元へは戻らない。 if AlSession[:al_request_uri] Alone::redirect_to( AlSession[:al_request_uri] ) AlSession.delete( :al_request_uri ) Alone::send_http_headers() exit end return true end |