using APT.BaseData.Domain.Entities.OP;
using APT.BaseData.Domain.Msg;
using APT.Infrastructure.Core;
using APT.Utility;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APT.OP.WebApi.Controllers.Api
{
    [Route("api/OP/User")]
    public partial class UserController : AuthorizeApiController<T_OP_USER>
    {
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("ReSetPwd")]
        public JsonActionResult<bool> ReSetPwd([FromBody] KeywordFilter filter)
        {
            return SafeExecute<bool>(() =>
            {


                string userId = filter.Keyword;
                if (string.IsNullOrEmpty(userId))
                    userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserId;
                if (string.IsNullOrEmpty(userId))
                    throw new Exception(ErrMsg.CM_NOEXIT_USER);
                var user = this.GetEntity<T_OP_USER>(userId);
                user.PASSWORD = "E10ADC3949BA59ABBE56E057F20F883E";//默认密码123456
                this.UpdateEntity(user);
                return true;
            });
        }
    }
}
