init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,146 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Http;
|
||||
using Kreta.BusinessLogic.Helpers;
|
||||
using Kreta.BusinessLogic.Security;
|
||||
using Kreta.BusinessLogic.Utils;
|
||||
using Kreta.Core.ConnectionType;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Security;
|
||||
using Kreta.User.WebApi.Attributes;
|
||||
using Kreta.User.WebApi.Infrastructure;
|
||||
using static Kreta.Core.Constants;
|
||||
|
||||
namespace Kreta.User.WebApi.Controllers
|
||||
{
|
||||
[ApiKeyAuthorization]
|
||||
[RoutePrefix(Constants.RoutePrefix + Constants.VersionName)]
|
||||
public class AuthenticationController : ApiController
|
||||
{
|
||||
[Route("authenticate")]
|
||||
[HttpPost]
|
||||
public IHttpActionResult Authenticate(AuthenticationRequest authenticationRequest)
|
||||
{
|
||||
var organizationIdentifier = CommonUtils.GetOrganizationIdentifier();
|
||||
AuthenticationInfo authenticationInfo;
|
||||
|
||||
try
|
||||
{
|
||||
authenticationInfo = !string.IsNullOrWhiteSpace(authenticationRequest.Password)
|
||||
? AuthenticateByUserNameAndPassword(authenticationRequest.UserName, authenticationRequest.Password, organizationIdentifier)
|
||||
: AuthenticateByUserNameAndUniqueId(authenticationRequest.IdpUniqueId, organizationIdentifier);
|
||||
|
||||
}
|
||||
catch (FrameworkException ex) when (ex is UserNotFoundException || ex is NextTanevBelepesException || ex is ArchivBelepesException)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
|
||||
if (authenticationInfo == null)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
return Ok(authenticationInfo);
|
||||
}
|
||||
|
||||
[Route("status")]
|
||||
[HttpGet]
|
||||
public IHttpActionResult Status()
|
||||
{
|
||||
return Ok("IAmAlive");
|
||||
}
|
||||
|
||||
[Route("changePassword")]
|
||||
[HttpPost]
|
||||
public IHttpActionResult ChangePassword(ChangePasswordRequest changePasswordRequest)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var organizationIdentifier = CommonUtils.GetOrganizationIdentifier();
|
||||
|
||||
var loginInfo = new FelhasznaloBelepesHelper(new OrganizationConnectionType(0, 0, organizationIdentifier, 0)).AuthenticateUser(changePasswordRequest.Username, changePasswordRequest.Password);
|
||||
|
||||
if (loginInfo == null || loginInfo.PasswordState == PasswordState.INVALID)
|
||||
{
|
||||
throw new IncorrectPasswordException(loginInfo.BelepesiNev);
|
||||
}
|
||||
|
||||
new FelhasznaloBelepesHelper(new MobileConnectionType(loginInfo.FelhasznaloId, loginInfo.IntezmenyId, loginInfo.IntezmenyAzonosito, loginInfo.AktivTanevId))
|
||||
.ChangeUserPassword(changePasswordRequest.Username, changePasswordRequest.NewPassword);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private AuthenticationInfo AuthenticateByUserNameAndPassword(string userName, string password, string organizationIdentifier)
|
||||
{
|
||||
var loginInfo = new FelhasznaloBelepesHelper(new OrganizationConnectionType(0, 0, organizationIdentifier, 0)).AuthenticateUser(userName, password);
|
||||
|
||||
if (loginInfo == null || loginInfo.PasswordState == PasswordState.INVALID)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var authenticationInfo = new AuthenticationHelper(new MobileConnectionType(loginInfo.FelhasznaloId, loginInfo.IntezmenyId, loginInfo.IntezmenyAzonosito, loginInfo.AktivTanevId)).GetAuthenticationInfo(loginInfo, intezmenyiDictionaryEnvironmentName: string.Empty);
|
||||
|
||||
return authenticationInfo;
|
||||
}
|
||||
|
||||
private AuthenticationInfo AuthenticateByUserNameAndUniqueId(Guid idpUniqueId, string organizationIdentifier)
|
||||
{
|
||||
var loginInfo = new FelhasznaloBelepesHelper(new OrganizationConnectionType(0, 0, organizationIdentifier, 0)).GetLoginInfo(bejelentkezesiNev: null, idpUniqueId);
|
||||
|
||||
if (loginInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var authenticationInfo = new AuthenticationHelper(new MobileConnectionType(loginInfo.FelhasznaloId, loginInfo.IntezmenyId, loginInfo.IntezmenyAzonosito, loginInfo.AktivTanevId)).GetAuthenticationInfo(loginInfo, intezmenyiDictionaryEnvironmentName: string.Empty);
|
||||
|
||||
var userUniqueId = authenticationInfo.TutelaryIdpUniqueId ?? authenticationInfo.InstituteUserIdpUniqueId;
|
||||
|
||||
if (idpUniqueId != userUniqueId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return authenticationInfo;
|
||||
}
|
||||
|
||||
public class AuthenticationRequest
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public Guid IdpUniqueId { get; set; }
|
||||
}
|
||||
|
||||
public class ChangePasswordRequest
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(General.JelszoMaximumKarakterekSzama, MinimumLength = General.JelszoMinimumKarakterekSzama)]
|
||||
public string NewPassword { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using System.Web.Http;
|
||||
using Kreta.User.WebApi.Attributes;
|
||||
using Kreta.User.WebApi.Infrastructure;
|
||||
|
||||
namespace Kreta.User.WebApi.Controllers
|
||||
{
|
||||
[ApiKeyAuthorization]
|
||||
[RoutePrefix(Constants.RoutePrefix + Constants.VersionName)]
|
||||
public class InformationController : ApiController
|
||||
{
|
||||
private readonly Core.VersionInfo _versionInfo;
|
||||
|
||||
public InformationController()
|
||||
{
|
||||
_versionInfo = Core.KretaVersion.Instance;
|
||||
}
|
||||
|
||||
[Route("getversion")]
|
||||
[HttpGet]
|
||||
public Core.VersionInfo GetVersion()
|
||||
{
|
||||
return _versionInfo;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue