Class: AlLogin
- Inherits:
-
Object
- Object
- AlLogin
- Defined in:
- lib/al_login_main.rb
Overview
ログインマネージャ
Instance Attribute Summary (collapse)
-
- (AlForm) form
readonly
ログイン用フォームオブジェクト.
-
- (String) template_name
readonly
ログイン画面テンプレートファイル名.
-
- (Hash) values
readonly
フォームから受け取った値.
Class Method Summary (collapse)
-
+ (Object) logout
ログアウト.
Instance Method Summary (collapse)
-
- (True, False) confirm
認証.
-
- (Object) display_confirm_screen
認証用画面の表示.
-
- (AlLogin) initialize(template_name = nil)
constructor
constructor.
-
- (True, False) login
ログインメイン処理.
Constructor Details
- (AlLogin) initialize(template_name = nil)
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
- (AlForm) form (readonly)
ログイン用フォームオブジェクト
22 23 24 |
# File 'lib/al_login_main.rb', line 22 def form @form end |
- (String) template_name (readonly)
ログイン画面テンプレートファイル名
25 26 27 |
# File 'lib/al_login_main.rb', line 25 def template_name @template_name end |
- (Hash) values (readonly)
フォームから受け取った値
28 29 30 |
# File 'lib/al_login_main.rb', line 28 def values @values end |
Class Method Details
+ (Object) logout
Note:
セッション情報を削除して、ログアウトとする。
ログアウト
118 119 120 |
# File 'lib/al_login_main.rb', line 118 def self.logout() AlSession::destroy() end |
Instance Method Details
- (True, False) confirm
Note:
サブクラスでオーバライドする。
認証
131 132 133 |
# File 'lib/al_login_main.rb', line 131 def confirm() return false end |
- (Object) display_confirm_screen
認証用画面の表示
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 |
- (True, False) login
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 |
# 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_login_token] != 'DUMMY_ID_D0Sv3ebV32' print "You must enable cookie. <br>\n" print "And click bellow, jump login page.<br>\n" print '<a href="' + Alone::escape_html( Alone::request_uri() ) + "\">To Login page.</a><br>\n" exit end 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 ) end return true end |