Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the ASP.NET 4.8 samples to use file-scoped namespaces #320

Merged
merged 1 commit into from
May 31, 2024
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ This repository contains samples demonstrating **how to use [OpenIddict](https:/

## OWIN/ASP.NET 4.8 samples
- [Fornax](samples/Fornax): authorization code flow demo using ASP.NET Web Forms 4.8 and OWIN/Katana, with a .NET Framework 4.8 console acting as the client.
- [Mortis](samples/Mortis): authorization code flow demo, with an ASP.NET MVC 5.2 application acting as the client.
- [Kalarba](samples/Kalarba): resource owner password credentials demo using OWIN/Katana, ASP.NET Web API and the OpenIddict degraded mode.
- [Mortis](samples/Mortis): authorization code flow demo using ASP.NET MVC 5.2 and ASP.NET Web API 2.2, with an ASP.NET MVC 5.2 application acting as the client.
- [Kalarba](samples/Kalarba): resource owner password credentials demo using OWIN/Katana, ASP.NET Web API 2.2 and the OpenIddict degraded mode.

## External samples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
using Microsoft.Extensions.Logging;
using System.Diagnostics;

namespace Dantooine.WebAssembly.Server.Pages
namespace Dantooine.WebAssembly.Server.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;
private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
9 changes: 4 additions & 5 deletions samples/Fornax/Fornax.Server/About.aspx.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Web.UI;

namespace Fornax.Server
namespace Fornax.Server;

public partial class About : Page
{
public partial class About : Page
protected void Page_Load(object sender, EventArgs e)
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}
7 changes: 3 additions & 4 deletions samples/Fornax/Fornax.Server/About.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions samples/Fornax/Fornax.Server/Account/AddPhoneNumber.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;

namespace Fornax.Server.Account
namespace Fornax.Server.Account;

public partial class AddPhoneNumber : System.Web.UI.Page
{
public partial class AddPhoneNumber : System.Web.UI.Page
protected void PhoneNumber_Click(object sender, EventArgs e)
{
protected void PhoneNumber_Click(object sender, EventArgs e)
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var code = manager.GenerateChangePhoneNumberToken(User.Identity.GetUserId(), PhoneNumber.Text);
if (manager.SmsService != null)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var code = manager.GenerateChangePhoneNumberToken(User.Identity.GetUserId(), PhoneNumber.Text);
if (manager.SmsService != null)
var message = new IdentityMessage
{
var message = new IdentityMessage
{
Destination = PhoneNumber.Text,
Body = "Your security code is " + code
};

manager.SmsService.Send(message);
}
Destination = PhoneNumber.Text,
Body = "Your security code is " + code
};

Response.Redirect("/Account/VerifyPhoneNumber?PhoneNumber=" + HttpUtility.UrlEncode(PhoneNumber.Text));
manager.SmsService.Send(message);
}

Response.Redirect("/Account/VerifyPhoneNumber?PhoneNumber=" + HttpUtility.UrlEncode(PhoneNumber.Text));
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 19 additions & 20 deletions samples/Fornax/Fornax.Server/Account/Confirm.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;

namespace Fornax.Server.Account
namespace Fornax.Server.Account;

public partial class Confirm : Page
{
public partial class Confirm : Page
protected string StatusMessage
{
protected string StatusMessage
{
get;
private set;
}
get;
private set;
}

protected void Page_Load(object sender, EventArgs e)
protected void Page_Load(object sender, EventArgs e)
{
string code = IdentityHelper.GetCodeFromRequest(Request);
string userId = IdentityHelper.GetUserIdFromRequest(Request);
if (code != null && userId != null)
{
string code = IdentityHelper.GetCodeFromRequest(Request);
string userId = IdentityHelper.GetUserIdFromRequest(Request);
if (code != null && userId != null)
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = manager.ConfirmEmail(userId, code);
if (result.Succeeded)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = manager.ConfirmEmail(userId, code);
if (result.Succeeded)
{
successPanel.Visible = true;
return;
}
successPanel.Visible = true;
return;
}
successPanel.Visible = false;
errorPanel.Visible = true;
}
successPanel.Visible = false;
errorPanel.Visible = true;
}
}
59 changes: 29 additions & 30 deletions samples/Fornax/Fornax.Server/Account/Confirm.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 22 additions & 23 deletions samples/Fornax/Fornax.Server/Account/Forgot.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,34 @@
using Microsoft.AspNet.Identity.Owin;
using Fornax.Server.Models;

namespace Fornax.Server.Account
namespace Fornax.Server.Account;

public partial class ForgotPassword : Page
{
public partial class ForgotPassword : Page
protected void Page_Load(object sender, EventArgs e)
{
protected void Page_Load(object sender, EventArgs e)
{
}
}

protected void Forgot(object sender, EventArgs e)
protected void Forgot(object sender, EventArgs e)
{
if (IsValid)
{
if (IsValid)
// Validate the user's email address
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
ApplicationUser user = manager.FindByName(Email.Text);
if (user == null || !manager.IsEmailConfirmed(user.Id))
{
// Validate the user's email address
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
ApplicationUser user = manager.FindByName(Email.Text);
if (user == null || !manager.IsEmailConfirmed(user.Id))
{
FailureText.Text = "The user either does not exist or is not confirmed.";
ErrorMessage.Visible = true;
return;
}
// For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
// Send email with the code and the redirect to reset password page
//string code = manager.GeneratePasswordResetToken(user.Id);
//string callbackUrl = IdentityHelper.GetResetPasswordRedirectUrl(code, Request);
//manager.SendEmail(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>.");
loginForm.Visible = false;
DisplayEmail.Visible = true;
FailureText.Text = "The user either does not exist or is not confirmed.";
ErrorMessage.Visible = true;
return;
}
// For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
// Send email with the code and the redirect to reset password page
//string code = manager.GeneratePasswordResetToken(user.Id);
//string callbackUrl = IdentityHelper.GetResetPasswordRedirectUrl(code, Request);
//manager.SendEmail(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>.");
loginForm.Visible = false;
DisplayEmail.Visible = true;
}
}
}
Loading