Description:
allows local users
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r771:15215b7e2423 - - 1 file changed: 1 inserted, 1 deleted

@@ -1,85 +1,85
1 1 class LoginController < ApplicationController
2 2
3 3 @@authenticators = []
4 4
5 5 def index
6 6 # show login screen
7 7 reset_session
8 8 redirect_to :controller => 'main', :action => 'login'
9 9 end
10 10
11 11 def login
12 12 user = get_authenticated_user(params[:login], params[:password])
13 13 unless user
14 14 flash[:notice] = 'Wrong password'
15 15 redirect_to :controller => 'main', :action => 'login'
16 16 return
17 17 end
18 18
19 19 if (!GraderConfiguration['right.bypass_agreement']) and (!params[:accept_agree]) and !user.admin?
20 20 flash[:notice] = 'You must accept the agreement before logging in'
21 21 redirect_to :controller => 'main', :action => 'login'
22 22 return
23 23 end
24 24
25 25 #process logging in
26 26 session[:user_id] = user.id
27 27 session[:admin] = user.admin?
28 28
29 29 # clear forced logout flag for multicontests contest change
30 30 if GraderConfiguration.multicontests?
31 31 contest_stat = user.contest_stat
32 32 if contest_stat.respond_to? :forced_logout
33 33 if contest_stat.forced_logout
34 34 contest_stat.forced_logout = false
35 35 contest_stat.save
36 36 end
37 37 end
38 38 end
39 39
40 40 #save login information
41 41 Login.create(user_id: user.id, ip_address: request.remote_ip)
42 42
43 43 redirect_to :controller => 'main', :action => 'list'
44 44 end
45 45
46 46 def site_login
47 47 begin
48 48 site = Site.find(params[:login][:site_id])
49 49 rescue ActiveRecord::RecordNotFound
50 50 site = nil
51 51 end
52 52 if site==nil
53 53 flash[:notice] = 'Wrong site'
54 54 redirect_to :controller => 'main', :action => 'login' and return
55 55 end
56 56 if (site.password) and (site.password == params[:login][:password])
57 57 session[:site_id] = site.id
58 58 redirect_to :controller => 'site', :action => 'index'
59 59 else
60 60 flash[:notice] = 'Wrong site password'
61 61 redirect_to :controller => 'site', :action => 'login'
62 62 end
63 63 end
64 64
65 65 def self.add_authenticator(authenticator)
66 66 @@authenticators << authenticator
67 67 end
68 68
69 69 protected
70 70
71 71 def get_authenticated_user(login, password)
72 72 if @@authenticators.empty?
73 73 return User.authenticate(login, password)
74 74 else
75 - user = nil
75 + user = User.authenticate(login, password)
76 76 @@authenticators.each do |authenticator|
77 77 if not user
78 78 user = authenticator.authenticate(login, password)
79 79 end
80 80 end
81 81 return user
82 82 end
83 83 end
84 84
85 85 end
You need to be logged in to leave comments. Login now