@@ -45,6 +45,24 @@ sub param ($c, @opts) {
45
45
return wantarray ? @{ $c -> {paramcache }{$name } } : $c -> {paramcache }{$name }[0];
46
46
}
47
47
48
+ sub setSessionParams ($c ) {
49
+ $c -> app-> sessions-> cookie_name(
50
+ $c -> stash(' courseID' ) ? ' WeBWorKCourseSession.' . $c -> stash(' courseID' ) : ' WeBWorKGeneralSession' );
51
+
52
+ # If the hostname is 'localhost' or '127.0.0.1', then the cookie domain must be omitted.
53
+ my $hostname = $c -> req-> url-> to_abs-> host;
54
+ $c -> app-> sessions-> cookie_domain($hostname ) if $hostname ne ' localhost' && $hostname ne ' 127.0.0.1' ;
55
+
56
+ $c -> app-> sessions-> cookie_path($c -> ce-> {webworkURLRoot });
57
+ $c -> app-> sessions-> secure($c -> ce-> {CookieSecure });
58
+
59
+ # If this is a session for LTI content selection, then always use SameSite None. Otherwise cookies will not be
60
+ # sent since this is in an iframe embedded in the LMS.
61
+ $c -> app-> sessions-> samesite($c -> stash-> {isContentSelection } ? ' None' : $c -> ce-> {CookieSameSite });
62
+
63
+ return ;
64
+ }
65
+
48
66
# Override the Mojolicious::Controller session method to set the cookie parameters
49
67
# from the course environment the first time it is called.
50
68
sub session ($c , @args ) {
@@ -53,20 +71,7 @@ sub session ($c, @args) {
53
71
# Initialize the cookie session the first time this is called.
54
72
unless ($c -> stash-> {' webwork2.cookie_session_initialized' }) {
55
73
$c -> stash-> {' webwork2.cookie_session_initialized' } = 1;
56
-
57
- $c -> app-> sessions-> cookie_name(
58
- $c -> stash(' courseID' ) ? ' WeBWorKCourseSession.' . $c -> stash(' courseID' ) : ' WeBWorKGeneralSession' );
59
-
60
- # If the hostname is 'localhost' or '127.0.0.1', then the cookie domain must be omitted.
61
- my $hostname = $c -> req-> url-> to_abs-> host;
62
- $c -> app-> sessions-> cookie_domain($hostname ) if $hostname ne ' localhost' && $hostname ne ' 127.0.0.1' ;
63
-
64
- $c -> app-> sessions-> cookie_path($c -> ce-> {webworkURLRoot });
65
- $c -> app-> sessions-> secure($c -> ce-> {CookieSecure });
66
-
67
- # If this is a session for LTI content selection, then always use SameSite None. Otherwise cookies will not be
68
- # sent since this is in an iframe embedded in the LMS.
69
- $c -> app-> sessions-> samesite($c -> stash-> {isContentSelection } ? ' None' : $c -> ce-> {CookieSameSite });
74
+ $c -> setSessionParams;
70
75
}
71
76
72
77
return $c -> SUPER::session(@args );
0 commit comments