public async Task <IActionResult> ApplicantIsAuthorized( [FromQuery] string apikey, [FromBody] ApplicationAuth applicationAuth, [FromHeader(Name = "jwttoken")] string jwttoken, [FromHeader(Name = "conference_id")] int conference_id) { if (this.auth.KeyIsValid(apikey) && this.jwtService.PermissionLevelValid(jwttoken, "user")) { var authForConf = this._context.ApplicationAuth.Where(a => a.Conference_ID == conference_id && a.Council_ID == applicationAuth.Council_ID && a.Password == applicationAuth.Password && a.Used == false).FirstOrDefault(); if (authForConf == null) { var authForConfOtherKey = this._context.ApplicationAuth.Where(a => a.Conference_ID == conference_id && a.Council_ID == 0 && a.Password == applicationAuth.Password && a.Used == false).FirstOrDefault(); if (authForConfOtherKey == null) { return(this.Ok(new { PasswordFound = false, Priority = 0 })); } return(this.Ok(new { PasswordFound = true, Prioriy = authForConfOtherKey.Priority, IsOtherKey = true })); } else { return(this.Ok(new { PasswordFound = true, Prioriy = authForConf.Priority })); } } return(this.Unauthorized()); }
public async Task <IActionResult> GeneratePasswordsForCouncils( [FromHeader(Name = "jwttoken")] string jwttoken, [FromHeader(Name = "conference_id")] int conference_id, [FromBody] OtherKeys otherKeys, [FromQuery] string apikey) { if (this.jwtService.PermissionLevelValid(jwttoken, "admin") && this.auth.KeyIsValid(apikey)) { if (this._context.ApplicationAuth.Any(aa => aa.Conference_ID == conference_id)) { return(this.NoContent()); } else { var councils = this._context.Council.Where(c => c.Invalid == false).ToList(); // List<ApplicationAuth> appAuth = new List<ApplicationAuth>(); foreach (Council currentCouncil in councils) { ApplicationAuth one = new ApplicationAuth { Council_ID = currentCouncil.CouncilID, Conference_ID = conference_id, Priority = 1, Password = this.GeneratePassword(), Used = false, }; ApplicationAuth two = new ApplicationAuth { Council_ID = currentCouncil.CouncilID, Conference_ID = conference_id, Priority = 2, Password = this.GeneratePassword(), Used = false, }; ApplicationAuth three = new ApplicationAuth { Council_ID = currentCouncil.CouncilID, Conference_ID = conference_id, Priority = 3, Password = this.GeneratePassword(), Used = false, }; ApplicationAuth four = new ApplicationAuth { Council_ID = currentCouncil.CouncilID, Conference_ID = conference_id, Priority = 4, Password = this.GeneratePassword(), Used = false, }; ApplicationAuth five = new ApplicationAuth { Council_ID = currentCouncil.CouncilID, Conference_ID = conference_id, Priority = 5, Password = this.GeneratePassword(), Used = false, }; ApplicationAuth six = new ApplicationAuth { Council_ID = currentCouncil.CouncilID, Conference_ID = conference_id, Priority = 6, Password = this.GeneratePassword(), Used = false, }; this._context.Add(one); this._context.Add(two); this._context.Add(three); this._context.Add(four); this._context.Add(five); this._context.Add(six); try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { this.telBot.SendTextMessage($"Error at generating passwords for {currentCouncil.CouncilID}, {currentCouncil.Name} - {currentCouncil.University}"); } } for (int i = 0; i <= otherKeys.OtherKeysCount; i++) { ApplicationAuth key = new ApplicationAuth { Council_ID = 0, Conference_ID = conference_id, Priority = 1, Password = this.GeneratePassword(), Used = false, }; this._context.Add(key); try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { this.telBot.SendTextMessage($"Error at generating otherKey"); } } return(this.Ok()); } } return(this.Unauthorized()); }