2020-04-15 14:09:52 +02:00
|
|
|
using Microsoft.AspNetCore.Identity;
|
2020-04-15 01:42:06 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-05-01 14:07:09 +02:00
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-04-16 12:56:17 +02:00
|
|
|
using System.Linq;
|
2020-04-15 01:42:06 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-04-10 13:35:39 +02:00
|
|
|
using zero.Core;
|
|
|
|
|
using zero.Core.Api;
|
2020-04-15 01:42:06 +02:00
|
|
|
using zero.Core.Entities;
|
2020-04-16 00:56:22 +02:00
|
|
|
using zero.Core.Identity;
|
2020-05-14 13:32:33 +02:00
|
|
|
using zero.Core.Options;
|
2020-05-12 13:42:01 +02:00
|
|
|
using zero.Core.Plugins;
|
2020-05-01 14:07:09 +02:00
|
|
|
using zero.Core.Renderer;
|
2020-04-10 13:35:39 +02:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2020-04-15 01:42:06 +02:00
|
|
|
//[ZeroAuthorize("tobi")]
|
2020-04-10 13:35:39 +02:00
|
|
|
public class TestController : BackofficeController
|
|
|
|
|
{
|
2020-05-11 15:34:47 +02:00
|
|
|
IAuthenticationApi Api;
|
|
|
|
|
ISpacesApi SpacesApi;
|
|
|
|
|
ILanguagesApi LanguagesApi;
|
|
|
|
|
SignInManager<User> SignInManager;
|
2020-04-10 13:35:39 +02:00
|
|
|
|
2020-05-01 14:07:09 +02:00
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
public TestController(IAuthenticationApi api, ISpacesApi spacesApi, ILanguagesApi languagesApi, SignInManager<User> signInManager)
|
2020-04-10 13:35:39 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
2020-05-01 14:07:09 +02:00
|
|
|
SpacesApi = spacesApi;
|
2020-05-04 16:00:39 +02:00
|
|
|
LanguagesApi = languagesApi;
|
2020-04-15 01:42:06 +02:00
|
|
|
SignInManager = signInManager;
|
2020-04-10 13:35:39 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-15 01:42:06 +02:00
|
|
|
|
2020-05-12 13:42:01 +02:00
|
|
|
[HttpGet]
|
|
|
|
|
[ZeroAuthorize(false)]
|
2020-05-14 13:32:33 +02:00
|
|
|
public IActionResult GetPlugins([FromServices] IEnumerable<IZeroPlugin> plugins)
|
2020-05-12 13:42:01 +02:00
|
|
|
{
|
|
|
|
|
return Json(plugins);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
//[HttpGet]
|
|
|
|
|
//[ZeroAuthorize(false)]
|
|
|
|
|
//public IActionResult RenderConfig()
|
|
|
|
|
//{
|
|
|
|
|
// SocialContentRenderer renderer = new SocialContentRenderer();
|
2020-04-30 13:21:01 +02:00
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
// return Json(renderer.Build());
|
|
|
|
|
//}
|
2020-04-30 13:21:01 +02:00
|
|
|
|
|
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
//[HttpGet]
|
|
|
|
|
//[ZeroAuthorize(false)]
|
|
|
|
|
//public async Task<IActionResult> SaveSpaceContent()
|
|
|
|
|
//{
|
|
|
|
|
// TeamMember model = new TeamMember()
|
|
|
|
|
// {
|
|
|
|
|
// IsActive = true,
|
|
|
|
|
// Email = "tobi@test.com",
|
|
|
|
|
// Name = "Tobi",
|
|
|
|
|
// Position = "Chef",
|
|
|
|
|
// VideoUri = "https://swcs.pro"
|
|
|
|
|
// };
|
2020-05-01 14:07:09 +02:00
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
// model.Addresses.Add(new TeamMemberAddress()
|
|
|
|
|
// {
|
|
|
|
|
// City = "Braunau",
|
|
|
|
|
// Street = "My street",
|
|
|
|
|
// No = "23"
|
|
|
|
|
// });
|
2020-05-01 14:07:09 +02:00
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
// return Json(await SpacesApi.Save("team", model));
|
|
|
|
|
//}
|
2020-05-01 14:07:09 +02:00
|
|
|
|
|
|
|
|
|
2020-05-04 16:00:39 +02:00
|
|
|
[HttpGet]
|
|
|
|
|
[ZeroAuthorize(false)]
|
|
|
|
|
public async Task<IActionResult> AddLanguage()
|
|
|
|
|
{
|
|
|
|
|
return Json(await LanguagesApi.Save(new Language()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
IsActive = true,
|
|
|
|
|
Name = "English",
|
|
|
|
|
Code = "en-US",
|
|
|
|
|
IsDefault = true
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-11 15:34:47 +02:00
|
|
|
//[HttpGet]
|
|
|
|
|
//[ZeroAuthorize(false)]
|
|
|
|
|
//public async Task<IActionResult> GetSpaceList()
|
|
|
|
|
//{
|
|
|
|
|
// return Json(await SpacesApi.GetList<TeamMember>("team"));
|
|
|
|
|
//}
|
2020-05-01 14:07:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ZeroAuthorize(false)]
|
|
|
|
|
public IActionResult GetRenderer([FromQuery] string alias)
|
|
|
|
|
{
|
|
|
|
|
Space space = SpacesApi.GetByAlias(alias);
|
|
|
|
|
|
2020-05-14 13:32:33 +02:00
|
|
|
AbstractGenericRenderer renderer = Options.Renderers.GetAllItems().FirstOrDefault(x => x.TargetType == space.Type);
|
2020-05-01 14:07:09 +02:00
|
|
|
|
|
|
|
|
if (renderer == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json(renderer.Build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-04-15 01:42:06 +02:00
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Login([FromQuery] string username, [FromQuery] string password)
|
|
|
|
|
{
|
|
|
|
|
Microsoft.AspNetCore.Identity.SignInResult result = await SignInManager.PasswordSignInAsync(username, password, false, true);
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
username,
|
|
|
|
|
password,
|
|
|
|
|
result
|
2020-04-10 13:35:39 +02:00
|
|
|
});
|
|
|
|
|
}
|
2020-04-15 14:09:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[ZeroAuthorize]
|
|
|
|
|
public async Task<IActionResult> GetUser()
|
|
|
|
|
{
|
|
|
|
|
User user = await SignInManager.UserManager.GetUserAsync(HttpContext.User);
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
user
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-04-16 12:56:17 +02:00
|
|
|
[ZeroAuthorize]
|
|
|
|
|
public IActionResult GetUserClaims()
|
|
|
|
|
{
|
|
|
|
|
return Json(HttpContext.User.Claims.Select(claim => new { claim.Type, claim.Value }).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-04-15 14:09:52 +02:00
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Logout()
|
|
|
|
|
{
|
|
|
|
|
await SignInManager.SignOutAsync();
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = true
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-04-10 13:35:39 +02:00
|
|
|
}
|
|
|
|
|
}
|