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
37 changes: 30 additions & 7 deletions Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using ValuationBackend.Models;
using ValuationBackend.Services;
using System.Threading.Tasks;

namespace ValuationBackend.Controllers
{
Expand All @@ -9,10 +10,12 @@ namespace ValuationBackend.Controllers
public class AuthController : ControllerBase
{
private readonly IAuthService _authService;
private readonly PasswordResetService _passwordResetService;

public AuthController(IAuthService authService)
public AuthController(IAuthService authService, PasswordResetService passwordResetService)
{
_authService = authService;
_passwordResetService = passwordResetService;
}

[HttpPost("login")]
Expand Down Expand Up @@ -46,14 +49,34 @@ public async Task<IActionResult> Logout([FromBody] LogoutRequest request)
return Ok(new { msg = "success" });
}

[HttpPost("forgot-password")]
public async Task<IActionResult> ForgotPassword([FromBody] ForgotPasswordRequest request)
// --- New Password Reset Endpoints ---

[HttpPost("request-password-reset")]
public async Task<IActionResult> RequestPasswordReset([FromBody] EmailDto dto)
{
var result = await _authService.ForgotPasswordAsync(request.Username);
if (!result)
return NotFound(new { msg = "User not found" });
await _passwordResetService.RequestPasswordResetAsync(dto.Email);
return Ok(new { message = "If the email exists, an OTP has been sent." });
}

return Ok(new { msg = "success" });
[HttpPost("verify-otp")]
public async Task<IActionResult> VerifyOtp([FromBody] OtpDto dto)
{
var valid = await _passwordResetService.VerifyOtpAsync(dto.Email, dto.Otp);
if (!valid) return BadRequest(new { message = "Invalid or expired OTP." });
return Ok(new { message = "OTP verified." });
}

[HttpPost("reset-password")]
public async Task<IActionResult> ResetPassword([FromBody] ResetPasswordDto dto)
{
var success = await _passwordResetService.ResetPasswordAsync(dto.Email, dto.Otp, dto.NewPassword);
if (!success) return BadRequest(new { message = "Invalid OTP or email." });
return Ok(new { message = "Password reset successful." });
}

// --- DTOs for password reset ---
public class EmailDto { public string Email { get; set; } }
public class OtpDto { public string Email { get; set; } public string Otp { get; set; } }
public class ResetPasswordDto { public string Email { get; set; } public string Otp { get; set; } public string NewPassword { get; set; } }
}
}
36 changes: 36 additions & 0 deletions Controllers/iteration2/DecisionFieldController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using ValuationBackend.Models.DTOs;
using ValuationBackend.Services;
using ValuationBackend.Data;
using ValuationBackend.Models;
using Microsoft.EntityFrameworkCore;


[ApiController]
[Route("api/decision-fields")]
public class DecisionFieldController : ControllerBase
{
private readonly ValuationContext _context;

public DecisionFieldController(ValuationContext context)
{
_context = context;
}

[HttpPost]
public async Task<IActionResult> CreateField([FromBody] DecisionField field)
{
_context.DecisionFields.Add(field);
await _context.SaveChangesAsync();
return Ok(field);
}

[HttpGet]
public async Task<IActionResult> GetAllFields()
{
var fields = await _context.DecisionFields.ToListAsync();
return Ok(fields);
}
}
34 changes: 34 additions & 0 deletions Controllers/iteration2/RatingFileController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/{requestType}/ratingfile")]
public class RatingFileController : ControllerBase
{
// 1. Load all street names
[HttpGet("streets")]
public IActionResult GetStreets(string requestType)
{
var streets = new[]
{
new { id = "S1", name = "Main Street" },
new { id = "S2", name = "Highway Road" },
new { id = "S3", name = "Park Avenue" }
};

return Ok(new { streets });
}

// 2. Load obsolete numbers for selected street
[HttpGet("streets/{streetId}/obsolete-numbers")]
public IActionResult GetObsoleteNumbers(string requestType, string streetId)
{
var obsoleteNumbers = new[]
{
new { id = "O1", number = "101" },
new { id = "O2", number = "102" },
new { id = "O3", number = "103" }
};

return Ok(new { obsoleteNumbers });
}
}
6 changes: 5 additions & 1 deletion Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options) { }

public DbSet<RatingRequest> RatingRequests { get; set; }

public DbSet<LandMiscellaneousMasterFile> LandMiscellaneousMasterFiles { get; set; }

public DbSet<Reconciliation> Reconciliations { get; set; }
Expand Down Expand Up @@ -62,6 +62,10 @@ public AppDbContext(DbContextOptions<AppDbContext> options)

public DbSet<PropertyCategory> PropertyCategories { get; set; }


public DbSet<DecisionField> DecisionFields { get; set; }
public DbSet<PasswordReset> PasswordResets { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
Expand Down
2 changes: 2 additions & 0 deletions Data/DBInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,5 +1913,7 @@ private static void InitializeReconciliations(AppDbContext context)
context.SaveChanges();
Console.WriteLine("Reconciliations seeded.");
}


}
}
13 changes: 13 additions & 0 deletions Data/ValuationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using ValuationBackend.Models;

namespace ValuationBackend.Data
{
public class ValuationContext : DbContext
{
public ValuationContext(DbContextOptions<ValuationContext> options) : base(options) { }

public DbSet<DecisionField> DecisionFields { get; set; }
// ...add other DbSets as needed...
}
}
16 changes: 16 additions & 0 deletions Migrations/20250428193956_InitialCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
table.PrimaryKey("PK_RatingRequests", x => x.Id);
});

migrationBuilder.CreateTable(
name: "PasswordResets",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Email = table.Column<string>(nullable: false),
Otp = table.Column<string>(nullable: false),
ExpiresAt = table.Column<DateTime>(nullable: false),
Used = table.Column<bool>(nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PasswordResets", x => x.Id);
});
}

/// <inheritdoc />
Expand Down
Loading