@@ -31,18 +31,22 @@ protected function getUser(string $id): ?User
3131 }
3232 }
3333
34- public function getAnonymizedUsername ( string $ username ): string
34+ public function getUsername ( User $ actor ): ? string
3535 {
36- $ hash = hash ('sha256 ' , $ username );
37- $ eppnValue = env ('DB_EPPN ' );
38- if (is_bool ($ eppnValue ) && $ eppnValue ) {
39- $ enableEppn = true ;
40- } elseif (is_string ($ eppnValue ) && $ eppnValue == 'true ' ) {
41- $ enableEppn = true ;
36+ if ($ this ->isEnabledEppn ()) {
37+ return ($ actor ->auth === 'lti ' )
38+ ? $ actor ->alternatename
39+ : $ actor ->username ;
4240 } else {
43- $ enableEppn = false ;
41+ return $ actor -> username ;
4442 }
45- if ($ enableEppn ) {
43+ }
44+
45+ public function getAnonymizedUsername (User $ actor ): string
46+ {
47+ if ($ this ->isEnabledEppn ()) {
48+ $ username = $ this ->getUsername ($ actor );
49+ $ hash = $ username ? hash ('sha256 ' , $ username ) : '' ;
4650 $ eppn = Eppn::where ('username ' , $ username )->first ();
4751 if (is_null ($ eppn )) {
4852 if (strpos ($ username , '@ ' )) {
@@ -62,7 +66,7 @@ public function getAnonymizedUsername(string $username): string
6266 return $ eppn ->hash ;
6367 }
6468 } else {
65- return $ hash ;
69+ return hash ( ' sha256 ' , $ actor -> username ) ;
6670 }
6771 }
6872
@@ -122,4 +126,16 @@ public function getCourseId(string $id): string
122126 {
123127 return env ('APP_URL ' ) . '/course/view.php?id= ' . $ id ;
124128 }
129+
130+ protected function isEnabledEppn (): bool
131+ {
132+ $ eppnValue = env ('DB_EPPN ' );
133+ if (is_bool ($ eppnValue ) && $ eppnValue ) {
134+ return true ;
135+ } elseif (is_string ($ eppnValue ) && $ eppnValue == 'true ' ) {
136+ return true ;
137+ } else {
138+ return false ;
139+ }
140+ }
125141}
0 commit comments