Class: AccountsController

Inherits:
ReaderActionController show all
Defined in:
app/controllers/accounts_controller.rb

Instance Method Summary collapse

Methods inherited from ReaderActionController

#default_welcome_url, #logged_in?, #logged_in_admin?, #logged_in_user?, #permission_denied

Instance Method Details

#createObject



64
65
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
# File 'app/controllers/accounts_controller.rb', line 64

def create
  @reader = Reader.new(params[:reader])
  @reader.clear_password = params[:reader][:password]

  unless @reader.email.blank?
    flash[:error] = t('reader_extension.please_avoid_spam_trap')
    @reader.email = ''
    @reader.errors.add(:trap, t("reader_extension.must_be_empty"))
    render :action => 'new' and return
  end

  unless @email_field = session[:email_field]
    flash[:error] = 'please_use_form'
    redirect_to new_reader_url and return
  end

  @reader.email = params[@email_field.intern]
  if (@reader.valid?)
    @reader.save!
    @reader.send_activation_message
    self.current_reader = @reader
    redirect_to reader_activation_url
  else
    @reader.email_field = session[:email_field]
    render :action => 'new'
  end
end

#dashboardObject



41
42
43
44
# File 'app/controllers/accounts_controller.rb', line 41

def dashboard
  # @reader = current_reader
  expires_now
end

#editObject



56
57
58
# File 'app/controllers/accounts_controller.rb', line 56

def edit
  expires_now
end

#edit_profileObject



60
61
62
# File 'app/controllers/accounts_controller.rb', line 60

def edit_profile
  expires_now
end

#indexObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/accounts_controller.rb', line 14

def index
  respond_to do |format|
    format.html {
      set_expiry
      render :template => 'readers/index'
    }
    format.csv {
      send_data Reader.csv_for(@readers), :type => 'text/csv; charset=utf-8; header=present', :filename => "everyone.csv"
    }
    format.vcard {
      send_data Reader.vcards_for(@readers), :filename => "everyone.vcf"
    }
  end
end

#newObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/accounts_controller.rb', line 46

def new
  if current_reader
    flash[:error] = t('reader_extension.already_logged_in')
    redirect_to url_for(current_reader) and return
  end
  @reader = Reader.new
  session[:return_to] = request.referer
  session[:email_field] = @reader.generate_email_field_name
end

#showObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/accounts_controller.rb', line 29

def show
  respond_to do |format|
    format.html {
      set_expiry
      render :template => 'readers/show'
    }
    format.vcard {
      send_data @reader.vcard.to_s, :filename => "#{@reader.filename}.vcf"	
    }
  end
end

#updateObject



92
93
94
95
96
97
98
99
100
# File 'app/controllers/accounts_controller.rb', line 92

def update
  params[:reader][:clear_password] = params[:reader][:password] if params[:reader][:password]
  if @reader.update_attributes(params[:reader])
    flash[:notice] = t('reader_extension.account_updated')
    redirect_to reader_dashboard_url
  else
    render :action => 'edit'
  end
end