Show More
Commit Description:
merge
Commit Description:
merge
References:
File last commit:
Show/Diff file:
Action:
app/controllers/login_controller.rb
| 89 lines
| 2.3 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | class LoginController < ApplicationController | ||
|
r770 | @@authenticators = [] | ||
|
r0 | def index | ||
# show login screen | ||||
reset_session | ||||
redirect_to :controller => 'main', :action => 'login' | ||||
end | ||||
def login | ||||
|
r770 | user = get_authenticated_user(params[:login], params[:password]) | ||
r691 | unless user | |||
flash[:notice] = 'Wrong password' | ||||
redirect_to :controller => 'main', :action => 'login' | ||||
return | ||||
end | ||||
if (!GraderConfiguration['right.bypass_agreement']) and (!params[:accept_agree]) and !user.admin? | ||||
r535 | flash[:notice] = 'You must accept the agreement before logging in' | |||
redirect_to :controller => 'main', :action => 'login' | ||||
r691 | return | |||
end | ||||
#process logging in | ||||
session[:user_id] = user.id | ||||
session[:admin] = user.admin? | ||||
|
r295 | |||
r691 | # clear forced logout flag for multicontests contest change | |||
if GraderConfiguration.multicontests? | ||||
contest_stat = user.contest_stat | ||||
if contest_stat.respond_to? :forced_logout | ||||
if contest_stat.forced_logout | ||||
contest_stat.forced_logout = false | ||||
contest_stat.save | ||||
|
r295 | end | ||
end | ||||
r691 | end | |||
r410 | ||||
r691 | #save login information | |||
Login.create(user_id: user.id, ip_address: request.remote_ip) | ||||
redirect_to :controller => 'main', :action => 'list' | ||||
|
r0 | end | ||
|
r123 | def site_login | ||
begin | ||||
site = Site.find(params[:login][:site_id]) | ||||
rescue ActiveRecord::RecordNotFound | ||||
site = nil | ||||
end | ||||
if site==nil | ||||
flash[:notice] = 'Wrong site' | ||||
redirect_to :controller => 'main', :action => 'login' and return | ||||
end | ||||
|
r162 | if (site.password) and (site.password == params[:login][:password]) | ||
|
r123 | session[:site_id] = site.id | ||
redirect_to :controller => 'site', :action => 'index' | ||||
else | ||||
flash[:notice] = 'Wrong site password' | ||||
|
r162 | redirect_to :controller => 'site', :action => 'login' | ||
|
r123 | end | ||
end | ||||
r754 | def logout | |||
redirect_to root_path | ||||
end | ||||
|
r770 | def self.add_authenticator(authenticator) | ||
@@authenticators << authenticator | ||||
end | ||||
protected | ||||
def get_authenticated_user(login, password) | ||||
if @@authenticators.empty? | ||||
return User.authenticate(login, password) | ||||
else | ||||
|
r771 | user = User.authenticate(login, password) | ||
|
r770 | @@authenticators.each do |authenticator| | ||
if not user | ||||
user = authenticator.authenticate(login, password) | ||||
end | ||||
end | ||||
return user | ||||
end | ||||
end | ||||
|
r0 | end | ||