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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using O2NextGen.Auth.Web.Services;

namespace O2NextGen.Auth.Web.Extensions
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddApplicationServices(this IServiceCollection services,IConfiguration configuration)
{
//register delegating handlers
// services.AddTransient<HttpClientAuthorizationDelegatingHandler>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

//register http services
services
.AddHttpClient<IESenderService, ESenderService>("E-Sender", client =>
{
client.BaseAddress = new Uri(configuration.GetValue<string>("urls:ESenderUrl"));
});

return services;
}
}
}
27 changes: 27 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Helpers/DummyEmailSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.Extensions.Logging;
using O2NextGen.Auth.Web.Services;

namespace O2NextGen.Auth.Web.Helpers
{
internal class DummyEmailSender : IEmailSender
{
private readonly ILogger<DummyEmailSender> _logger;
private readonly IESenderService _service;

public DummyEmailSender(ILogger<DummyEmailSender> logger, IESenderService service)
{
_logger = logger;
_service = service;
}
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
_logger.LogWarning("EmailSender implementation is being used!!!!");
_logger.LogWarning($"htmlMessage = { HttpUtility.HtmlDecode(htmlMessage)}");
_service.Send(email,subject,htmlMessage);
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public void Format(LogEvent logEvent, TextWriter output)

private void FormatBody(LogEvent logEvent, TextWriter output)
{
using (var writer = new JsonTextWriter(output))
{


// add json body
var writer = new JsonTextWriter(output);
writer.WriteStartObject();

// write level
Expand Down Expand Up @@ -80,7 +83,7 @@ private void FormatBody(LogEvent logEvent, TextWriter output)

writer.WriteEndObject();
writer.Flush();
}
} }

private static string FormatLogLevel(LogEventLevel level)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Login.en.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Remove="Logs\**" />
</ItemGroup>

<ItemGroup>
Expand All @@ -62,14 +63,20 @@
<AutoGen>True</AutoGen>
<DependentUpon>Login.en.resx</DependentUpon>
</Compile>
<Compile Remove="Logs\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\SharedResource.en" />
<None Remove="Resources\Resources.ru" />
<None Remove="Logs\**" />
</ItemGroup>

<ItemGroup>
<Folder Include="css\core" />
</ItemGroup>

<ItemGroup>
<Content Remove="Logs\**" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/AccessDenied.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page
@model O2NextGen.Auth.Web.Pages.Account.AccessDenied

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<title></title>
</head>
<body>
<div>
<h1>Access Denied!!!s</h1>
</div>
</body>
</html>
12 changes: 12 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/AccessDenied.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace O2NextGen.Auth.Web.Pages.Account
{
public class AccessDenied : PageModel
{
public void OnGet()
{

}
}
}
19 changes: 19 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/Account/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@page
@model O2NextGen.Auth.Web.Pages.Account.Index

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<title></title>
</head>
<body>
<div>
Test index page
</div>
</body>
</html>
12 changes: 12 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/Account/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace O2NextGen.Auth.Web.Pages.Account
{
public class Index : PageModel
{
public void OnGet()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div role="hidden" class="mt-12 border-t">
<span class="block w-max mx-auto -mt-3 px-4 text-center text-gray-500 bg-white">Or</span>
</div>
<form action="" class="space-y-6 py-6">
<form id="account" method="post" class="space-y-6 py-6">
<div>
<input type="email" asp-for="Input.Email"
placeholder="@Localizer["Email"]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
 using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand Down Expand Up @@ -33,7 +29,8 @@ public LoginModel(SignInManager<O2User> signInManager, ILogger<LoginModel> logge
[BindProperty]
public InputModel Input { get; set; }

public IList<AuthenticationScheme> ExternalLogins { get; set; }
//Todo: will create to login with Fb, Vk, MicrosoftId, Google Account
// public IList<AuthenticationScheme> ExternalLogins { get; set; }

public string ReturnUrl { get; set; }

Expand Down Expand Up @@ -63,10 +60,11 @@ public async Task OnGetAsync(string returnUrl = null)

returnUrl = returnUrl ?? Url.Content("~/");

//Todo: will create to login with Fb, Vk, MicrosoftId, Google Account
// Clear the existing external cookie to ensure a clean login process
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
// await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
// ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

ReturnUrl = returnUrl;
}
Expand All @@ -83,7 +81,7 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
return Redirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
Expand Down
11 changes: 11 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/Logout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@page
@model O2NextGen.Auth.Web.Pages.Account.LogoutModel

@{
Layout = null;
}

<header>
<h1>@ViewData["Title"]</h1>
<p>You have successfully logged out of the application.</p>
</header>
41 changes: 41 additions & 0 deletions src/Services/auth/O2NextGen.Auth.Web/Pages/Logout.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using O2NextGen.Auth.Web.Data;

namespace O2NextGen.Auth.Web.Pages.Account
{
[AllowAnonymous]
public class LogoutModel : PageModel
{
private readonly SignInManager<O2User> _signInManager;
private readonly ILogger<LogoutModel> _logger;

public LogoutModel(SignInManager<O2User> signInManager, ILogger<LogoutModel> logger)
{
_signInManager = signInManager;
_logger = logger;
}

public void OnGet()
{
}

public async Task<IActionResult> OnPost(string returnUrl = null)
{
await _signInManager.SignOutAsync();
_logger.LogInformation("User logged out.");
if (returnUrl != null)
{
return Redirect(returnUrl);
}
else
{
return Page();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",

await _signInManager.SignInAsync(user, isPersistent: false);

return LocalRedirect(returnUrl);
if (string.IsNullOrWhiteSpace(returnUrl))
{
LocalRedirect("~/");
}
else
{
Redirect(returnUrl);
}

}
foreach (var error in result.Errors)
{
Expand Down
Loading