File tree Expand file tree Collapse file tree 8 files changed +36
-0
lines changed
Expand file tree Collapse file tree 8 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,20 @@ pub struct AuthConfig {
2828 pub gitlab : GitlabAuthConfig ,
2929}
3030
31+ impl AuthConfig {
32+ /// return true if at least one configuration is enabled
33+ pub fn enabled ( & self ) -> bool {
34+ self . local . enabled || self . github . enabled || self . gitlab . enabled
35+ }
36+
37+ /// return true if at least one registration is allowed
38+ pub fn allow_registration ( & self ) -> bool {
39+ ( self . local . enabled && self . local . allow_registration )
40+ || ( self . github . enabled && self . github . allow_registration )
41+ || ( self . gitlab . enabled && self . gitlab . allow_registration )
42+ }
43+ }
44+
3145/// The authentication state, having things like OAuth clients for external authentication.
3246pub struct AuthState {
3347 /// The authentication state for the "local" strategy, if enabled.
Original file line number Diff line number Diff line change @@ -57,7 +57,10 @@ pub(crate) async fn get(
5757 let local_registration_enabled = auth. local . allow_registration ;
5858 let has_separator = local_enabled && ( github_enabled || gitlab_enabled) ;
5959
60+ let auth = & state. frontend . config . auth ;
6061 let context = json ! ( {
62+ "auth_disabled" : !auth. enabled( ) ,
63+ "registration_disabled" : !auth. allow_registration( ) ,
6164 "instance" : & state. frontend. config,
6265 "flash" : flash_message,
6366 "local_enabled" : local_enabled,
Original file line number Diff line number Diff line change @@ -55,8 +55,11 @@ pub(crate) async fn get(
5555 . limit ( 10 )
5656 . load ( conn) ?;
5757
58+ let auth = & state. frontend . config . auth ;
5859 let engine = & state. frontend . handlebars ;
5960 let context = json ! ( {
61+ "auth_disabled" : !auth. enabled( ) ,
62+ "registration_disabled" : !auth. allow_registration( ) ,
6063 "user" : user. map( |it| it. into_inner( ) ) ,
6164 "instance" : & state. frontend. config,
6265 "total_downloads" : helpers:: humanize_number( total_downloads) ,
Original file line number Diff line number Diff line change @@ -334,8 +334,11 @@ pub(crate) async fn get(
334334 chrono:: NaiveDateTime :: parse_from_str ( crate_desc. updated_at . as_str ( ) , DATETIME_FORMAT )
335335 . unwrap ( ) ;
336336
337+ let auth = & state. frontend . config . auth ;
337338 let engine = & state. frontend . handlebars ;
338339 let context = json ! ( {
340+ "auth_disabled" : !auth. enabled( ) ,
341+ "registration_disabled" : !auth. allow_registration( ) ,
339342 "user" : user. map( |it| it. into_inner( ) ) ,
340343 "instance" : & state. frontend. config,
341344 "crate" : {
Original file line number Diff line number Diff line change @@ -83,8 +83,11 @@ pub(crate) async fn get(
8383 None
8484 } ;
8585
86+ let auth = & state. frontend . config . auth ;
8687 let engine = & state. frontend . handlebars ;
8788 let context = json ! ( {
89+ "auth_disabled" : !auth. enabled( ) ,
90+ "registration_disabled" : !auth. allow_registration( ) ,
8891 "user" : user. map( |it| it. into_inner( ) ) ,
8992 "instance" : & state. frontend. config,
9093 "total_results" : total_results,
Original file line number Diff line number Diff line change @@ -83,8 +83,11 @@ pub(crate) async fn get(
8383 None
8484 } ;
8585
86+ let auth = & state. frontend . config . auth ;
8687 let engine = & state. frontend . handlebars ;
8788 let context = json ! ( {
89+ "auth_disabled" : !auth. enabled( ) ,
90+ "registration_disabled" : !auth. allow_registration( ) ,
8891 "user" : user. map( |it| it. into_inner( ) ) ,
8992 "instance" : & state. frontend. config,
9093 "total_results" : total_results,
Original file line number Diff line number Diff line change @@ -96,8 +96,11 @@ pub(crate) async fn get(
9696 None
9797 } ;
9898
99+ let auth = & state. frontend . config . auth ;
99100 let engine = & state. frontend . handlebars ;
100101 let context = json ! ( {
102+ "auth_disabled" : !auth. enabled( ) ,
103+ "registration_disabled" : !auth. allow_registration( ) ,
101104 "user" : user. map( |it| it. into_inner( ) ) ,
102105 "instance" : & state. frontend. config,
103106 "searched_text" : searched_text,
Original file line number Diff line number Diff line change 308308 </div >
309309 </form >
310310 </div >
311+ {{ #unless auth_disabled }}
311312 <div class =" navbar-login-container" >
312313 {{ #if user }}
313314 <a href =" /account/manage" class =" navbar-tag" >Manage account</a >
314315 <a href =" /account/logout" class =" navbar-tag" >Logout</a >
315316 {{ else }}
316317 <a href =" /account/login" class =" navbar-tag" >Login</a >
318+ {{ #unless registration_disabled }}
317319 <a href =" /account/register" class =" navbar-tag" >Register</a >
320+ {{ /unless }}
318321 {{ /if }}
319322 </div >
323+ {{ /unless }}
320324 <div class =" navbar-burger-container" >
321325 <label class =" navbar-burger-icon fas" for =" burger-checkbox" ></label >
322326 </div >
You can’t perform that action at this time.
0 commit comments