예제 #1
0
        public async Task <ActionResult <AcceptLoginResponse> > Login(Login model)
        {
            var loginInfo = await _hydra.GetLoginInfo(model.LoginChallenge);

            if (loginInfo.Skip)
            {
                return(await _hydra.AcceptLogin(new AcceptLoginRequest(loginInfo.Subject), model.LoginChallenge));
            }
            var appuser = await _userManager.FindByEmailAsync(model.Username);

            if (appuser == null)
            {
                appuser = await _userManager.FindByNameAsync(model.Username);
            }
            if (appuser == null)
            {
                return(NotFound());
            }
            var valid = await _userManager.CheckPasswordAsync(appuser, model.Password);

            if (!valid)
            {
                return(BadRequest(IDPErrors.InvalidCredential));
            }
            return(await _hydra.AcceptLogin(new AcceptLoginRequest(appuser.Id), model.LoginChallenge));
        }
예제 #2
0
        public async Task <ActionResult <RedirectResponse> > Login(Login model)
        {
            var loginInfo = await _hydra.GetLoginInfo(model.LoginChallenge);

            if (loginInfo.Skip)
            {
                return(await _hydra.AcceptLogin(new AcceptLoginRequest(loginInfo.Subject), model.LoginChallenge));
            }
            var appuser = await _userManager.FindByEmailAsync(model.Username);

            if (appuser == null)
            {
                appuser = await _userManager.FindByNameAsync(model.Username);
            }
            if (appuser == null)
            {
                return(NotFound());
            }
            var valid = await _userManager.CheckPasswordAsync(appuser, model.Password);

            if (!valid)
            {
                return(BadRequest(IDPErrors.InvalidCredential));
            }
            var response = await _hydra.AcceptLogin(new AcceptLoginRequest(appuser.UserName), model.LoginChallenge);

            var signInLog = new SignInLog
            {
                UserName        = appuser.UserName,
                IpAddress       = Request.Headers["X-Real-IP"],
                UserAgent       = Request.Headers["User-Agent"],
                AcceptedLoginAt = DateTimeOffset.Now,
                LoginChallenge  = model.LoginChallenge
            };

            _db.Add(signInLog);
            await _db.SaveChangesAsync();

            return(response);
        }