Beispiel #1
0
        public virtual async Task <StatusBuilder> LoginAsync(LoginDetails details)
        {
            var output  = new StatusBuilder();
            var results = new LoginResults();

            results.User = await _userManager.FindByNameAsync(details.Username);

            if (results.User != null)
            {
                var passwordValid = await _userManager.CheckPasswordAsync(results.User, details.Password);

                if (passwordValid)
                {
                    results.Result = await _signInManager.PasswordSignInAsync(details.Username, details.Password, true, lockoutOnFailure : false);
                }
                else
                {
                    // It's an invalid password, but include both username and password to lower hacking attempts
                    output.RecordFailure("Invalid Password or Username");
                }
            }
            else
            {
                // It's an invalid username, but include both username and password to lower hacking attempts
                output.RecordFailure("Invalid Username or Password");
            }

            output.SetData(results);

            return(output);
        }
        public async Task <StatusBuilder> Login([FromBody] LoginDetails model)
        {
            var results = this.HandleModelState();

            if (results.IsSuccessful)
            {
                results = await _accountService.LoginAsync(model);
            }

            return(results);
        }