public IEnumerable <string> Get(string code, string state)
        {
            _logger.LogInformation("from get receiving a code");
            if (code == null)
            {
                _logger.LogInformation("code was null");
            }
            else
            {
                using (StreamWriter writer = new StreamWriter("./code"))
                {
                    writer.WriteLine(code);
                    _logger.LogInformation("code stored in txt, done!");
                    writer.Close();
                }
                using (var context = new CodesContext())
                {
                    var result = context.Codes.AsNoTracking().FirstOrDefault(x => x.secret_key == state);
                    if (result == null)
                    {
                        _logger.LogInformation("there is not auth for this code request yet, or invalid state");
                    }
                    else
                    {
                        result.code = code;
                        context.Entry(result).State = EntityState.Modified;

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!context.Codes.Any(e => e.Id == result.Id))
                            {
                                return(new string[] { "NOT FOUND" });
                            }
                        }
                    }
                }
            }
            return(new string[] { });
        }
Esempio n. 2
0
 public AuthController(CodesContext context, ILogger <AuthCallbackController> logger)
 {
     _context      = context;
     hashAlgorithm = SHA256.Create();
     _logger       = logger;
 }
 public CodesController(CodesContext codesContext)
 {
     _codesContext = codesContext;
 }