Skip to content

Instantly share code, notes, and snippets.

@adgilfillan
Last active December 14, 2015 06:19
Show Gist options
  • Save adgilfillan/5041457 to your computer and use it in GitHub Desktop.
Save adgilfillan/5041457 to your computer and use it in GitHub Desktop.
def login
if request.post?
user = User.find_by_email(params[:email])
if ! user.nil? && user.password == params[:password]
session[:user_id] = user.id
progress_redirect
else
redirect_to(:back, :alert => "Invalid Email/Password.")
end
end
end
def progress_redirect
user = User.find_by_email(params[:email])
if user.role == "admin"
redirect_to(:controller => 'users', :action => 'index')
elsif user.progress == 0
redirect_to(:controller => 'pages', :action => 'welcome')
sign_in_flash
else
redirect_to(:controller => 'lessons', :action => 'show', :id => user.progress)
end
end
def sign_in_flash
user = User.find_by_email(params[:email])
if user.role == "admin"
elsif user.progress > 0
flash[:alert] = 'Attention! This section only needs to be completed once.
If you have already completed this section, please access the lessons and resources using the navigation bar at the top.'
else
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment