Class: Junebug::Controllers::Login

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

Instance Method Summary collapse

Instance Method Details

#getObject



224
225
226
227
228
229
230
# File 'lib/junebug/controllers.rb', line 224

def get
  @page_title = "Login/Create Account"
  @return_to = input.return_to
  puts "\nBB" + @return_to.to_s
  puts "input: #{input}"
  render :login
end

#postObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/junebug/controllers.rb', line 232

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(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(input.return_to)
      return
    else
      @notice = @user.errors.full_messages[0]
    end
  end
  render :login
end