Beispiel #1
0
        public async Task <SignInResult> SignIn(string userNameOrEmail, string password)
        {
            var user = userNameOrEmail.Contains("@") ?
                       await _identityProvider.GetByEmail(userNameOrEmail) :
                       await _identityProvider.GetByUserName(userNameOrEmail);

            if (user == default(User))
            {
                return(new SignInResult
                {
                    Succeeded = false
                });
            }

            var result = await _identityManager.PasswordSignIn(user.UserName, password, true, true);

            if (!result.Succeeded)
            {
                return(result);
            }

            var claims = new List <Claim>
            {
                new Claim("FirstName", user.FirstName),
                new Claim("LastName", user.LastName)
            };

            var roles = await _identityManager.GetUserRoles(user.UserName);

            foreach (var role in roles)
            {
                claims.Add(new Claim(ClaimTypes.Role, role));
            }

            await _identityManager.AddClaims(user.UserName, claims);

            return(result);
        }