diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/sessions_controller.rb | 20 | ||||
-rw-r--r-- | app/controllers/static_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 6 |
5 files changed, 36 insertions, 2 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..7487f87 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + #include sessionhelper for the session controller and view + include SessionsHelper end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 16d11b5..68cb949 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,2 +1,22 @@ class SessionsController < ApplicationController + + def new + end + + # find the user and create a new session + def create + user = User.find_by(email: params[:session][:email].downcase) + if user && user.authenticate(params[:session][:password]) + sign_in user + redirect_to root_path + else + render 'new' + end + end + + def destroy + sign_out + redirect_to root_path + end + end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index c6df11e..6fc9490 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -1,2 +1,4 @@ class StaticController < ApplicationController + def homepage + end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 720305f..27ba020 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -14,6 +14,7 @@ class TournamentsController < ApplicationController # GET /tournaments/new def new + @game_names = Game.all.collect @tournament = Tournament.new end @@ -21,6 +22,12 @@ class TournamentsController < ApplicationController def edit end + def selected + render :update do |page| + page.replace_html 'ajax-form', :partial => 'selected' + end + end + # POST /tournaments # POST /tournaments.json def create diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b18efed..f540dde 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,6 +10,7 @@ class UsersController < ApplicationController # GET /users/1 # GET /users/1.json def show + @user = User.find(param[:id]) end # GET /users/new @@ -28,7 +29,8 @@ class UsersController < ApplicationController respond_to do |format| if @user.save - format.html { redirect_to @user, notice: 'User was successfully created.' } + sign_in @user + format.html { redirect_to root_path, notice: 'User was successfully created.' } format.json { render action: 'show', status: :created, location: @user } else format.html { render action: 'new' } @@ -69,6 +71,6 @@ class UsersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:name, :email, :user_name) + params.require(:user).permit(:name, :email, :user_name, :password, :password_confirmation) end end |