Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions TourismApp/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public AccountController(
// ==========================

[HttpGet]
public IActionResult Login(string returnUrl = null)
public IActionResult Login(string? returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
public async Task<IActionResult> Login(LoginViewModel model, string? returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (!ModelState.IsValid) return View(model);
Expand All @@ -53,7 +53,7 @@ public async Task<IActionResult> Login(LoginViewModel model, string returnUrl =
}

var result = await _signInManager.PasswordSignInAsync(
user.UserName, model.Password, model.RememberMe, lockoutOnFailure: false);
user.UserName!, model.Password, model.RememberMe, lockoutOnFailure: false);

if (result.Succeeded)
{
Expand All @@ -63,7 +63,6 @@ public async Task<IActionResult> Login(LoginViewModel model, string returnUrl =

if (!hasPreferences)
{

return RedirectToAction("Index", "Preferences");
}

Expand Down Expand Up @@ -106,7 +105,8 @@ public async Task<IActionResult> Register(RegisterViewModel model)

var pending = await _dbContext.PendingUsers.FirstOrDefaultAsync(u => u.Email == model.Email);
var passwordHasher = new PasswordHasher<Users>();
var passwordHash = passwordHasher.HashPassword(null, model.Password);

var passwordHash = passwordHasher.HashPassword(null!, model.Password);
var token = Guid.NewGuid().ToString();

if (pending != null)
Expand Down Expand Up @@ -174,7 +174,7 @@ public async Task<IActionResult> ConfirmPendingUser(string token, string email)
Email = pendingUser.Email,
UserName = pendingUser.Email,
EmailConfirmed = true,
PasswordHash = pendingUser.PasswordHash
PasswordHash = pendingUser.PasswordHash
};

var result = await _userManager.CreateAsync(user);
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task<IActionResult> VerifyEmail(VerifyEmailViewModel model)
var resetLink = Url.Action("ChangePassword", "Account", new { email = user.Email, token = token }, Request.Scheme);
string message = $"<p>Click here to reset your password: <a href='{resetLink}'>Reset Password</a></p>";

await _emailService.SendEmailAsync(user.Email, "Password Reset Request", message);
await _emailService.SendEmailAsync(user.Email!, "Password Reset Request", message);

return RedirectToAction("VerifyEmailSent");
}
Expand All @@ -230,7 +230,11 @@ public IActionResult ChangePassword(string token, string email)
{
ModelState.AddModelError("", "Invalid password reset token.");
}
return View(new ChangePasswordViewModel { Token = token, Email = email });
return View(new ChangePasswordViewModel
{
Token = token ?? string.Empty,
Email = email ?? string.Empty
});
}

[HttpPost]
Expand Down
18 changes: 8 additions & 10 deletions TourismApp/Controllers/ExploreController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public ExploreController(RankingService rankingService,
_exploreService = exploreService;
}

public async Task<IActionResult> Index(string section = "poi", string category = null, string q = null, string eventCategory = null, string date = null, string sort = null)
public async Task<IActionResult> Index(string section = "poi", string? category = null, string? q = null, string? eventCategory = null, string? date = null, string? sort = null)
{
var userId = _userManager.GetUserId(User);

var viewModel = new ExploreViewModel
{
Section = section,
Category = category,
Query = q
Category = category ?? string.Empty,
Query = q ?? string.Empty
};

if (section == "poi")
{
var pois = await _rankingService.GetPersonalizedFeedAsync(userId);
var pois = await _rankingService.GetPersonalizedFeedAsync(userId ?? string.Empty);

if (!string.IsNullOrEmpty(category))
{
Expand All @@ -46,10 +46,9 @@ public async Task<IActionResult> Index(string section = "poi", string category =

if (!string.IsNullOrEmpty(q))
{
pois = pois.Where(p => p.Name.Contains(q, System.StringComparison.OrdinalIgnoreCase)).ToList();
pois = pois.Where(p => p.Name != null && p.Name.Contains(q, System.StringComparison.OrdinalIgnoreCase)).ToList();
}


if (!string.IsNullOrWhiteSpace(sort))
{
switch (sort)
Expand All @@ -67,22 +66,21 @@ public async Task<IActionResult> Index(string section = "poi", string category =

viewModel.PointsOfInterest = pois;
}

else
{
if (section == "news")
{
viewModel.News = await _exploreService.GetNewsAsync(q);
viewModel.News = await _exploreService.GetNewsAsync(q ?? string.Empty);
}

if (section == "events")
{
viewModel.Events = await _exploreService.GetEventsAsync(q, eventCategory, date);
viewModel.Events = await _exploreService.GetEventsAsync(q ?? string.Empty, eventCategory ?? string.Empty, date ?? string.Empty);
}

if (section == "municipalities")
{
viewModel.MunicipalitiesList = await _exploreService.GetMunicipalitiesAsync(q);
viewModel.MunicipalitiesList = await _exploreService.GetMunicipalitiesAsync(q ?? string.Empty);
}
}

Expand Down
5 changes: 2 additions & 3 deletions TourismApp/Models/Municipality.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.Extensions.Logging;
using System.ComponentModel.DataAnnotations;

using System.ComponentModel.DataAnnotations;

namespace TourismApp.Models
{
public class Municipality
Expand All @@ -11,7 +9,8 @@ public class Municipality
public int Id { get; set; }

[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

public string? ImageUrl { get; set; }

public ICollection<PointOfInterest> PointsOfInterest { get; set; } = new List<PointOfInterest>();
Expand Down
4 changes: 2 additions & 2 deletions TourismApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
builder.Services.AddControllersWithViews();

// Add Razor Pages support (ESSENZIALE per Login/Logout/Identity)
builder.Services.AddRazorPages(); // <--- MANCAVA QUESTO!
builder.Services.AddRazorPages();

// Register HTTP Client for external API calls (e.g., Open Data)
builder.Services.AddHttpClient();
Expand Down Expand Up @@ -124,6 +124,6 @@
pattern: "{controller=Home}/{action=Index}/{id?}");

// Rotta per le Razor Pages (Login, Register, Logout)
app.MapRazorPages(); // <--- MANCAVA QUESTO!
app.MapRazorPages();

app.Run();
1 change: 1 addition & 0 deletions TourismApp/TourismApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aa10327e-0ddb-4f9f-8ef3-af1cb0c3afc5</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 8 additions & 9 deletions TourismApp/ViewModels/RegisterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@

namespace TourismApp.ViewModels
{

public class RegisterViewModel
{
[Required(ErrorMessage = "Name is required")]
[StringLength(50, ErrorMessage = "Name cannot exceed 50 characters.")]
[StringLength(50, ErrorMessage = "Name cannot exceed 50 characters.")]
[Display(Name = "Name")]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

[Required(ErrorMessage = "Surname is required")]
[StringLength(50, ErrorMessage = "Surname cannot exceed 50 characters.")]
[Display(Name = "Surname")]
public string Surname { get; set; }
public string Surname { get; set; } = string.Empty;

[Required(ErrorMessage = "Date of birth is required")]
[DataType(DataType.Date)]
[Display(Name = "Date of Birth")]
public DateTime DateOfBirth { get; set; }
[Display(Name = "Date of Birth")]
public DateTime DateOfBirth { get; set; }

[Required(ErrorMessage = "Email is required")]
[EmailAddress(ErrorMessage = "Please enter a valid email address")]
[StringLength(100)]
[Display(Name = "Email")]
public string Email { get; set; }
public string Email { get; set; } = string.Empty;

[Required(ErrorMessage = "Password is required")]
[DataType(DataType.Password)]
[Display(Name = "Set Password")]
[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$",
ErrorMessage = "Your password must contain at least 1 lowercase letter, 1 uppercase letter, 1 number, and be at least 8 characters long.")]
public string Password { get; set; }
public string Password { get; set; } = string.Empty;

[DataType(DataType.Password)]
[Display(Name = "Confirm Password")]
[Compare("Password", ErrorMessage = "The password and password confirmation do not match.")]
public string ConfirmPassword { get; set; }
public string ConfirmPassword { get; set; } = string.Empty;
}
}
4 changes: 2 additions & 2 deletions TourismApp/ViewModels/VerifyEmailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public class VerifyEmailViewModel
{
[Required(ErrorMessage = "Email is required.")]
[EmailAddress]
public string Email { get; set; }
public string Email { get; set; } = string.Empty;
}
}
}
4 changes: 2 additions & 2 deletions TourismApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"EmailSettings": {
"SmtpServer": "smtp.gmail.com",
"Port": "587",
"SenderEmail": "dfrgroup3@gmail.com",
"SenderPassword": "ifiq lkiv wdak tmlm"
"SenderEmail": "",
"SenderPassword": ""
}

}
Expand Down
Binary file added storico_commit.txt
Binary file not shown.
Loading