Sha256: 22b7f3d416f30b289cfb5c2e9e0101515683e336a13d630555a5269aa9b2d7c0

Contents?: true

Size: 988 Bytes

Versions: 3

Compression:

Stored size: 988 Bytes

Contents

require_dependency "blogr/application_controller"

module Blogr
  class SessionsController < ApplicationController

  	layout "blogr/login"

  	before_filter :authorize, except: [:new, :create]

    def index
    	redirect_to login_path		
    end
    
    def new
    	if current_blogr_user
    		redirect_to root_path
    		flash[:error] = "You are already logged in"
    	end

    	@title = "Login"
    	session[:return_to] = params[:return_to] if params[:return_to]
    end

    def create
    	user = User.find_by_username(params[:username]) || User.find_by_email(params[:username])
    	if user && user.authenticate(params[:password])
    		session[:user_id] = user.id
    		redirect_to root_path, notice: "Welcome back #{user.first_name}, time to get blogging!"
    	else
    		flash[:error] = "Username or password is invalid"
    		render "new"
    	end
    end

    def destroy
    	session[:user_id] = nil
    	redirect_to login_path, :notice => "Logged out!"
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blogr-0.0.8 app/controllers/blogr/sessions_controller.rb
blogr-0.0.7 app/controllers/blogr/sessions_controller.rb
blogr-0.0.6 app/controllers/blogr/sessions_controller.rb