Sha256: 079bb78c6277a1bdff060c1adca54399ff941c2b0a3c03bef1b4b441c32457b1

Contents?: true

Size: 709 Bytes

Versions: 1

Compression:

Stored size: 709 Bytes

Contents

class SessionsController < ApplicationController
	before_action :redirect_if_connected, except: :destroy

	def new
	end

	def create
		@user = User.where("lower(name) = ?", params[:session][:name].strip.downcase).first
		if @user && @user.authenticate(params[:session][:password])
			sign_in(@user, permanent: params[:session][:remember_me] == "1")
			redirect_back_or profile_path, success: t('snapuser.session.success')
		else
			flash.now[:error] = t('snapuser.session.error')
			render 'new'
		end
	end

	def destroy
		sign_out
		redirect_to root_path, success: t('snapuser.session.destroy.success')
	end

	private

	def redirect_if_connected
		redirect_to profile_path unless current_user.nil?
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snapuser-0.2.0 app/controllers/sessions_controller.rb