Sha256: 1825dad315da78113098f5f0dfe4189204451b33fac40a58ff2dcaf30d9d3968

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

# Copyright (C) 2003-2006 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 GPL 2.

$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
require 'qwik/act-getpass'
require 'qwik/mailaddress'

module Qwik
  class Action
    def act_sendpass
      c_require_member

      return sendpass_show_form if ! @req.is_post?

      status = {}
      members = @site.member.list
      @req.query.each {|mail, v|
	if ! MailAddress.valid?(mail) || v != 'on'
	  status[mail] = _('Wrong format.')
	  next
	end

	if ! members.include?(mail)
	  status[mail] = _('Not a member.')
	  next
	end

	passmail = generate_password_mail(mail)
	sendmail = Sendmail.new(@config.smtp_host, @config.smtp_port,
				@config.test)
	begin
	  sendmail.send(passmail)
	  status[mail] = _('Succeeded.')
	rescue
	  status[mail] = _('Failed.')
	end
      }

      ar = []
      status.each {|mail, result|
	ar << [:li, mail, ' : ', result.to_s]
      }
      return c_notice(_('Send Password done')) {
	[:ul, ar]
      }
    end

    def sendpass_show_form
      members = @site.member.list.sort
      return c_notice(_('Send Password')) {
	[[:h2, _('You can send password for the members.')],
	  [:p, _('Please select members to send password.')],
	  [:form, {:action=>'.sendpass', :method=>'post',
	      :style=>'text-align: center; margin: 32px 0 48px;'},
	    [:ul, members.map {|member|
		[:li, [:input, {:type=>'checkbox', :name=>member}, ' '+member]]
	      }
	    ],
	    [:input, {:type=>'submit', :value=>_('Send Password')}]]]
      }
    end
  end
end

if $0 == __FILE__
  require 'qwik/test-common'
  require 'qwik/test-module-public'
  $test = true
end

if defined?($test) && $test
  class TestActSendPass < Test::Unit::TestCase
    include TestSession

    def test_all
      t_add_user

      res = session '/test/.sendpass'
      ok_title 'Send Password'
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
qwik2md-2.0.1 vendor/qwik/lib/qwik/act-sendpass.rb
qwik2md-2.0.0 vendor/qwik/lib/qwik/act-sendpass.rb
qwik2md-1.0.2 vendor/qwik/lib/qwik/act-sendpass.rb
qwik2md-1.0.1 vendor/qwik/lib/qwik/act-sendpass.rb
qwik2md-1.0.0 vendor/qwik/lib/qwik/act-sendpass.rb
qwik2md-0.1.0 vendor/qwik/lib/qwik/act-sendpass.rb
qwikdoc-0.0.1 vendor/qwik/act-sendpass.rb