private async Task <PlayerBE> GetPlayerByName(string playerName) { string nameHash = GetUsernameHash(playerName); PlayerBE playerBE = await base.Facade.GetPlayerByNameHash(nameHash); return(playerBE); }
private PlayerBE GetEntity(PlayerEntity pe) { if (null == pe) { return(null); } short MaxSeason = pe.PlayerSeason.Max <PlayerSeasonEntity, short>(x => x.season_id); PlayerSeasonEntity pse = pe.PlayerSeason.Single(x => x.season_id.Equals(MaxSeason)); var result = new PlayerBE { Bio = string.IsNullOrEmpty(pse.bio) ? "no bio provided" : pse.bio, Captain = pse.captain.GetValueOrDefault(), ClassYr = pse.@class, EligibilityYr = pse.eligibility, FirstName = pe.first, Height = pse.height.GetValueOrDefault(), HighSchool = pe.highschool, HomeState = pe.homestate, Hometown = pe.hometown, JerseyNum = pse.jersey.GetValueOrDefault(), LastName = pe.last, Major = pe.major, MiddleName = pe.middle, Officer = pse.officer.GetValueOrDefault(), PlayerID = pe.id, Position = pse.position, President = pse.president.GetValueOrDefault(), SeasonID = pse.season_id, Weight = pse.weight.GetValueOrDefault() }; return(result); }
private PlayerEntity GetPlayerEntity(PlayerBE pbe) { var pse = new PlayerSeasonEntity { @class = pbe.ClassYr.Trim(), eligibility = pbe.EligibilityYr.Trim(), height = (short)pbe.Height, jersey = (short)pbe.JerseyNum, player_id = (short)pbe.PlayerID, position = pbe.Position.Trim(), season_id = (short)pbe.SeasonID, weight = (short)pbe.Weight, team = pbe.Team.Trim() }; var pe = new PlayerEntity { first = pbe.FirstName.Trim(), highschool = pbe.HighSchool.Trim(), homestate = pbe.HomeState.Trim(), hometown = pbe.Hometown.Trim(), id = (short)pbe.PlayerID, last = pbe.LastName.Trim(), major = pbe.Major.Trim(), middle = pbe.MiddleName.Trim() }; pe.PlayerSeason.Add(pse); return(pe); }
public async Task <string> Login(string username, string password) { //The most common validation that will be violated in this method is the IncorrectUsernamePassword rule //Preset that statusDetail in preparation for if we have to set it List <StatusDetail> statusDetails = new List <StatusDetail>() { new StatusDetail() { Code = Status400.IncorrectUsernamePassword.ToInt32(), Desc = StatusMessage.IncorrectUsernamePassword.GetValue() } }; PlayerBE player = await GetPlayerByName(username); //Player validation if (player == null) { base.StatusResp.SetStatusResponse(Status500.BusinessError, StatusMessage.BusinessError, statusDetails); return(null); } //Password validation string passwordHash = GetPasswordHash(password, player.PasswordSalt, player.PasswordPepper); if (!passwordHash.Equals(player.PasswordHash)) { base.StatusResp.SetStatusResponse(Status500.BusinessError, StatusMessage.BusinessError, statusDetails); return(null); } //Made it this far then the login is valid. //Create a new login token, update the user with related token details and return the new token player.LoginTokenExpireDateTime = DateTime.UtcNow.AddDays(14); //Start this now while we generate the token, make sure to wait on it before leaving Task <PlayerBE> updatePlayerTask = Facade.UpdatePlayer(player); string jwtToken = TokenMan.GenerateLoginToken(player.PlayerID, player.LoginTokenExpireDateTime); //Update validation PlayerBE updatedPlayer = await updatePlayerTask; if (updatedPlayer == null) { statusDetails = new List <StatusDetail>() { new StatusDetail() { Code = Status700.DbUpdateError.ToInt32(), Desc = StatusMessage.DbUpdateError.GetValue() } }; base.StatusResp.SetStatusResponse(Status500.RetryError, StatusMessage.RetryError, statusDetails); return(null); } return(jwtToken); }
public async Task <PlayerBE> GetPlayerByPlayerID(int playerID) { PlayerEntity playerEntity = await base.DataSvc.PlayerRepo.GetByPlayerIDAsync(playerID); PlayerBE playerBE = playerEntity != null?base.Mapper.Map <PlayerBE>(playerEntity) : null; return(playerBE); }
public async Task <ActionResult <Player> > GetPlayerByID([FromQuery] int playerID) { PlayerBE playerBE = await base.Adapter.GetPlayerByID(playerID); Player player = playerBE != null?base.Mapper.Map <Player>(playerBE) : null; return(player); }
public async Task <PlayerBE> GetPlayerByNameHash(string nameHash) { PlayerEntity playerEntity = await base.DataSvc.PlayerRepo.GetByNameHashAsync(nameHash); PlayerBE playerBE = playerEntity != null?base.Mapper.Map <PlayerBE>(playerEntity) : null; return(playerBE); }
public async Task <bool> NameIsAvailable(string playerName) { PlayerBE playerBE = await GetPlayerByName(playerName); bool isAvailable = playerBE == null; return(isAvailable); }
public async Task InsertNewPlayer(PlayerBE newPlayer) { PlayerEntity playerEntity = base.Mapper.Map <PlayerEntity>(newPlayer); playerEntity.CreatedBy = playerEntity.LastModifiedBy = SystemConstants.DefaultUser; playerEntity.CreatedDateTime = playerEntity.LastModifiedDateTime = DateTime.UtcNow; await base.DataSvc.PlayerRepo.InsertAsync(playerEntity); newPlayer.PlayerID = playerEntity.PlayerID; }
public async Task <string> ChangeUsername(int playerID, string newUsername) { PlayerBE playerBE = await base.Facade.GetPlayerByPlayerID(playerID); playerBE.Name = newUsername; playerBE.NameHash = GetUsernameHash(newUsername); playerBE.LoginTokenExpireDateTime = DateTime.UtcNow.AddDays(14); await base.Facade.UpdatePlayer(playerBE); string newToken = TokenMan.GenerateLoginToken(playerID, playerBE.LoginTokenExpireDateTime); return(newToken); }
public async Task ChangePassword(int playerID, string currentPassword, string newPassword) { List <StatusDetail> statusDetails; PlayerBE playerBE = await base.Facade.GetPlayerByPlayerID(playerID); string newPassHash = GetPasswordHash(newPassword, playerBE.PasswordSalt, playerBE.PasswordPepper); //New password cannot be old password if (newPassHash == playerBE.PasswordHash) { statusDetails = new List <StatusDetail>() { new StatusDetail() { Code = Status400.NewPasswordSamePassword.ToInt32(), Desc = StatusMessage.NewPasswordSamePassword.GetValue() } }; base.StatusResp.SetStatusResponse(Status500.BusinessError, StatusMessage.BusinessError, statusDetails); return; } string currentPassHash = GetPasswordHash(currentPassword, playerBE.PasswordSalt, playerBE.PasswordPepper); //Current password was incorrect if (currentPassHash != playerBE.PasswordHash) { statusDetails = new List <StatusDetail>() { new StatusDetail() { Code = Status400.IncorrectPassword.ToInt32(), Desc = StatusMessage.IncorrectPassword.GetValue() } }; base.StatusResp.SetStatusResponse(Status500.BusinessError, StatusMessage.BusinessError, statusDetails); return; } //Everthing is good, perform the update string salt = Guid.NewGuid().ToString("N"); string pepper = Guid.NewGuid().ToString("N"); string passwordHash = GetPasswordHash(newPassword, salt, pepper); playerBE.PasswordSalt = salt; playerBE.PasswordPepper = pepper; playerBE.PasswordHash = passwordHash; await base.Facade.UpdatePlayer(playerBE); }
public async Task <PlayerBE> GetPlayerByID(int playerID) { PlayerBE playerBE = await base.Facade.GetPlayerByPlayerID(playerID); if (playerBE == null) { List <StatusDetail> statusDetails = new List <StatusDetail>() { new StatusDetail() { Code = Status300.PlayerNotFoundByID.ToInt32(), Desc = StatusMessage.PlayerNotFoundByID.GetValue() } }; base.StatusResp.SetStatusResponse(Status500.BadRequest, StatusMessage.BadRequest, statusDetails); } return(playerBE); }
public async Task <PlayerBE> UpdatePlayer(PlayerBE playerBE) { PlayerEntity playerEntity = base.Mapper.Map <PlayerEntity>(playerBE); playerEntity.LastModifiedBy = SystemConstants.DefaultUser; playerEntity.LastModifiedDateTime = DateTime.UtcNow; bool updatedSuccessfully = await base.DataSvc.PlayerRepo.UpdateAsync(playerEntity); if (!updatedSuccessfully) { return(null); } PlayerBE updatedPlayerBE = base.Mapper.Map <PlayerBE>(playerEntity); return(updatedPlayerBE); }
private PlayerBE GetEntity(PlayerEntity pe, short seasonID = -1) { if (null == pe) { return(null); } if (seasonID.Equals(-1)) { seasonID = pe.PlayerSeason.Max <PlayerSeasonEntity, short>(x => x.season_id); } PlayerSeasonEntity pse = pe.PlayerSeason.Single(x => x.season_id.Equals(seasonID)); var result = new PlayerBE { FirstName = pe.first, HighSchool = pe.highschool, HomeState = pe.homestate, Hometown = pe.hometown, LastName = pe.last, Major = pe.major, MiddleName = pe.middle, PlayerID = pe.id }; bool seasonExists = (null == pse); result.Bio = (seasonExists || string.IsNullOrEmpty(pse.bio)) ? "no bio provided" : pse.bio; result.Captain = seasonExists ? false : pse.captain.GetValueOrDefault(); result.ClassYr = seasonExists ? string.Empty : pse.@class; result.EligibilityYr = seasonExists ? string.Empty : pse.eligibility; result.Height = seasonExists ? 0 : pse.height.GetValueOrDefault(); result.JerseyNum = seasonExists ? -1 : pse.jersey.GetValueOrDefault(); result.Officer = seasonExists ? false : pse.officer.GetValueOrDefault(); result.Position = seasonExists ? string.Empty : pse.position; result.President = seasonExists ? false : pse.president.GetValueOrDefault(); result.SeasonID = seasonExists ? 0 : pse.season_id; result.Weight = seasonExists ? 0 : pse.weight.GetValueOrDefault(); return(result); }
public async Task <string> CreateAccount(string username, string password) { string salt = Guid.NewGuid().ToString("N"); string pepper = Guid.NewGuid().ToString("N"); string passwordHash = GetPasswordHash(password, salt, pepper); PlayerBE newPlayer = new PlayerBE() { PasswordSalt = salt, PasswordPepper = pepper, PasswordHash = passwordHash, NameHash = GetUsernameHash(username), Name = username, LoginTokenExpireDateTime = DateTime.UtcNow.AddDays(14) }; await base.Facade.InsertNewPlayer(newPlayer); string loginToken = TokenMan.GenerateLoginToken(newPlayer.PlayerID, newPlayer.LoginTokenExpireDateTime); return(loginToken); }
public PlayerModel(PlayerBE player) { Bio = player.Bio; Captain = player.Captain; ClassYr = player.ClassYr; EligibilityYr = player.EligibilityYr; FirstName = player.FirstName; Height = player.Height; HighSchool = player.HighSchool; HomeState = player.HomeState; Hometown = player.Hometown; JerseyNum = player.JerseyNum; LastName = player.LastName; Major = player.Major; MiddleName = player.MiddleName; Officer = player.Officer; PlayerID = player.PlayerID; Position = player.Position; President = player.President; SeasonID = player.SeasonID; Weight = player.Weight; }
public ActionResult Index(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index", "roster", new { id = KSU.maxPlayerSeason })); //return RedirectToAction("Index", "players", new { id = KSU.maxPlayerSeason }); } int player_id; if (int.TryParse(id, out player_id)) { return(RedirectToAction("Index", "roster", new { id = player_id })); //if (player_id >= 2010 && player_id <= KSU.maxPlayerSeason) //{ // RosterModel data = new RosterModel(); // data.Players = GetPlayerModelLst(_playerBL.PlayersBySeason(player_id)); // data.Games = new GameListModel(_gameBL.GamesBySeason(player_id)); // if (data.Players.Count.Equals(0) && player_id.Equals(KSU.maxGameSeason)) // { // throw new Exception("KSULAX||Player profiles for " + player_id + " coming soon!"); // } // else if (data.Players.Count.Equals(0)) // { // throw new Exception("KSULAX||we can't find the roster you requested"); // } // else // { // return View(data); // } //} ////find player by id //else //{ // string name = string.Empty; // if (_playerBL.getPlayerNamebyID(player_id, out name)) // { // return RedirectToAction("Index", "players", new { id = name }); // } // else // { // throw new Exception("KSULAX||we can't find the player id you requested"); // } //} } //find player by full name else { if (string.Compare(id, id.ToLower()).Equals(0)) { PlayerBE player = _playerBL.PlayerByName(id); if (null == player) { throw new Exception("KSULAX||we can't find the player you requested"); } PlayerBioModel result = new PlayerBioModel(); result.PlayerInfo = new PlayerModel(player); result.PlayerStatList = new PlayerGameStatListModel(_gameBL.PlayerGameStats(playerID: player.PlayerID)); result.PlayerAwardList = new PlayerAwardModelList(_awardBL.AwardsByPlayerID(player.PlayerID)); return(View("Player", result)); } else { return(RedirectToAction("Index", "players", new { id = id.ToLower() })); } } }