Browse Source

Added user integration for 3rd party apps.

pull/7950/head
Alper Ebicoglu 8 years ago
parent
commit
cd98341904
  1. 17
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LoginController.cs
  2. 4
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/Models/AbpLoginResult.cs
  3. 4
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs
  4. 16
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  5. 18
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

17
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LoginController.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -29,7 +30,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
[HttpPost] [HttpPost]
[Route("")] [Route("")]
public virtual async Task<IActionResult> Login(UserLoginInfo login) public virtual async Task<AbpLoginResult> Login(UserLoginInfo login)
{ {
if (login == null) if (login == null)
{ {
@ -55,28 +56,28 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
if (result.IsLockedOut) if (result.IsLockedOut)
{ {
return Json(new AbpLoginResult(LoginResultType.LockedOut)); return new AbpLoginResult(LoginResultType.LockedOut);
} }
if (result.RequiresTwoFactor) if (result.RequiresTwoFactor)
{ {
return Json(new AbpLoginResult(LoginResultType.RequiresTwoFactor)); return new AbpLoginResult(LoginResultType.RequiresTwoFactor);
} }
if (result.IsNotAllowed) if (result.IsNotAllowed)
{ {
return Json(new AbpLoginResult(LoginResultType.NotAllowed)); return new AbpLoginResult(LoginResultType.NotAllowed);
} }
if (!result.Succeeded) if (!result.Succeeded)
{ {
return Json(new AbpLoginResult(LoginResultType.InvalidUserNameOrPassword)); return new AbpLoginResult(LoginResultType.InvalidUserNameOrPassword);
} }
return Json(new AbpLoginResult(LoginResultType.Success) return new AbpLoginResult(LoginResultType.Success)
{ {
IdentityCookieToken = GetCookieValueFromResponse(AspNetCoreIdentityCookieName) //todo: cookie name can be retrieved from UseAuthentication options IdentityCookieToken = GetCookieValueFromResponse(AspNetCoreIdentityCookieName)
}); };
} }
private string GetCookieValueFromResponse(string cookieName) private string GetCookieValueFromResponse(string cookieName)

4
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/Models/AbpLoginResult.cs

@ -1,4 +1,6 @@
using Volo.Abp.Account.Web.Areas.Account.Controllers.Models; using System;
using Volo.Abp.Account.Web.Areas.Account.Controllers.Models;
using Volo.Abp.Identity;
namespace Volo.Abp.Account.Web.Areas.Account.Controllers namespace Volo.Abp.Account.Web.Areas.Account.Controllers
{ {

4
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs

@ -15,5 +15,9 @@ namespace Volo.Abp.Identity
Task<GetPermissionListResultDto> GetPermissionsAsync(Guid id); Task<GetPermissionListResultDto> GetPermissionsAsync(Guid id);
Task UpdatePermissionsAsync(Guid id, UpdatePermissionsDto input); Task UpdatePermissionsAsync(Guid id, UpdatePermissionsDto input);
Task<IdentityUserDto> FindByUsernameAsync(string username);
Task<IdentityUserDto> FindByEmailAsync(string email);
} }
} }

16
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -112,7 +112,21 @@ namespace Volo.Abp.Identity
{ {
await _permissionAppServiceHelper.UpdateAsync(UserPermissionValueProvider.ProviderName, id.ToString(), input); await _permissionAppServiceHelper.UpdateAsync(UserPermissionValueProvider.ProviderName, id.ToString(), input);
} }
public async Task<IdentityUserDto> FindByUsernameAsync(string username)
{
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
await _userManager.FindByNameAsync(username)
);
}
public async Task<IdentityUserDto> FindByEmailAsync(string email)
{
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
await _userManager.FindByEmailAsync(email)
);
}
private async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input) private async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input)
{ {
(await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors();

18
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

@ -63,5 +63,23 @@ namespace Volo.Abp.Identity
{ {
return _userAppService.UpdatePermissionsAsync(id, input); return _userAppService.UpdatePermissionsAsync(id, input);
} }
[HttpGet]
public virtual Task<IdentityUserDto> FindByUsernameAsync(string username)
{
if (CurrentUser.Id.HasValue)
{
return _userAppService.FindByUsernameAsync(username);
}
Console.WriteLine("Not logged in!");
throw new UnauthorizedAccessException();
}
[HttpGet]
public virtual Task<IdentityUserDto> FindByEmailAsync(string email)
{
return _userAppService.FindByEmailAsync(email);
}
} }
} }

Loading…
Cancel
Save