zhaolei
2020-11-20 921de2254ff5712a44ed8575ee8efe34252f6603
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Bootstrap.DataAccess;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
 
namespace Bootstrap.Admin.Controllers
{
    /// <summary>
    /// 新用户注册控制器
    /// </summary>
    [Route("api/[controller]")]
    [Authorize]
    [ApiController]
    public class NewController : ControllerBase
    {
        /// <summary>
        /// 通知管理页面获得所有新用户方法调用
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<object> Get()
        {
            return UserHelper.RetrieveNewUsers().Select(user => new
            {
                user.Id,
                user.UserName,
                user.DisplayName,
                user.Description,
                user.RegisterTime
            });
        }
        /// <summary>
        /// 新用户授权/拒绝接口
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public bool Put([FromBody]User value)
        {
            var ret = false;
            var userName = User.Identity.Name;
            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(value.Id))
            {
                if (value.UserStatus == UserStates.ApproveUser)
                {
                    ret = UserHelper.Approve(value.Id, userName);
                }
                else if (value.UserStatus == UserStates.RejectUser)
                {
                    ret = UserHelper.Reject(value.Id, userName);
                }
            }
            return ret;
        }
    }
}