@@ -30,8 +30,7 @@ public async Task<IActionResult> Login([FromServices] IAuthenticationSchemeProvi
30
30
31
31
var silkierScheme = await schemes . GetSchemeAsync ( authenticationOptions . AuthScheme ) ;
32
32
33
- if ( string . IsNullOrEmpty ( authenticationOptions . UserName ) ||
34
- string . IsNullOrEmpty ( authenticationOptions . UserPassword ) )
33
+ if ( authenticationOptions . Authenticate == null )
35
34
{
36
35
foreach ( var userClaim in HttpContext . User . Claims )
37
36
{
@@ -42,8 +41,7 @@ public async Task<IActionResult> Login([FromServices] IAuthenticationSchemeProvi
42
41
! HttpContext . User . HasClaim ( authenticationOptions . SilkierQuartzClaim ,
43
42
authenticationOptions . SilkierQuartzClaimValue ) )
44
43
{
45
- await SignIn ( false ) ;
46
-
44
+ await SignIn ( false , SilkierQuartzAuthenticationOptions . DefaultUserName , SilkierQuartzAuthenticationOptions . DefaultPassword ) ;
47
45
return RedirectToAction ( nameof ( SchedulerController . Index ) , nameof ( Scheduler ) ) ;
48
46
}
49
47
else
@@ -70,19 +68,16 @@ public async Task<IActionResult> Login([FromServices] IAuthenticationSchemeProvi
70
68
public async Task < IActionResult > Login ( [ FromForm ] AuthenticateViewModel request )
71
69
{
72
70
var form = HttpContext . Request . Form ;
73
-
74
- if ( string . Compare ( request . UserName , authenticationOptions . UserName ,
75
- StringComparison . InvariantCulture ) != 0 ||
76
- string . Compare ( request . Password , authenticationOptions . UserPassword ,
77
- StringComparison . InvariantCulture ) != 0 )
71
+ if ( ! authenticationOptions . Authenticate ( request . UserName , request . Password ) )
78
72
{
79
73
request . IsLoginError = true ;
80
74
return View ( request ) ;
81
75
}
82
-
83
- await SignIn ( request . IsPersist ) ;
84
-
85
- return RedirectToAction ( nameof ( SchedulerController . Index ) , nameof ( Scheduler ) ) ;
76
+ else
77
+ {
78
+ await SignIn ( request . IsPersist , request . UserName , request . Password ) ;
79
+ return RedirectToAction ( nameof ( SchedulerController . Index ) , nameof ( Scheduler ) ) ;
80
+ }
86
81
}
87
82
88
83
[ HttpGet ]
@@ -93,17 +88,17 @@ public async Task<IActionResult> Logout()
93
88
return RedirectToAction ( nameof ( Login ) ) ;
94
89
}
95
90
96
- private async Task SignIn ( bool isPersistentSignIn )
91
+ private async Task SignIn ( bool isPersistentSignIn , string userName , string password )
97
92
{
98
93
var claims = new List < Claim >
99
94
{
100
- new Claim ( ClaimTypes . NameIdentifier , string . IsNullOrEmpty ( authenticationOptions . UserName )
95
+ new Claim ( ClaimTypes . NameIdentifier , string . IsNullOrEmpty ( userName )
101
96
? "SilkierQuartzAdmin"
102
- : authenticationOptions . UserName ) ,
97
+ : SilkierQuartzAuthenticationOptions . DefaultUserName ) ,
103
98
104
- new Claim ( ClaimTypes . Name , string . IsNullOrEmpty ( authenticationOptions . UserPassword )
99
+ new Claim ( ClaimTypes . Name , string . IsNullOrEmpty ( password )
105
100
? "SilkierQuartzPassword"
106
- : authenticationOptions . UserPassword ) ,
101
+ : SilkierQuartzAuthenticationOptions . DefaultPassword ) ,
107
102
108
103
new Claim ( authenticationOptions . SilkierQuartzClaim , authenticationOptions . SilkierQuartzClaimValue )
109
104
} ;
0 commit comments