Class: ReaderSessionsController

Inherits:
ReaderActionController show all
Defined in:
app/controllers/reader_sessions_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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/reader_sessions_controller.rb', line 40

def create
  @reader_session = ReaderSession.new(params[:reader_session])
  @reader_session.save do |success|
    if success
      if @reader_session.reader.activated? && @reader_session.reader.clear_password        
        @reader_session.reader.clear_password = ""                          # we forget the cleartext version on the first successful login
        @reader_session.reader.save(false)
      end
      respond_to do |format|
        format.html {
          flash[:notice] = t('reader_extension.hello').titlecase + " #{@reader_session.reader.preferred_name}. " + t('reader_extension.welcome_back')
          redirect_back_or_to default_welcome_url(@reader_session.reader)
        }
        format.js { 
          redirect_back_with_format(:js)
        }
      end
    else
      respond_to do |format|
        format.html { render :action => :new }
        format.js { render :action => :new, :layout => false }
      end
    end
  end
end

#destroyObject



66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/reader_sessions_controller.rb', line 66

def destroy
  current_reader_session.destroy
  if current_user
    cookies[:session_token] = { :expires => 1.day.ago }
    current_user.forget_me
    session['user_id'] = nil
    current_user = nil
  end
  redirect_to 
end

#newObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/reader_sessions_controller.rb', line 25

def new
  if current_reader
    if current_reader.activated?
      cookies[:error] = t('reader_extension.already_logged_in')
      redirect_to default_welcome_url(current_reader)
    else
      cookies[:error] = t('reader_extension.account_requires_activation')
      redirect_to reader_activation_url
    end
  else
    @reader_session = ReaderSession.new
    expires_now
  end
end

#showObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/reader_sessions_controller.rb', line 7

def show
  @reader = current_reader
  respond_to do |format|
    format.html { 
      if !@reader
        redirect_to 
      elsif @reader.inactive?
        redirect_to reader_activation_url
      else
        redirect_to reader_profile_url
      end
    }
    format.js {
      render :partial => 'accounts/controls', :layout => false
    }
  end
end