Skip to content

Commit

Permalink
Merge pull request #58 from Purdue-ACM-SIGAPP/revert-56-DotNet-Hide-URL
Browse files Browse the repository at this point in the history
Revert "Dot net hide url"
  • Loading branch information
AndrewZacharyLiu authored Jan 24, 2025
2 parents e82ac26 + e903cfe commit 8434a22
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 41 deletions.
7 changes: 0 additions & 7 deletions Controllers/EventsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SimpleWebAppReact.Entities;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -97,8 +96,6 @@ public async Task<IEnumerable<Events>> Get([FromQuery] string? eventName = null,
/// <param name="events"></param>
/// <returns></returns>
[HttpPost]
//roles that can edit events
[Authorize(Roles ="RA, Club, Greek Life Officer")]
public async Task<ActionResult> Post(Events events)
{
await _events.InsertOneAsync(events);

Check warning on line 101 in Controllers/EventsController.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
Expand All @@ -112,8 +109,6 @@ public async Task<ActionResult> Post(Events events)
/// <param name="events"></param>
/// <returns></returns>
[HttpPut]
//roles that can edit events
[Authorize(Roles ="RA, Club, Greek Life Officer")]
public async Task<ActionResult> Update(Events events)
{
var filter = Builders<Events>.Filter.Eq(x => x.Id, events.Id);
Expand All @@ -127,8 +122,6 @@ public async Task<ActionResult> Update(Events events)
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}")]
//roles that can edit events
[Authorize(Roles ="RA, Club, Greek Life Officer")]
public async Task<ActionResult> Delete(string id)
{
var filter = Builders<Events>.Filter.Eq(x => x.Id, id);
Expand Down
7 changes: 2 additions & 5 deletions Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using SimpleWebAppReact.Entities;
using Microsoft.Extensions.Logging;
using MongoDB.Bson;
using MongoDB.Driver;
using SimpleWebAppReact.Services;

Expand Down Expand Up @@ -73,14 +72,13 @@ public async Task<IEnumerable<User>> Get([FromQuery] string? name = null, [FromQ
[HttpGet("{id}")]
public async Task<ActionResult<User?>> GetById(string id)
{
ObjectId objectId = new ObjectId(id);
// Simple validation to check if the ID is not null
if (string.IsNullOrEmpty(id))
{
return BadRequest("Invalid ID format.");
}

var filter = Builders<User>.Filter.Eq(x => x.Id, objectId);
var filter = Builders<User>.Filter.Eq(x => x.Id, id);
var user = _users.Find(filter).FirstOrDefault();
return user is not null ? Ok(user) : NotFound();
}
Expand Down Expand Up @@ -119,8 +117,7 @@ public async Task<ActionResult> Update(User user)
[HttpDelete("{id}")]
public async Task<ActionResult> Delete(string id)
{
ObjectId objectId = new ObjectId(id);
var filter = Builders<User>.Filter.Eq(x => x.Id, objectId);
var filter = Builders<User>.Filter.Eq(x => x.Id, id);
await _users.DeleteOneAsync(filter);
return Ok();
}
Expand Down
10 changes: 4 additions & 6 deletions Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using AspNetCore.Identity.Mongo.Model;

namespace SimpleWebAppReact.Entities;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
/// <summary>
/// Class structure matches 1-1 with User Table in database
/// </summary>
public class User : MongoUser
public class User
{
// [BsonId]
// [BsonElement("_id"), BsonRepresentation(BsonType.ObjectId)]
// public string? Id { get; set; }
[BsonId]
[BsonElement("_id"), BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }

[BsonElement("name"), BsonRepresentation(BsonType.String)]
public string? Name { get; set; }
Expand Down
23 changes: 2 additions & 21 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System.Security.Claims;
using AspNetCore.Identity.Mongo;
using AspNetCore.Identity.Mongo.Model;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using SimpleWebAppReact;
using SimpleWebAppReact.Entities;
using SimpleWebAppReact.Services;

var builder = WebApplication.CreateBuilder(args);
Expand Down Expand Up @@ -50,28 +47,12 @@
});
});
builder.Services.AddSingleton<MongoDbService>();
// Here, configure User
var connectionString = builder.Configuration.GetConnectionString("DbConnection");
var databaseName = builder.Configuration.GetConnectionString("DatabaseName");

// At the ConfigureServices section in Startup.cs
builder.Services.AddIdentityMongoDbProvider<User, MongoRole>(identity =>
{
identity.Password.RequiredLength = 8;
// other options
},
mongo =>
{
mongo.ConnectionString = connectionString;
// other options
});

builder.Services.AddHttpClient<BuildingOutlineService>();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = builder.Configuration.GetConnectionString("opt_Authority");
options.Audience = builder.Configuration.GetConnectionString("opt_audience");
options.Authority = "https://dev-2gowyyl3kin685ua.us.auth0.com/";
options.Audience = "http://localhost:5128";
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.NameIdentifier,
Expand Down
2 changes: 0 additions & 2 deletions SimpleWebAppReact.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.Identity.Mongo" Version="9.0.1-rc1" />
<PackageReference Include="Auth0.AspNetCore.Authentication" Version="1.4.1" />
<PackageReference Include="dotenv.net" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.33" />
<PackageReference Include="MongoDB.AspNet.Identity" Version="1.0.5" />
<PackageReference Include="MongoDB.Driver" Version="2.28.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down

0 comments on commit 8434a22

Please sign in to comment.