Beispiel #1
0
        public async Task <ActionResult <UserDto> > Register(RegisterDto registerDto)
        {
            if (await UserExists(registerDto.Username))
            {
                return(BadRequest("Username is taken"));
            }

            using var hmac = new HMACSHA512();

            var user = new AppUser
            {
                UserName     = registerDto.Username.ToLower(),
                PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(registerDto.Password)),
                PasswordSalt = hmac.Key
            };

            _context.Users.Add(user);

            await _context.SaveChangesAsync();

            return(new UserDto
            {
                Username = user.UserName,
                Token = _tokenService.CreateToken(user)
            });
        }
Beispiel #2
0
        public async Task <ActionResult> Create([FromBody] CreateFeedModel createFeedModel)
        {
            var existing = await _rssFeedRepository.GetByUriAsync(createFeedModel.Uri);

            if (existing != null)
            {
                return(Conflict());
            }

            var rssFeed = await _rssFeedRepository.CreateAsync(createFeedModel.Uri);

            if (await _refreshRssFeed.RefreshAsync(rssFeed, CancellationToken.None))
            {
                await _context.SaveChangesAsync();
            }

            return(Created(Url.ActionLink(nameof(Get), values: new { id = rssFeed.Id }), rssFeed));
        }