public Result<customer_account> Login(IDbConnection db, string userName, string pwd, IPAddress ip) { string userNameLC = userName.ToLower(); var loginInfo = db.Query<customer_login_password>("SELECT * FROM customer_login_password WHERE lower(username)=@userName OR lower(email)=@userName ", new { userName = userNameLC }).FirstOrDefault(); if (loginInfo == null || string.Compare(loginInfo.unhashed_password, pwd, StringComparison.OrdinalIgnoreCase) != 0) { return Result<customer_account>.Null(ErrorCodes.InvalidUserNameOrPassword); } var user = GetCustomerById(db, loginInfo.customer_account_id); int id = user.Data.id; // Change country code only IF the database has not store this value before // if (string.IsNullOrEmpty(user.Data.country_code) || string.IsNullOrEmpty(user.Data.country_name)) { ip.GetCountryCode(c => user.Data.country_code = c, n => user.Data.country_name = n); } // TODO: Update user.Data.last_login_at = DateTime.UtcNow; db.Execute("UPDATE customer_account SET last_login_at=@last_login_at, country_code=@country_code, country_name=@country_name", user.Data); return user; }
public static JObject getDownloadLinksForCurrentUser(Game game, ApplicationUser currentUser, IPAddress ip) { var countryCode = String.Empty; if (currentUser != null) { countryCode = currentUser.country_code; } else { string country_code = null; string country_name = null; if (ip.GetCountryCode(c => country_code = c, n => country_name = n)) { countryCode = country_code; } } var downloadLink = JObject.Parse(game.download_links); var jsonLink = JObject.Parse(game.download_links); if (Local.NO_GAME_STORES_COUNTRY_CODES.Contains(countryCode.ToLower())) { if (jsonLink["google"] != null) { downloadLink.Remove("google"); } } else { if (game.id != 21 && game.id != 24) { if (jsonLink["apk"] != null) { downloadLink.Remove("apk"); } } } return downloadLink; }