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
認証用画面の表示.
-
#initialize(template_name = nil) ⇒ AlLogin
constructor
constructor.
-
#login ⇒ True, False
ログインメイン処理.
Constructor Details
#initialize(template_name = nil) ⇒ AlLogin
constructor
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/al_login_main.rb', line 35 def initialize( template_name = nil ) @template_name = template_name || "./al_login.rhtml" @form = AlForm.new( [ AlText.new( 'user_id', :label=>'ユーザID', :required=>true, :validator=>/^[\w_-]+$/ ), AlText.new( 'password', :label=>'パスワード', :required=>true, :validator=>/^[\w_-]+$/ ), ] ) end |
Instance Attribute Details
#form ⇒ AlForm (readonly)
Returns ログイン用フォームオブジェクト.
22 23 24 |
# File 'lib/al_login_main.rb', line 22 def form @form end |
#template_name ⇒ String (readonly)
Returns ログイン画面テンプレートファイル名.
25 26 27 |
# File 'lib/al_login_main.rb', line 25 def template_name @template_name end |
#values ⇒ Hash (readonly)
Returns フォームから受け取った値.
28 29 30 |
# File 'lib/al_login_main.rb', line 28 def values @values end |
Class Method Details
Instance Method Details
#confirm ⇒ True, False
Note:
認証
サブクラスでオーバライドする。
138 139 140 |
# File 'lib/al_login_main.rb', line 138 def confirm() return false end |
#display_confirm_screen ⇒ Object
認証用画面の表示
50 51 52 53 |
# File 'lib/al_login_main.rb', line 50 def display_confirm_screen() AlTemplate.run( @template_name, binding ) AlSession[:al_login_token] = 'DUMMY_ID_D0Sv3ebV32' end |
#login ⇒ True, False
Note:
ログインメイン処理
ログインの一連の処理を実施し、ログインが成功したら trueを返す。 ログイン前にリクエストされたURIは保存されるが、POSTデータは保存されないので、 必要なら自分で処理するか、当システム内へ内包する方法を立案すべき。
66 67 68 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 |
# File 'lib/al_login_main.rb', line 66 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.( "ユーザIDまたはパスワードが違います。" ) 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 |