Example #1
0
        public async Task <IActionResult> PutBotTable(int id, BotsTable botTable)
        {
            if (id != botTable.BotId)
            {
                return(BadRequest());
            }

            _context.Entry(botTable).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BotTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutPlatformGroupTable(int id, PlatformTable platformGroupTable)
        {
            if (id != platformGroupTable.PlatformId)
            {
                return(BadRequest());
            }

            _context.Entry(platformGroupTable).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlatformGroupTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <AuthenticationResult> AuthenticateAsync(UserTable user)
        {
            // authentication successful so generate jwt token
            AuthenticationResult authenticationResult = new AuthenticationResult();
            var tokenHandler = new JwtSecurityTokenHandler();

            try
            {
                var key = Encoding.ASCII.GetBytes(_appSettings.JwtSettings.Secret);


                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.UserData,
                                  "IsValid", ClaimValueTypes.String, "(local)")
                    }),
                    Expires            = DateTime.UtcNow.Add(_appSettings.JwtSettings.TokenLifetime),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                };
                var token = tokenHandler.CreateToken(tokenDescriptor);
                authenticationResult.Token = tokenHandler.WriteToken(token);
                var refreshToken = new RefreshTokenTable
                {
                    Token        = Guid.NewGuid().ToString(),
                    JwtId        = token.Id,
                    UserId       = user.UserId,
                    CreationDate = DateTime.UtcNow,
                    ExpiryDate   = DateTime.UtcNow.AddMonths(6)
                };
                await _context.RefreshTokenTables.AddAsync(refreshToken);

                await _context.SaveChangesAsync();

                authenticationResult.RefreshToken = refreshToken.Token;
                authenticationResult.Success      = true;

                return(authenticationResult);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }