예제 #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request">请求</param>
        public async Task <SignInWithTokenResult> SignInAsync(AdminLoginRequest request)
        {
            var user = await GetUserAsync(request.UserName);

            if (user == null)
            {
                return new SignInWithTokenResult {
                           Message = "用户名不存在", State = SignInState.Failed
                }
            }
            ;
            await AddClaimsToUserAsync(user, ApplicationCode.Admin);

            var result = await SignInManager.SignInAsync(user, request.Password);

            user.AddLoginLog(Web.IP, Web.Browser);
            await MessageEventBus.PublishAsync(new UserLoginMessageEvent(new UserLoginMessage
            {
                UserId = user.Id,
                Name = user.Nickname,
                Ip = Web.IP,
                UserAgent = Web.Browser
            }, false));

            await UnitOfWork.CommitAsync();

            return(await GetLoginResultAsync(user, result, ApplicationCode.Admin));
        }
예제 #2
0
        /// <summary>
        /// 获取登录结果
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="signInResult">登录结果</param>
        /// <param name="applicationCode">应用程序编码</param>
        private async Task <SignInWithTokenResult> GetLoginResultAsync(User user, SignInResult signInResult, string applicationCode)
        {
            if (signInResult.State == SignInState.Failed)
            {
                return new SignInWithTokenResult {
                           UserId = signInResult.UserId, State = signInResult.State, Message = signInResult.Message
                }
            }
            ;
            await MessageEventBus.PublishAsync(new UserLoginMessageEvent(new UserLoginMessage
            {
                UserId = user.Id,
                Name = user.Nickname,
                Ip = Web.IP,
                UserAgent = Web.Browser
            }));

            var result = await TokenBuilder.CreateAsync(user.GetClaims().ToDictionary(x => x.Type, x => x.Value));

            return(new SignInWithTokenResult
            {
                UserId = signInResult.UserId,
                State = signInResult.State,
                Message = signInResult.Message,
                Token = result
            });
        }
예제 #3
0
        public async Task <IActionResult> TestMessageAsync([FromBody] TestMessage request)
        {
            await MessageEventBus.PublishAsync(new TestMessageEvent1(request));

            await UnitOfWork.CommitAsync();

            return(Success());
        }
예제 #4
0
        //[AntiDuplicateRequest]
        public async Task <IActionResult> TestMessageAsync([FromBody] TestMessage request)
        {
            Log.Info("测试日志消息Begin");
            await MessageEventBus.PublishAsync(new TestMessageEvent1(request, request.Send));

            if (request.NeedCommit)
            {
                await UnitOfWork.CommitAsync();
            }
            Log.Info("测试日志消息End");
            return(Success());
        }
예제 #5
0
        static async Task CommonPublish()
        {
            var eventBus    = new MessageEventBus();
            var tokenSource = new CancellationTokenSource();
            var i           = 0;

            while (!tokenSource.IsCancellationRequested)
            {
                await eventBus.PublishAsync("test", new { Time = DateTime.Now, Index = i }, "");

                i++;
            }
        }
예제 #6
0
        public async Task <IActionResult> TestMessageAsync([FromBody] TestMessage request)
        {
            Logger.LogInformation($"测试Logger消息{nameof(ILogger<TestController>)} - 0: {request.Id}");
            OtherLog
            .Message($"测试Logger消息{nameof(ILog<TestController>)} - 0: {request.Id}")
            .LogInformation();
            Log.Info("测试日志消息Begin");
            await MessageEventBus.PublishAsync(new TestMessageEvent1(request, request.Send));

            if (request.NeedCommit)
            {
                await UnitOfWork.CommitAsync();
            }
            Log.Info("测试日志消息End");
            return(Success());
        }
예제 #7
0
        public async Task TestMessage1Async(TestMessage message, [FromCap] CapHeader header)
        {
            if (message.ThrowException)
            {
                throw new NotImplementedException("主动触发,暂未生效");
            }
            Log.Info($"测试一波CAP消息 - 0: {message.Id}");
            Logger.LogDebug($"测试一波CAP消息 - 1: {message.Id}");
            var log = Bing.Logs.Log.GetLog(nameof(TestMessageEventHandler));

            log.Debug($"测试一波CAP消息 - 1 - 1: {message.Id}");
            Debug.WriteLine(message.Id);
            await MessageEventBus.PublishAsync(new TestMessageEvent2(message, message.Send));

            if (message.NeedCommit)
            {
                await UnitOfWork.CommitAsync();
            }
        }
예제 #8
0
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="request">创建请求参数</param>
        public async Task <Guid> CreateAsync(CreateRoleRequest request)
        {
            var role = ToEntity(request);

            role.Type = "Role";
            await RoleManager.CreateAsync(role);

            await MessageEventBus.PublishAsync(new CreateRoleMessageEvent(
                                                   new CreateRoleMessage()
            {
                Code = $"event:{role.Code}",
                Name = $"event:{role.Name}",
                Type = $"event:{role.Type}"
            }));

            await UnitOfWork.CommitAsync();

            return(role.Id);
        }
예제 #9
0
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="request">创建请求参数</param>
        public async Task <Guid> CreateAsync(CreateRoleRequest request)
        {
            var role = ToEntity(request);

            role.Type = "Role";
            await RoleManager.CreateAsync(role);

            await MessageEventBus.PublishAsync(new CreateRoleMessageEvent(
                                                   new CreateRoleMessage()
            {
                Code = $"event:{role.Code}",
                Name = $"event:{role.Name}",
                Type = $"event:{role.Type}"
            }));

            await SqlExecutor.ExecuteSqlAsync("insert into Systems.Test(Id, Name) Values(@Id, @Name)",
                                              new { Id = Guid.NewGuid(), Name = "隔壁老王" });

            await UnitOfWork.CommitAsync();

            return(role.Id);
        }