2011-05-11 13:38:46 +02:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
|
|
|
|
skip_before_filter :authenticate
|
|
|
|
layout 'login'
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
user = User.authenticate(params[:nick], params[:password])
|
|
|
|
if user
|
|
|
|
session[:user_id] = user.id
|
2012-08-24 19:52:38 +02:00
|
|
|
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
|
2012-12-30 16:34:01 +01:00
|
|
|
if session[:return_to].present?
|
|
|
|
redirect_to_url = session[:return_to]
|
|
|
|
session[:return_to] = nil
|
|
|
|
else
|
|
|
|
redirect_to_url = root_url
|
|
|
|
end
|
|
|
|
redirect_to redirect_to_url, :notice => "Logged in!"
|
2011-05-11 13:38:46 +02:00
|
|
|
else
|
|
|
|
flash.now.alert = "Invalid email or password"
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
session[:user_id] = nil
|
|
|
|
redirect_to login_url, :notice => "Logged out!"
|
|
|
|
end
|
|
|
|
end
|