-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsessions_controller.rb
More file actions
54 lines (48 loc) · 1.41 KB
/
sessions_controller.rb
File metadata and controls
54 lines (48 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class SessionsController < Clearance::SessionsController
before_action :require_signed_out, only: [:new_coach,:new_admin]
def new_coach
render template: "sessions/new_coach"
end
def new_admin
render template: "sessions/new_admin"
end
def create
@user = authenticate(params)
if @user.present? && @user.is_blocked
flash[:error] = "You have been blocked! Contact an Admin for details."
redirect_to coaches_sign_in_path
else
sign_in(@user) do |status|
if status.success?
redirect_back_or url_after_create
else
flash.now.alert = status.failure_message
if params["user_type"] == "coach"
render template: "sessions/new_coach", status: :unauthorized
elsif params["user_type"] == "admin"
render template: "sessions/new_admin", status: :unauthorized
else
render template: "clearance/sessions/new", status: :unauthorized
end
end
end
end
end
def url_after_create
if params["user_type"] == "coach"
flash[:notice] = "Welcome back! Do you want to coach an event?"
events_coaches_path
elsif params["user_type"] == "admin"
admin_root_path
else
Clearance.configuration.redirect_url
end
end
def logged_in
render template: "sessions/logged_in"
end
def destroy_coach
sign_out
redirect_to coaches_sign_in_path
end
end