AccountController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Abp.UI;
  2. using Abp.WebApi.Controllers;
  3. using Microsoft.Owin.Security.OAuth;
  4. namespace ShwasherSys.Api.Controllers
  5. {
  6. public class AccountController : AbpApiController
  7. {
  8. public static OAuthBearerAuthenticationOptions OAuthBearerOptions { get; private set; }
  9. //private readonly LogInManager _logInManager;
  10. static AccountController()
  11. {
  12. OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
  13. }
  14. //public AccountController(LogInManager logInManager)
  15. //{
  16. // _logInManager = logInManager;
  17. // LocalizationSourceName = IwbYueConsts.LocalizationSourceName;
  18. //}
  19. //[HttpPost]
  20. //public async Task<AjaxResponse> Authenticate(LoginModel loginModel)
  21. //{
  22. // CheckModelState();
  23. // var loginResult = await GetLoginResultAsync(
  24. // loginModel.UsernameOrEmailAddress,
  25. // loginModel.Password,
  26. // loginModel.TenancyName
  27. // );
  28. // var ticket = new AuthenticationTicket(loginResult.Identity, new AuthenticationProperties());
  29. // var currentUtc = new SystemClock().UtcNow;
  30. // ticket.Properties.IssuedUtc = currentUtc;
  31. // ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(30));
  32. // return new AjaxResponse(OAuthBearerOptions.AccessTokenFormat.Protect(ticket));
  33. //}
  34. //private async Task<AbpLoginResult<Tenant, User>> GetLoginResultAsync(string usernameOrEmailAddress, string password, string tenancyName)
  35. //{
  36. // var loginResult = await _logInManager.LoginAsync(usernameOrEmailAddress, password, tenancyName);
  37. // switch (loginResult.Result)
  38. // {
  39. // case AbpLoginResultType.Success:
  40. // return loginResult;
  41. // default:
  42. // throw CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress, tenancyName);
  43. // }
  44. //}
  45. //private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
  46. //{
  47. // switch (result)
  48. // {
  49. // case AbpLoginResultType.Success:
  50. // return new ApplicationException("Don't call this method with a success result!");
  51. // case AbpLoginResultType.InvalidUserNameOrEmailAddress:
  52. // case AbpLoginResultType.InvalidPassword:
  53. // return new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword"));
  54. // case AbpLoginResultType.InvalidTenancyName:
  55. // return new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName));
  56. // case AbpLoginResultType.TenantIsNotActive:
  57. // return new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName));
  58. // case AbpLoginResultType.UserIsNotActive:
  59. // return new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress));
  60. // case AbpLoginResultType.UserEmailIsNotConfirmed:
  61. // return new UserFriendlyException(L("LoginFailed"), "Your email address is not confirmed. You can not login"); //TODO: localize message
  62. // default: //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
  63. // Logger.Warn("Unhandled login fail reason: " + result);
  64. // return new UserFriendlyException(L("LoginFailed"));
  65. // }
  66. //}
  67. protected virtual void CheckModelState()
  68. {
  69. if (!ModelState.IsValid)
  70. {
  71. throw new UserFriendlyException("Invalid request!");
  72. }
  73. }
  74. }
  75. }