Class: Junebug::Controllers::Login

Inherits:
Object
  • Object
show all
Defined in:
lib/junebug/controllers.rb

Instance Method Summary collapse

Instance Method Details

#getObject



149
150
151
152
153
# File 'lib/junebug/controllers.rb', line 149

def get
  @page_title = "Login/Create Account"
  @return_to = input.return_to
  render :login
end

#postObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/junebug/controllers.rb', line 155

def post
  @page_title = "Login/Create Account"
  @user = User.find :first, :conditions => ['username = ? AND password = ?', input.username, input.password]
  @return_to = input.return_to
  if @user
    if @user.password == input.password
      @state.user = @user
      input.return_to.blank? ? redirect(Junebug.startpage) : redirect(Junebug.config['url'] + input.return_to)
      return
    else
      @notice = 'Authentication failed'
    end
  else
    @user = User.create :username=>input.username, :password=>input.password
    if @user.errors.empty?
      @state.user = @user
      input.return_to.blank? ? redirect(Junebug.startpage) : redirect(Junebug.config['url'] + input.return_to)
      return
    else
      @notice = @user.errors.full_messages[0]
    end
  end
  render :login
end