2019-03-22 15:46:32 +08:00
|
|
|
|
using Bootstrap.Admin.Query;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-11-21 21:01:50 +08:00
|
|
|
|
using System;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/[controller]")]
|
2018-11-24 15:12:44 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class UsersController : ControllerBase
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2018-11-24 15:12:44 +08:00
|
|
|
|
public QueryData<object> Get([FromQuery]QueryUserOption value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
return value.RetrieveData();
|
|
|
|
|
}
|
2018-08-10 18:01:26 +08:00
|
|
|
|
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
2018-09-13 19:21:35 +08:00
|
|
|
|
/// <param name="type"></param>
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("{id}")]
|
2018-10-31 15:49:30 +08:00
|
|
|
|
public IEnumerable<object> Post(string id, [FromQuery]string type)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
2019-01-17 12:13:30 +08:00
|
|
|
|
IEnumerable<object> ret = null;
|
2018-09-13 19:21:35 +08:00
|
|
|
|
switch (type)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
case "role":
|
2019-01-17 12:13:30 +08:00
|
|
|
|
ret = UserHelper.RetrievesByRoleId(id).Select(p => new
|
2018-10-31 15:49:30 +08:00
|
|
|
|
{
|
|
|
|
|
p.Id,
|
|
|
|
|
p.DisplayName,
|
|
|
|
|
p.UserName,
|
|
|
|
|
p.Checked
|
|
|
|
|
});
|
2019-01-17 12:13:30 +08:00
|
|
|
|
break;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
case "group":
|
2019-01-17 12:13:30 +08:00
|
|
|
|
ret = UserHelper.RetrievesByGroupId(id);
|
|
|
|
|
break;
|
2019-03-05 14:53:34 +08:00
|
|
|
|
case "reset":
|
|
|
|
|
ret = UserHelper.RetrieveResetReasonsByUserName(id).Select(u => new { u.Key, u.Value });
|
|
|
|
|
break;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
2019-01-17 12:13:30 +08:00
|
|
|
|
return ret;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
2019-03-22 15:46:32 +08:00
|
|
|
|
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <summary>
|
2018-10-30 17:02:36 +08:00
|
|
|
|
/// 前台User View调用,新建/更新用户
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
[HttpPost]
|
2019-03-22 15:46:32 +08:00
|
|
|
|
[ButtonAuthorize(Url = "~/Admin/Users", Auth = "add,edit")]
|
2018-06-07 12:25:03 +08:00
|
|
|
|
public bool Post([FromBody]User value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
2018-09-13 19:51:11 +08:00
|
|
|
|
var ret = false;
|
2018-10-30 13:07:29 +08:00
|
|
|
|
if (string.IsNullOrEmpty(value.Id))
|
2018-09-13 19:51:11 +08:00
|
|
|
|
{
|
|
|
|
|
value.Description = string.Format("管理员{0}创建用户", User.Identity.Name);
|
|
|
|
|
value.ApprovedBy = User.Identity.Name;
|
2018-11-21 21:01:50 +08:00
|
|
|
|
value.ApprovedTime = DateTime.Now;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
ret = UserHelper.Save(value);
|
2018-09-13 19:51:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
ret = UserHelper.Update(value.Id, value.Password, value.DisplayName);
|
2018-09-13 19:51:11 +08:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
2019-03-22 15:46:32 +08:00
|
|
|
|
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
2019-03-22 15:46:32 +08:00
|
|
|
|
/// <param name="values"></param>
|
2018-09-13 19:21:35 +08:00
|
|
|
|
/// <param name="type"></param>
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut("{id}")]
|
2019-03-22 15:46:32 +08:00
|
|
|
|
[ButtonAuthorize(Url = "~/Admin/Users", Auth = "assignRole,assignGroup")]
|
|
|
|
|
public bool Put(string id, [FromBody]IEnumerable<string> values, [FromQuery]string type)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
var ret = false;
|
2018-09-13 19:21:35 +08:00
|
|
|
|
switch (type)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
case "role":
|
2019-03-22 15:46:32 +08:00
|
|
|
|
ret = RoleHelper.SaveByUserId(id, values);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
break;
|
|
|
|
|
case "group":
|
2019-03-22 15:46:32 +08:00
|
|
|
|
ret = GroupHelper.SaveByUserId(id, values);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-03-22 15:46:32 +08:00
|
|
|
|
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
[HttpDelete]
|
2019-03-22 15:46:32 +08:00
|
|
|
|
[ButtonAuthorize(Url = "~/Admin/Users", Auth = "del")]
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public bool Delete([FromBody]IEnumerable<string> value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
return UserHelper.Delete(value);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
2019-03-22 15:46:32 +08:00
|
|
|
|
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[HttpOptions]
|
|
|
|
|
public string Options()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-20 17:55:29 +08:00
|
|
|
|
}
|