Beispiel #1
0
        public override async Task <MangoUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (loginProvider == null)
            {
                throw new ArgumentNullException(nameof(loginProvider));
            }
            if (providerKey == null)
            {
                throw new ArgumentNullException(nameof(providerKey));
            }

            ExternalLoginEntity exl = await _userDbContext.ExternalLogins.FirstOrDefaultAsync(ex => ex.LoginProvider == loginProvider && ex.ProviderKey == providerKey);

            if (exl == null)
            {
                return(null);
            }
            UserEntity userEntity = await _userDbContext.MangoUsers.FirstOrDefaultAsync(ex => ex.Id == exl.UserId);

            if (userEntity == null)
            {
                throw new UserNotFoundException($"method:{nameof(FindByLoginAsync)},没有找到id为:{exl.UserId}的用户");
            }
            return(MEConversion.UserE2M(userEntity));
        }
Beispiel #2
0
        public override async Task AddLoginAsync(MangoUser user, UserLoginInfo login, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (login == null)
            {
                throw new ArgumentNullException(nameof(login));
            }

            var mangouser = await FindByNameEntityAsync(user.UserName);

            if (mangouser != null)
            {
                ExternalLoginEntity externalLogin = MEConversion.ExternalLoginM2E(login);
                externalLogin.UserId = mangouser.Id;

                await _userDbContext.ExternalLogins.AddAsync(externalLogin);
            }
        }