Skip to content

Commit

Permalink
Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fergalmoran committed Sep 25, 2023
2 parents 582a178 + 5b3282c commit 67ead7e
Show file tree
Hide file tree
Showing 27 changed files with 247 additions and 4,110 deletions.
110 changes: 52 additions & 58 deletions mixyboos-api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Bogus;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -13,72 +10,69 @@
using MixyBoos.Api.Data.DTO;
using MixyBoos.Api.Data.Models;
using MixyBoos.Api.Data.Utils;
using MixyBoos.Api.Services.Extensions;
using MixyBoos.Api.Services.Helpers;
using OpenIddict.Validation.AspNetCore;

namespace MixyBoos.Api.Controllers {
[Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
[Route("[controller]")]
public class AccountController : _Controller {
private readonly UserManager<MixyBoosUser> _userManager;
private readonly MixyBoosContext _context;
private readonly IConfiguration _config;
private readonly ImageCacher _imageCacher;
[Authorize]
[Route("[controller]")]
public class AccountController : _Controller {
private readonly UserManager<MixyBoosUser> _userManager;
private readonly MixyBoosContext _context;
private readonly IConfiguration _config;
private readonly ImageCacher _imageCacher;

public AccountController(
UserManager<MixyBoosUser> userManager,
MixyBoosContext dbContext,
IConfiguration config,
ImageCacher imageCacher,
ILogger<AccountController> logger) : base(logger) {
_userManager = userManager;
_context = dbContext;
_config = config;
_imageCacher = imageCacher;
}

//
// POST: /Account/Register
[HttpPost("register")]
[AllowAnonymous]
public async Task<IActionResult> Register([FromBody] RegisterDTO model) {
if (!ModelState.IsValid) {
return BadRequest(ModelState);
}
public AccountController(
UserManager<MixyBoosUser> userManager,
MixyBoosContext dbContext,
IConfiguration config,
ImageCacher imageCacher,
ILogger<AccountController> logger) : base(logger) {
_userManager = userManager;
_context = dbContext;
_config = config;
_imageCacher = imageCacher;
}

var faker = new Faker("en");
var user = new MixyBoosUser {
UserName = model.UserName,
Email = model.UserName,
DisplayName = model.DisplayName,
Title = faker.Name.JobTitle()
};
var result = await _userManager.CreateAsync(user, model.Password);
//
// POST: /Account/Register
[HttpPost("register")]
[AllowAnonymous]
public async Task<IActionResult> Register([FromBody] RegisterDTO model) {
if (!ModelState.IsValid) {
return BadRequest(ModelState);
}

if (result.Succeeded) {
await _imageCacher.CacheUserImages(user, _config);
var faker = new Faker("en");
var user = new MixyBoosUser {
UserName = model.UserName,
Email = model.UserName,
DisplayName = model.DisplayName,
Title = faker.Name.JobTitle()
};
var result = await _userManager.CreateAsync(user, model.Password);

await _userManager.UpdateAsync(user);
await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Email, user.Email));
return Ok(model);
}
if (result.Succeeded) {
await _imageCacher.CacheUserImages(user, _config);

AddErrors(result);
await _userManager.UpdateAsync(user);
await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Email, user.Email));
return Ok(model);
}

// If we got this far, something failed.
return BadRequest(ModelState);
}
AddErrors(result);

// If we got this far, something failed.
return BadRequest(ModelState);
}

#region Helpers

private void AddErrors(IdentityResult result) {
foreach (var error in result.Errors) {
ModelState.AddModelError(string.Empty, error.Description);
}
}
#region Helpers

#endregion
private void AddErrors(IdentityResult result) {
foreach (var error in result.Errors) {
ModelState.AddModelError(string.Empty, error.Description);
}
}

#endregion
}
}
235 changes: 0 additions & 235 deletions mixyboos-api/Controllers/AuthorizationController.cs

This file was deleted.

3 changes: 1 addition & 2 deletions mixyboos-api/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
using MixyBoos.Api.Controllers.Hubs;
using MixyBoos.Api.Data;
using MixyBoos.Api.Data.Models;
using OpenIddict.Validation.AspNetCore;

namespace MixyBoos.Api.Controllers;

[Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
[Authorize]
[Route("[controller]")]
public class ChatController : _Controller {
private readonly UserManager<MixyBoosUser> _userManager;
Expand Down
Loading

0 comments on commit 67ead7e

Please sign in to comment.