Skip to content

Commit

Permalink
Merge pull request #56 from Purdue-ACM-SIGAPP/DotNet-Hide-URL
Browse files Browse the repository at this point in the history
Dot net hide url
  • Loading branch information
dpanek27 authored Jan 22, 2025
2 parents dd2677b + 439d27f commit e82ac26
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
7 changes: 7 additions & 0 deletions Controllers/EventsController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SimpleWebAppReact.Entities;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -96,6 +97,8 @@ 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 104 in Controllers/EventsController.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
Expand All @@ -109,6 +112,8 @@ 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 @@ -122,6 +127,8 @@ 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: 5 additions & 2 deletions Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using SimpleWebAppReact.Entities;
using Microsoft.Extensions.Logging;
using MongoDB.Bson;
using MongoDB.Driver;
using SimpleWebAppReact.Services;

Expand Down Expand Up @@ -72,13 +73,14 @@ 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, id);
var filter = Builders<User>.Filter.Eq(x => x.Id, objectId);
var user = _users.Find(filter).FirstOrDefault();
return user is not null ? Ok(user) : NotFound();
}
Expand Down Expand Up @@ -117,7 +119,8 @@ public async Task<ActionResult> Update(User user)
[HttpDelete("{id}")]
public async Task<ActionResult> Delete(string id)
{
var filter = Builders<User>.Filter.Eq(x => x.Id, id);
ObjectId objectId = new ObjectId(id);
var filter = Builders<User>.Filter.Eq(x => x.Id, objectId);
await _users.DeleteOneAsync(filter);
return Ok();
}
Expand Down
10 changes: 6 additions & 4 deletions Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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
public class User : MongoUser
{
[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: 21 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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 @@ -47,12 +50,28 @@
});
});
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 = "https://dev-2gowyyl3kin685ua.us.auth0.com/";
options.Audience = "http://localhost:5128";
options.Authority = builder.Configuration.GetConnectionString("opt_Authority");
options.Audience = builder.Configuration.GetConnectionString("opt_audience");
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.NameIdentifier,
Expand Down
2 changes: 2 additions & 0 deletions SimpleWebAppReact.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
</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 e82ac26

Please sign in to comment.