示例#1
0
        public async Task <IActionResult> LoginAsync([FromBody] LoginUserCommeds command)
        {
            await DispatchCommandAsync(command);

            var dto = GetCachedObject <JwtDto>(command.Id);

            return(Ok(dto));
        }
示例#2
0
        public async Task HandleAsync(LoginUserCommeds command)
        {
            var user = await _swizzerContext.Users.FirstOrDefaultAsync(x => x.Email == command.Email);

            if (user == null)
            {
                throw new SwizzerServerException(ErrorCode.InvalidParameter);
            }

            var hash = _seciurityService.GetHash(command.Password, user.Salt);

            if (hash != user.Hash)
            {
                throw new SwizzerServerException(ErrorCode.InvalidParameter);
            }
            var userDto = _swizzerMapper.MapTo <UserDto>(user);
            var jwt     = _seciurityService.GetJwt(userDto);

            jwt.Id = command.Id;

            _cacheService.Set(jwt);
        }