public async Task <Player> Authenticate(string login, string password) { password = HelperMD5.GenerateMD5Hash(password); var player = (await playerRepository.GetAllAsync()).SingleOrDefault(x => x.Login == login && x.Password == password); if (player == null) { return(null); } player.GenerateToken(appSettings.Secret, appSettings.ExpiresMinutes); return(player); }
public virtual IEnumerable <TEntity> Find(Expression <Func <TEntity, bool> > query) { MethodBase method = MethodBase.GetCurrentMethod(); var queryMD5 = HelperMD5.ComputeHash(HelperMD5.ObjectToByteArray(query)); var key = $"{typeof(TEntity).FullName}-{method.Name}-{queryMD5}"; return(MemoryCache.GetOrCreate( groupCacheKey, key, 3600, (cacheEntry) => { return DbContext.Repository.Query <TEntity>().Where(query).ToList(); })); }
bool createMovie(string htmlCode, ref Movie movie, ref string error) { try { string url_web = htmlCode.MatchRegex("<a href=\"([^\"]*)\" alt="); string title = htmlCode.MatchRegex("<h2 class=\"mb10\">([^<]*)<br><span"); string url_image = htmlCode.MatchRegex("url=(https://[^\"]*)\" alt="); string description = htmlCode.MatchRegex("<p class=\"font12\">([^<]*)</p>"); if (url_web.Length == 0) { throw new Exception("Url web not found"); } if (title.Length == 0) { throw new Exception("Title not found"); } if (url_image.Length == 0) { throw new Exception("Url image not found"); } if (description.Length == 0) { throw new Exception("Description not found"); } movie = new Movie(HelperMD5.calculateHashMD5(url_web)); movie.title = title; movie.url_image = url_image; movie.url_web = url_web; movie.description = description; } catch (Exception ex) { error = "createMovie -> " + ex.Message; } return(0 == error.Length); }
public async Task <IActionResult> PostAsync([FromBody] SavePlayerResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var player = mapper.Map <SavePlayerResource, Player>(resource); player.Password = HelperMD5.GenerateMD5Hash(player.Password); player.PlayerInfo = new PlayerInfo { MaxDamage = 0, MaxKills = 0, PassedGames = 0 }; var result = await playerService.SaveAsync(player); if (!result.IsSuccess) { return(BadRequest(result.Message)); } var customerResource = mapper.Map <Player, PlayerResource>(result.internalValue); return(Ok(customerResource)); }