@@ -45,6 +45,24 @@ sub param ($c, @opts) {
4545 return wantarray ? @{ $c -> {paramcache }{$name } } : $c -> {paramcache }{$name }[0];
4646}
4747
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+
4866# Override the Mojolicious::Controller session method to set the cookie parameters
4967# from the course environment the first time it is called.
5068sub session ($c , @args ) {
@@ -53,20 +71,7 @@ sub session ($c, @args) {
5371 # Initialize the cookie session the first time this is called.
5472 unless ($c -> stash-> {' webwork2.cookie_session_initialized' }) {
5573 $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;
7075 }
7176
7277 return $c -> SUPER::session(@args );
0 commit comments