Skip to content

Commit

Permalink
Fixes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Jan 15, 2019
1 parent 9dc5af9 commit fcc0025
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 2,968 deletions.
2 changes: 1 addition & 1 deletion appveyor.build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 6.0.0-build.{build}
version: 6.1.0-build.{build}
skip_tags: true
image: Visual Studio 2017
build_script:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 6.0.1
version: 6.1.0
skip_non_tags: true
image: Visual Studio 2017
build_script:
Expand Down
6 changes: 3 additions & 3 deletions src/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
[assembly: AssemblyCulture("")]


[assembly: AssemblyVersion("6.0.1")]
[assembly: AssemblyFileVersion("6.0.1")]
[assembly: AssemblyInformationalVersion("6.0.1")]
[assembly: AssemblyVersion("6.1.0")]
[assembly: AssemblyFileVersion("6.1.0")]
[assembly: AssemblyInformationalVersion("6.1.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
using Microsoft.Owin.Security;
using UmbracoIdentity.Web.Models.UmbracoIdentity;
using Umbraco.Web;
using UmbracoIdentity.Web;
using Umbraco.Core;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using UmbracoIdentity;
using UmbracoIdentity.Models;
using IdentityExtensions = UmbracoIdentity.IdentityExtensions;

namespace UmbracoIdentity.Web.Controllers
{
Expand Down Expand Up @@ -105,67 +102,46 @@ public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
await SignInAsync(user, isPersistent: false);
return RedirectToLocal(returnUrl);
}
else
{
// If the user does not have an account, then prompt the user to create an account
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;

return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
}
}

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
{
if (User.Identity.IsAuthenticated)
if (loginInfo.Email.IsNullOrWhiteSpace())
{
//go home, already authenticated
return RedirectToLocal(returnUrl);
ViewBag.Description = "No email address found in the claims, ensure your OAuth provider is configured to return the Email address";
return View("ExternalLoginFailure");
}

if (ModelState.IsValid)
{
// Get the information about the user from the external login provider
var info = await OwinContext.Authentication.GetExternalLoginInfoAsync();
if (info == null)
{
return View("ExternalLoginFailure");
}
// If the user does not have an account, then create one

var user = new UmbracoApplicationMember()
{
Name = info.ExternalIdentity.Name,
UserName = model.Email,
Email = model.Email
};
user = new UmbracoApplicationMember()
{
Name = loginInfo.ExternalIdentity.Name,
UserName = loginInfo.Email,
Email = loginInfo.Email
};

var result = await UserManager.CreateAsync(user);
var result = await UserManager.CreateAsync(user);
if (result.Succeeded)
{
result = await UserManager.AddLoginAsync(user.Id, loginInfo.Login);
if (result.Succeeded)
{
result = await UserManager.AddLoginAsync(user.Id, info.Login);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
await SignInAsync(user, isPersistent: false);

// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// SendEmail(user.Email, callbackUrl, "Confirm your account", "Please confirm your account by clicking this link");
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// SendEmail(user.Email, callbackUrl, "Confirm your account", "Please confirm your account by clicking this link");

return RedirectToLocal(returnUrl);
}
return RedirectToLocal(returnUrl);
}
AddModelErrors(result);
}

ViewBag.ReturnUrl = returnUrl;
return View(model);
//something went wrong
AddModelErrors(result);
return View("ExternalLoginFailure");
}


[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LinkLogin(string provider, string returnUrl = null)
Expand All @@ -190,7 +166,7 @@ public async Task<ActionResult> LinkLoginCallback(string returnUrl)
TempData["LinkLoginError"] = new[] { "An error occurred, could not get external login info" };
return RedirectToLocal(returnUrl);
}
var result = await UserManager.AddLoginAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity), loginInfo.Login);
var result = await UserManager.AddLoginAsync(User.Identity.GetUserId<int>(), loginInfo.Login);
if (result.Succeeded)
{
return RedirectToLocal(returnUrl);
Expand All @@ -205,12 +181,12 @@ public async Task<ActionResult> LinkLoginCallback(string returnUrl)
public async Task<ActionResult> Disassociate(string loginProvider, string providerKey)
{
var result = await UserManager.RemoveLoginAsync(
UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity),
User.Identity.GetUserId<int>(),
new UserLoginInfo(loginProvider, providerKey));

if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity));
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
await SignInAsync(user, isPersistent: false);
return RedirectToCurrentUmbracoPage();
}
Expand All @@ -230,7 +206,7 @@ public ActionResult ExternalLoginFailure()
[ChildActionOnly]
public ActionResult RemoveAccountList()
{
var linkedAccounts = UserManager.GetLogins(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity));
var linkedAccounts = UserManager.GetLogins(User.Identity.GetUserId<int>());
ViewBag.ShowRemoveButton = HasPassword() || linkedAccounts.Count > 1;
return PartialView(linkedAccounts);
}
Expand All @@ -243,7 +219,7 @@ public async Task<ActionResult> ToggleRole(string roleName)
{
if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentNullException("role cannot be null");

var user = await UserManager.FindByIdAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity));
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
if (user != null)
{
var found = user.Roles.FirstOrDefault(x => x.RoleName == roleName);
Expand Down Expand Up @@ -276,7 +252,7 @@ public async Task<ActionResult> ToggleRole(string roleName)
[ChildActionOnly]
public async Task<ActionResult> ShowRoles()
{
var user = await UserManager.FindByIdAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity));
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());

var model = new RoleManagementModel();

Expand Down Expand Up @@ -314,10 +290,10 @@ public async Task<ActionResult> ManagePassword([Bind(Prefix = "managePasswordMod
{
if (ModelState.IsValid)
{
IdentityResult result = await UserManager.ChangePasswordAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity), model.OldPassword, model.NewPassword);
IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId<int>(), model.OldPassword, model.NewPassword);
if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity));
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
await SignInAsync(user, isPersistent: false);
TempData["ChangePasswordSuccess"] = true;
return RedirectToCurrentUmbracoPage();
Expand All @@ -339,7 +315,7 @@ public async Task<ActionResult> ManagePassword([Bind(Prefix = "managePasswordMod

if (ModelState.IsValid)
{
IdentityResult result = await UserManager.AddPasswordAsync(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity), model.NewPassword);
IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId<int>(), model.NewPassword);
if (result.Succeeded)
{
TempData["ChangePasswordSuccess"] = true;
Expand Down Expand Up @@ -480,7 +456,7 @@ private void AddModelErrors(IdentityResult result, string prefix = "")

private bool HasPassword()
{
var user = UserManager.FindById(UmbracoIdentity.IdentityExtensions.GetUserId<int>(User.Identity));
var user = UserManager.FindById(User.Identity.GetUserId<int>());
if (user != null)
{
return !user.PasswordHash.IsNullOrWhiteSpace();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,28 @@

<h2>@ViewBag.Title.</h2>
<h3 class="text-danger">Unsuccessful login with service.</h3>

@if (ViewBag.Description != null)
{
<p>@ViewBag.Description</p>
}

@if (ViewData.ModelState.Count > 0)
{
<ul>
@foreach (var state in ViewData.ModelState)
{
<li>
@state.Key :
<ul>
@foreach (var error in state.Value.Errors)
{
<li>
@error.ErrorMessage
</li>
}
</ul>
</li>
}
</ul>
}
Loading

0 comments on commit fcc0025

Please sign in to comment.