Skip to content

Commit

Permalink
merge hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Jul 31, 2022
2 parents b9bf791 + 4417a7d commit 762c05e
Show file tree
Hide file tree
Showing 4 changed files with 1,326 additions and 1,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
<div id="manage-web3-login" style="display:none">
<div id="manage-web3-login-alert" class="alert alert-danger" style="display:none"></div>
<p>
<button id="confirm-web3-login" class="btn btn-secondary" type="button">
<button id="confirm-web3-login" class="btn btn-secondary" type="button" disabled>
Yes, I know what I'm doing. Upgrade to Web3 account!
</button>

It will arrive soon!
</p>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ namespace Etherna.SSOServer.Areas.Identity.Pages.Account.Manage
public class Web3UpgradeModel : PageModel
{
// Fields.
private readonly SignInManager<UserBase> signInManager;
private readonly ISsoDbContext ssoDbContext;
private readonly UserManager<UserBase> userManager;
private readonly IUserService userService;
//private readonly SignInManager<UserBase> signInManager;
//private readonly ISsoDbContext ssoDbContext;
//private readonly UserManager<UserBase> userManager;
//private readonly IUserService userService;
private readonly IWeb3AuthnService web3AuthnService;

// Constructor.
public Web3UpgradeModel(
SignInManager<UserBase> signInManager,
ISsoDbContext ssoDbContext,
UserManager<UserBase> userManager,
IUserService userService,
//SignInManager<UserBase> signInManager,
//ISsoDbContext ssoDbContext,
//UserManager<UserBase> userManager,
//IUserService userService,
IWeb3AuthnService web3AuthnService)
{
this.signInManager = signInManager;
this.ssoDbContext = ssoDbContext;
this.userManager = userManager;
this.userService = userService;
//this.signInManager = signInManager;
//this.ssoDbContext = ssoDbContext;
//this.userManager = userManager;
//this.userService = userService;
this.web3AuthnService = web3AuthnService;
}

Expand All @@ -59,45 +59,49 @@ public void OnGet()
public async Task<IActionResult> OnGetRetriveAuthMessageAsync(string etherAddress) =>
new JsonResult(await web3AuthnService.RetriveAuthnMessageAsync(etherAddress));

public async Task<IActionResult> OnGetUpgradeWeb3Async(string etherAddress, string signature)
public Task<IActionResult> OnGetUpgradeWeb3Async(string etherAddress, string signature)
{
// Verify signature.
//get token
var token = await ssoDbContext.Web3LoginTokens.TryFindOneAsync(t => t.EtherAddress == etherAddress);
if (token is null)
{
StatusMessage = $"Web3 authentication code for {etherAddress} address not found";
return RedirectToPage();
}
// Temporary disabled (see: https://etherna.atlassian.net/browse/ESSO-165)
StatusMessage = $"Error, this function is temporary disabled";
return Task.FromResult<IActionResult>(RedirectToPage());

//check signature
var verifiedSignature = web3AuthnService.VerifySignature(token.Code, etherAddress, signature);
if (!verifiedSignature)
{
StatusMessage = $"Invalid signature for web3 authentication";
return RedirectToPage();
}
//// Verify signature.
////get token
//var token = await ssoDbContext.Web3LoginTokens.TryFindOneAsync(t => t.EtherAddress == etherAddress);
//if (token is null)
//{
// StatusMessage = $"Web3 authentication code for {etherAddress} address not found";
// return RedirectToPage();
//}

////check signature
//var verifiedSignature = web3AuthnService.VerifySignature(token.Code, etherAddress, signature);
//if (!verifiedSignature)
//{
// StatusMessage = $"Invalid signature for web3 authentication";
// return RedirectToPage();
//}

//delete used token
await ssoDbContext.Web3LoginTokens.DeleteAsync(token);
////delete used token
//await ssoDbContext.Web3LoginTokens.DeleteAsync(token);

//verify address
if (await userManager.GetUserAsync(User) is not UserWeb2 userWeb2)
return NotFound($"Unable to load user with ID '{userManager.GetUserId(User)}'.");
////verify address
//if (await userManager.GetUserAsync(User) is not UserWeb2 userWeb2)
// return NotFound($"Unable to load user with ID '{userManager.GetUserId(User)}'.");

if (!userWeb2.EtherLoginAddress.IsTheSameAddress(etherAddress))
{
StatusMessage = $"Signing address is different than user's Ethereum login address";
return RedirectToPage();
}
//if (!userWeb2.EtherLoginAddress.IsTheSameAddress(etherAddress))
//{
// StatusMessage = $"Signing address is different than user's Ethereum login address";
// return RedirectToPage();
//}

// Upgrade user to Web3 account.
var userWeb3 = await userService.UpgradeToWeb3(userWeb2);
//// Upgrade user to Web3 account.
//var userWeb3 = await userService.UpgradeToWeb3(userWeb2);

//refresh cookie claims
await signInManager.RefreshSignInAsync(userWeb3);
////refresh cookie claims
//await signInManager.RefreshSignInAsync(userWeb3);

return RedirectToPage("./Index");
//return RedirectToPage("./Index");
}
}
}
Loading

0 comments on commit 762c05e

Please sign in to comment.