public ActionResult <string> Authorize(string judgeId, string pass, string serviceId) { var currentTour = (from ct in _dbContext.CurrentTour select ct.Current).Last(); var judge = (currentTour == 0 ? (from tJudge in _dbContext.JudgesCv where tJudge.JudgeId == judgeId select tJudge).OfType <RROJudge>() : (from tJudge in _dbContext.JudgesFin where tJudge.JudgeId == judgeId select tJudge).OfType <RROJudge>()).FirstOrDefault(); if (judge == null) { return(BadRequest(AuthenticationError.UserNotFound)); } if (currentTour == 0) { if (!((RROJudgeCv)judge).PassHash.Equals(pass)) { return(BadRequest(AuthenticationError.IncorrectPassword)); } } else { if (!((RROJudgeFin)judge).PassHash.Equals(pass)) { return(BadRequest(AuthenticationError.IncorrectPassword)); } } var payload = JudgePayload.Create(judge, currentTour, serviceId); var service = (from tService in _dbContext.Services where tService.ServiceId == payload.Service select tService).FirstOrDefault(); if (service == null) { return(BadRequest(AuthenticationError.UnknownService)); } var tokenCv = JWTJudgeProvider.CreateToken(payload); return(tokenCv); }
public IActionResult Authorize(string judgeId, string pass, string serviceId) { var currentTour = (from ct in _dbContext.CurrentTour select ct.Current).Last(); switch (currentTour) { case 0: var getJudgeCv = from judge in _dbContext.JudgesCv where judge.JudgeId == judgeId select judge; if (!getJudgeCv.Any()) { return(BadRequest("User not found")); } var judgeCv = getJudgeCv.First(); if (!judgeCv.PassHash.Equals(pass)) { return(BadRequest("Incorrect password")); } var payloadCv = JudgePayload.Create(judgeCv, 0, serviceId); var serviceCv = (from service in _dbContext.Services where service.ServiceId == payloadCv.Service select service).FirstOrDefault(); if (serviceCv == null) { return(BadRequest("Unknown service")); } var tokenCv = JWTJudgeProvider.CreateToken(payloadCv); JWTJudgeFactory.AddToken(judgeCv.JudgeId, tokenCv, true); return(Ok(tokenCv)); case 1: var getJudgeFin = from judge in _dbContext.JudgesFin where judge.JudgeId == judgeId select judge; if (!getJudgeFin.Any()) { return(BadRequest("User not found")); } var judgeFin = getJudgeFin.First(); if (!judgeFin.PassHash.Equals(pass)) { return(BadRequest("Incorrect password")); } var payloadFin = JudgePayload.Create(judgeFin, 1, serviceId); var tokenFin = JWTJudgeProvider.CreateToken(payloadFin); JWTJudgeFactory.AddToken(judgeFin.JudgeId, tokenFin, true); return(Ok(tokenFin)); default: return(BadRequest("Server error")); } }