# $Id: ext_login.rb,v 1.3 2004/05/12 10:42:27 eto Exp $
# Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL2.

require 'qwik/ext_member'

module Qwik
  class Plugin
    def login_status
      user = @user
      return login_form_short if user.nil?
      @g.div{[
	  @g.p{user},
	  @g.p{@g.a("LogOut.html"){"LogOut"}}
	]}
    end

    def login_form_short
      @g.form("method"=>"POST"){[
	  "mail: ", @g.text("user"), @g.br,
	  "pass: ", @g.password("pass"), @g.br,
	  @g.submit("login"),
	]}
    end

    def login_form
      @g.form("method"=>"POST"){[
	  @g.p{"ID(E-mail)とパスワードを入力してください。"},
	  "ID(E-mail): ", @g.text("user"), @g.br,
	  "Password: ", @g.password("pass"), @g.br,
	  @g.submit(" ログイン "),
	]}
    end

    def logout()
      confirm = @query['confirm']
      return logout_exec if confirm && confirm == "yes"
      logout_form
    end

    def logout_form
      form {
"|確認|{{input(confirm,yes,must)}}|
|「ログアウトする」を押すと、本当にログアウトします。|
||{{submit(ログアウトする)}}|"}
    end

    def logout_exec
      @res.clear_cookies() #  remove the cookies from browser
      "** LOGOUTしました。\n[[FrontPage]]に戻る。".w.res
    end

    def dologout()
      logout_exec
    end
  end
end
