Skip to content

Instantly share code, notes, and snippets.

View CoskunKurtuldu's full-sized avatar

Coşkun Kurtuldu CoskunKurtuldu

View GitHub Profile
class Program
{
static void Main(string[] args)
{
var game = Game.CreateGame();
game.StartGame();
Debug.WriteLine("Text here");
}
}
version: '3.1'
services:
elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.2
ports:
- 9200:9200
volumes:
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "1s",
"PeriodTimespan": 1,
"Limit": 1
},
{
"Routes": [
//product api config
{
"DownstreamPathTemplate": "/api/product/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44336
using Microsoft.Extensions.DependencyInjection;
using MusicMarket.Api.Settings;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using System;
using Microsoft.AspNetCore.Builder;
namespace MusicMarket.Api.Extensions
{
private string GenerateJwt(User user, IList<string> roles)
{
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
new Claim(ClaimTypes.Name, user.UserName),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
};
[HttpPost("User/{userEmail}/Role")]
public async Task<IActionResult> AddUserToRole(string userEmail, [FromBody] string roleName)
{
var user = _userManager.Users.SingleOrDefault(u => u.UserName == userEmail);
var result = await _userManager.AddToRoleAsync(user, roleName);
if (result.Succeeded)
{
return Ok();
[HttpPost("Roles")]
public async Task<IActionResult> CreateRole(string roleName)
{
if(string.IsNullOrWhiteSpace(roleName))
{
return BadRequest("Role name should be provided.");
}
var newRole = new Role
{
[HttpPost("SignIn")]
public async Task<IActionResult> SignIn(UserLoginDTO userLoginDto)
{
var user = _userManager.Users.SingleOrDefault(u => u.UserName == userLoginDto.Email);
if (user is null)
{
return NotFound("User not found");
}
var userSigninResult = await _userManager.CheckPasswordAsync(user, userLoginDto.Password);
namespace MyMusic.Api.Resources
{
public class UserLoginDTO
{
public string Email { get; set; }
public string Password { get; set; }
}
}