Esempio n. 1
0
        public AccountController(TimetrackerContext dbContext)
        {
            _dbContext = dbContext;

            _jsonOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };
        }
Esempio n. 2
0
        public RoleController(TimetrackerContext context)
        {
            _context = context;

            _jsonOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };
        }
        public ProjectController(TimetrackerContext dbcontext, IHubContext <TrackingHub> hub)
        {
            _dbContext = dbcontext;

            _jsonOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };
            _hub = new Lazy <IHubContext <TrackingHub> >(hub);
        }
Esempio n. 4
0
        public static async Task GenerateToken(string id, Token user, TimetrackerContext context, bool isNew = false)
        {
            var claims = new List <Claim>
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, id)
            };

            var claimsIdentity = new ClaimsIdentity(claims, "Token",
                                                    ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);

            var now       = DateTime.UtcNow;
            var expiredIn = now.Add(tokenDurability);
            var jwt       = new JwtSecurityToken(
                issuer: TimetrackerAuthorizationOptions.ISSUER,
                audience: TimetrackerAuthorizationOptions.AUDIENCE,
                notBefore: now,
                claims: claimsIdentity.Claims,
                expires: expiredIn,
                signingCredentials: new SigningCredentials(
                    TimetrackerAuthorizationOptions.GetSymmetricSecurityKey(),
                    SecurityAlgorithms.HmacSha256)
                );

            var access_token  = new JwtSecurityTokenHandler().WriteToken(jwt);
            var refresh_token = Guid.NewGuid().ToString().Replace("-", "");

            user.AccessToken      = access_token;
            user.RefreshToken     = refresh_token;
            user.TokenExpiredDate = expiredIn;

            if (isNew)
            {
                await context.AddAsync(user)
                .ConfigureAwait(false);
            }

            await context.SaveChangesAsync(true)
            .ConfigureAwait(false);
        }
Esempio n. 5
0
 public TimeTrackerService()
 {
     _context = new TimetrackerContext();
 }
Esempio n. 6
0
 public TaskController(TimetrackerContext context, IHubContext <TrackingHub> hub)
 {
     _context = context;
     _hub     = new Lazy <IHubContext <TrackingHub> >(hub);
 }
 public WorktrackController(TimetrackerContext context)
 {
     _context = context;
 }
Esempio n. 8
0
 public TrackingHub(TimetrackerContext dbContext)
 {
     _dbContext = dbContext;
 }