Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Karim El-Husseiny Azzurrio

🎯
Focusing
Block or report user

Report or block Azzurrio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View routes.rb
root :to => "sessions#login"
match "signup", :to => "users#new"
match "login", :to => "sessions#login"
match "logout", :to => "sessions#logout"
match "home", :to => "sessions#home"
match "profile", :to => "sessions#profile"
match "setting", :to => "sessions#setting"
View sessions_controller.rb
def logout
session[:user_id] = nil
redirect_to :action => 'login'
end
View profile.html.erb
<h2 class='User_Header'> <%=@current_user.username%> Profile <h2>
View users_controller.rb
before_filter :save_login_state, :only => [:new, :create]
View sessions_controller.rb
before_filter :authenticate_user, :only => [:home, :profile, :setting]
before_filter :save_login_state, :only => [:login, :login_attempt]
View application_controller.rb
protected
def authenticate_user
if session[:user_id]
# set current user object to @current_user object variable
@current_user = User.find session[:user_id]
return true
else
redirect_to(:controller => 'sessions', :action => 'login')
return false
end
View sessions_controller.rb
def login_attempt
authorized_user = User.authenticate(params[:username_or_email],params[:login_password])
if authorized_user
session[:user_id] = authorized_user.id
flash[:notice] = "Wow Welcome again, you logged in as #{authorized_user.username}"
redirect_to(:action => 'home')
else
flash[:notice] = "Invalid Username or Password"
flash[:color]= "invalid"
render "login"
View cookie.rb
You can’t perform that action at this time.