public async Task <IResultModel> Add(LoginLogAddModel model)
        {
            var entity = _mapper.Map <LoginLogEntity>(model);
            var result = await _repository.InsertAsync(entity);

            return(ResultModel.Result(result));
        }
示例#2
0
        public async Task <IResultModel> Login([FromBody] LoginModel model)
        {
            var log = new LoginLogAddModel();

            try
            {
                var result = await _authService.Login(model, _webConfigModel.RefreshTokenExpiredTime);

                log.Result      = result.Successful;
                log.IP          = _loginInfo.IP;
                log.BrowserInfo = _accessor.HttpContext.Request.Headers["User-Agent"];
                log.UserCode    = model.UserCode;
                log.Remark      = result.Msg;

                if (result.Successful)
                {
                    var user      = result.Data.User;
                    var loginInfo = result.Data.AuthInfo;

                    log.UserName = user.UserName;

                    var claims = new[]
                    {
                        new Claim(ClaimsName.UserId, user.Id.ToString()),
                        new Claim(ClaimsName.UserCode, user.UserCode),
                        new Claim(ClaimsName.UserName, user.UserName),
                        new Claim(ClaimsName.OrganizeId, user.OrganizeId.ToString()),
                        new Claim(ClaimsName.LoginTime, loginInfo.LoginTime.ToString()),
                        new Claim(ClaimsName.RoleIds, result.Data.RoleIds),
                        new Claim(ClaimsName.RoleCodes, result.Data.RoleCodes),
                        new Claim(ClaimsName.RoleNames, result.Data.RoleNames)
                    };


                    var token = _jwtHandler.Build(claims, loginInfo.RefreshToken);
                    return(ResultModel.Success(token));
                }

                return(ResultModel.Failed(result.Msg));
            }
            catch (Exception ex)
            {
                log.Remark = ex.Message;
                return(ResultModel.Failed(ex.Message));
            }
            finally
            {
                await _loginLogService.Add(log);
            }
        }
 public Task <IResultModel> Add(LoginLogAddModel model)
 {
     return(_service.Add(model));
 }