Class: Userify::UserController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/userify/user_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



71
72
73
74
75
76
77
# File 'app/controllers/userify/user_controller.rb', line 71

def activate
  @user.confirm_email!
  
  (@user)
  flash[:notice] = "Confirmed email and signed in."
  redirect_to url_after_activate
end

#forgotObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/userify/user_controller.rb', line 79

def forgot
  case request.method
    
  when :get
    render :template => 'user/forgot'
    
  when :post
    if user = ::User.find_by_email(params[:forgot][:email])
      user.set_token!(24.hours.from_now)
      ::UserifyMailer.deliver_reset_password user
      flash[:notice] = "You will receive an email within the next few minutes. " <<
                       "It contains instructions for changing your password."
      redirect_to url_after_forgot
    else
      flash[:error] = "Unknown email"
      redirect_to :back
    end
  end
  
end

#resetObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/userify/user_controller.rb', line 100

def reset
  case request.method
    
  when :get
    render :template => 'user/reset'
    
  when :post
    if @user.update_password(params[:user][:password])
      @user.confirm_email! unless @user.is_email_confirmed?
      (@user)
      flash[:notice] = "You have successfully reset your password."
      redirect_to url_after_reset
    else
      redirect_to :back
    end
  end
  
end

#signinObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/userify/user_controller.rb', line 33

def 
  case request.method
    
  when :get
    store_location(true) if session[:return_to].blank?
    render :template => 'user/signin'
    
  when :post
    @user = ::User.authenticate(params[:signin][:email], params[:signin][:password])
    if @user.nil?
      flash[:error] = "Bad email or password."
      redirect_to :back
    else
      if @user.is_email_confirmed?
        if params[:signin] and params[:signin][:remember_me] == "1"
          @user.remember_me!
          cookies[:remember_token] = { :value => @user.token, :expires => @user.token_expires_at }
        end
        (@user)
        flash[:notice] = "Signed in successfully."
        redirect_back_or 
      else
        ::UserifyMailer.deliver_confirmation(@user)
        deny_access("User has not confirmed email. Confirmation email will be resent.")
      end
    end
  end
  
end

#signoutObject



63
64
65
66
67
68
69
# File 'app/controllers/userify/user_controller.rb', line 63

def signout
  current_user.clear_token! if current_user
  cookies.delete :remember_token
  reset_session
  flash[:notice] = "You have been signed out."
  redirect_to url_after_signout
end

#signupObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/userify/user_controller.rb', line 11

def 
  case request.method
    
  when :get
    @user = ::User.new(params[:signup])
    render :template => 'user/signup'
    
  when :post
    @user = ::User.new(params[:signup])
    if @user.save
      ::UserifyMailer.deliver_confirmation @user
      flash[:notice] = "You will receive an email within the next few minutes. " <<
                       "It contains instructions for confirming your account."
      redirect_to 
    else
      flash[:error] = generate_error_messages_for(@user)
      redirect_to :back
    end
  end
  
end