Exemplo n.º 1
0
        public async Task <IResponseOutput> Login(AuthLoginInput input)
        {
            var sw = new Stopwatch();

            sw.Start();
            var res = (await _authService.LoginAsync(input)) as IResponseOutput;

            sw.Stop();

            #region 添加登录日志
            var loginLogAddInput = new LoginLogAddInput()
            {
                CreatedUserName     = input.UserName,
                ElapsedMilliseconds = sw.ElapsedMilliseconds,
                Status = res.Success,
                Msg    = res.Msg
            };

            AuthLoginOutput user = null;
            if (res.Success)
            {
                user = (res as IResponseOutput <AuthLoginOutput>).Data;
                loginLogAddInput.CreatedUserId = user.Id;
                loginLogAddInput.RealName      = user.Name;
            }

            await _loginLogService.AddAsync(loginLogAddInput);

            #endregion

            if (!res.Success)
            {
                return(res);
            }

            #region 生成token信息
            var token = _userToken.Build(new[]
            {
                new Claim(ClaimAttributes.UserId, user.Id.ToString()),
                new Claim(ClaimAttributes.UserName, user.UserName),
                new Claim(ClaimAttributes.UserRealName, user.Name)
            });
            #endregion

            return(ResponseOutput.Ok(new { token }));
        }
Exemplo n.º 2
0
        public async Task <IResponseOutput> Login(AuthLoginInput input)
        {
            var sw = new Stopwatch();

            sw.Start();
            var res = await _authService.LoginAsync(input);

            sw.Stop();

            #region 添加登录日志

            var loginLogAddInput = new LoginLogAddInput()
            {
                CreatedUserName     = input.UserName,
                ElapsedMilliseconds = sw.ElapsedMilliseconds,
                Status = res.Success,
                Msg    = res.Msg
            };

            ResponseOutput <AuthLoginOutput> output = null;
            if (res.Success)
            {
                output = (res as ResponseOutput <AuthLoginOutput>);
                var user = output.Data;
                loginLogAddInput.CreatedUserId = user.Id;
                loginLogAddInput.NickName      = user.NickName;
                loginLogAddInput.TenantId      = user.TenantId;
            }

            await _loginLogService.AddAsync(loginLogAddInput);

            #endregion 添加登录日志

            if (!res.Success)
            {
                return(res);
            }

            return(GetToken(output));
        }