@ -71,9 +71,25 @@ namespace PlexRequests.UI.Modules
if ( landingCheck )
if ( landingCheck )
{
{
var landingSettings = await LandingPageSettings . GetSettingsAsync ( ) ;
var landingSettings = await LandingPageSettings . GetSettingsAsync ( ) ;
if ( landingSettings . Enabled )
if ( landingSettings . Enabled )
{
{
return View [ "Landing/Index" , landingSettings ] ;
if ( landingSettings . BeforeLogin )
{
var model = new LandingPageViewModel
{
Enabled = landingSettings . Enabled ,
Id = landingSettings . Id ,
EnabledNoticeTime = landingSettings . EnabledNoticeTime ,
NoticeEnable = landingSettings . NoticeEnable ,
NoticeEnd = landingSettings . NoticeEnd ,
NoticeMessage = landingSettings . NoticeMessage ,
NoticeStart = landingSettings . NoticeStart ,
ContinueUrl = landingSettings . BeforeLogin ? $"userlogin" : $"search"
} ;
return View [ "Landing/Index" , model ] ;
}
}
}
}
}
var settings = await AuthService . GetSettingsAsync ( ) ;
var settings = await AuthService . GetSettingsAsync ( ) ;
@ -84,7 +100,7 @@ namespace PlexRequests.UI.Modules
{
{
var dateTimeOffset = Request . Form . DateTimeOffset ;
var dateTimeOffset = Request . Form . DateTimeOffset ;
var username = Request . Form . username . Value ;
var username = Request . Form . username . Value ;
Log . Debug ( "Username \"{0}\" attempting to login" , username ) ;
Log . Debug ( "Username \"{0}\" attempting to login" , username ) ;
if ( string . IsNullOrWhiteSpace ( username ) )
if ( string . IsNullOrWhiteSpace ( username ) )
{
{
return Response . AsJson ( new JsonResponseModel { Result = false , Message = "Incorrect User or Password" } ) ;
return Response . AsJson ( new JsonResponseModel { Result = false , Message = "Incorrect User or Password" } ) ;
@ -107,7 +123,7 @@ namespace PlexRequests.UI.Modules
password = Request . Form . password . Value ;
password = Request . Form . password . Value ;
}
}
if ( settings . UserAuthentication & & settings . UsePassword ) // Authenticate with Plex
if ( settings . UserAuthentication & & settings . UsePassword ) // Authenticate with Plex
{
{
Log . Debug ( "Need to auth and also provide pass" ) ;
Log . Debug ( "Need to auth and also provide pass" ) ;
@ -127,7 +143,7 @@ namespace PlexRequests.UI.Modules
}
}
}
}
}
}
else if ( settings . UserAuthentication ) // Check against the users in Plex
else if ( settings . UserAuthentication ) // Check against the users in Plex
{
{
Log . Debug ( "Need to auth" ) ;
Log . Debug ( "Need to auth" ) ;
authenticated = CheckIfUserIsInPlexFriends ( username , settings . PlexAuthToken ) ;
authenticated = CheckIfUserIsInPlexFriends ( username , settings . PlexAuthToken ) ;
@ -138,7 +154,7 @@ namespace PlexRequests.UI.Modules
}
}
Log . Debug ( "Friends list result = {0}" , authenticated ) ;
Log . Debug ( "Friends list result = {0}" , authenticated ) ;
}
}
else if ( ! settings . UserAuthentication ) // No auth, let them pass!
else if ( ! settings . UserAuthentication ) // No auth, let them pass!
{
{
Log . Debug ( "No need to auth" ) ;
Log . Debug ( "No need to auth" ) ;
authenticated = true ;
authenticated = true ;
@ -153,12 +169,22 @@ namespace PlexRequests.UI.Modules
Session [ SessionKeys . ClientDateTimeOffsetKey ] = ( int ) dateTimeOffset ;
Session [ SessionKeys . ClientDateTimeOffsetKey ] = ( int ) dateTimeOffset ;
return Response . AsJson ( authenticated
if ( ! authenticated )
? new JsonResponseModel { Result = true }
{
: new JsonResponseModel { Result = false , Message = "Incorrect User or Password" } ) ;
return Response . AsJson ( new JsonResponseModel { Result = false , Message = "Incorrect User or Password" } ) ;
}
var landingSettings = LandingPageSettings . GetSettings ( ) ;
if ( landingSettings . Enabled )
{
if ( ! landingSettings . BeforeLogin )
return Response . AsJson ( new JsonResponseModel { Result = true , Message = "landing" } ) ;
}
return Response . AsJson ( new JsonResponseModel { Result = true , Message = "search" } ) ;
}
}
private Response Logout ( )
private Response Logout ( )
{
{
@ -167,8 +193,8 @@ namespace PlexRequests.UI.Modules
{
{
Session . Delete ( SessionKeys . UsernameKey ) ;
Session . Delete ( SessionKeys . UsernameKey ) ;
}
}
return Context . GetRedirect ( ! string . IsNullOrEmpty ( BaseUrl )
return Context . GetRedirect ( ! string . IsNullOrEmpty ( BaseUrl )
? $"~/{BaseUrl}/userlogin"
? $"~/{BaseUrl}/userlogin"
: "~/userlogin" ) ;
: "~/userlogin" ) ;
}
}