예제 #1
0
        protected virtual async Task ReplaceEmailToUsernameOfInputIfNeeds(UserLoginInfo login)
        {
            if (!ValidationHandler.IsValidEmailAddress(login.UserNameOrEmailAddress))
            {
                return;
            }

            var userByUsername = await _userManager.FindByNameAsync(login.UserNameOrEmailAddress);

            if (userByUsername != null)
            {
                return;
            }

            var userByEmail = await _userManager.FindByEmailAsync(login.UserNameOrEmailAddress);

            if (userByEmail == null)
            {
                return;
            }

            if (userByEmail.EmailConfirmed == false)
            {
                throw new UserFriendlyException("邮件未激活确认,无法使用邮件进行登录!");
            }

            login.UserNameOrEmailAddress = userByEmail.UserName;
        }
예제 #2
0
        public async Task <IActionResult> Index(UserLoginInfo login)
        {
            var dico = await DiscoveryClient.GetAsync(_configuration["AuthServer:Authority"]);

            if (dico.IsError)
            {
                Console.WriteLine(dico.Error);
                return(Json(new { code = 0, data = dico.Error }));
            }

            await ReplaceEmailToUsernameOfInputIfNeeds(login);

            var           tokenClient = new TokenClient(dico.TokenEndpoint, _configuration["AuthServer:ClientId"], _configuration["AuthServer:ClientSecret"]);
            TokenResponse tokenresp   = await tokenClient.RequestResourceOwnerPasswordAsync(login.UserNameOrEmailAddress, login.Password, "IdentityService BackendAdminAppGateway AuditLogging BaseManagement OrganizationService");

            if (tokenresp.IsError)
            {
                Console.WriteLine(tokenresp.Error);
                return(Json(new { code = 0, data = tokenresp.ErrorDescription, message = tokenresp.Error }));
            }

            return(Json(new { code = 1, data = tokenresp.Json }));
        }