Gen 方法 去除注释代码
GetUser 方法 密码判断 转大写 少定义一个参数
This commit is contained in:
parent
06bdd14bd4
commit
0ac5707edb
@ -46,28 +46,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
if (request.Grant_type == (int)PFGrantTypeEnum.账号密码)
|
||||
{
|
||||
var client = new System.Net.Http.HttpClient();
|
||||
///
|
||||
//var disco = await client.GetDiscoveryDocumentAsync(ConfigurationManager.AppSettings["IdentityServer"]);
|
||||
//if (disco.IsError)
|
||||
//{
|
||||
// Console.WriteLine(disco.Error);
|
||||
// return BadRequest(new { error = disco.Error, error_description = "验证服务器无法连接" });
|
||||
//}
|
||||
|
||||
BaseFilter filter = new BaseFilter();
|
||||
//if (string.IsNullOrEmpty(request.orgId))
|
||||
//{
|
||||
//using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"]))
|
||||
//{
|
||||
// var opUser = context.GetEntity<T_OP_ALLUSER>(i => i.CODE == request.UserName || i.PHONE == request.UserName, new string[] { "CODE", "TENANT", "PHONE" });
|
||||
// if (opUser == null)
|
||||
// throw new Exception("用户账号不存在");
|
||||
// filter.IsSpecifyDb = true;
|
||||
// filter.SpecifyTenant = opUser.TENANT;
|
||||
// filter.IgnoreOrgRule = true;
|
||||
// //request.orgId = opUser.ORG_ID.ToString();
|
||||
//}
|
||||
//}
|
||||
if (request.ClientId != "app")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(request.random))
|
||||
@ -82,29 +61,16 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
return BadRequest(new { error = "error VERIFY_CODE ", error_description = "验证码不正确" });
|
||||
}
|
||||
}
|
||||
//filter.OrgId = new Guid(request.orgId);
|
||||
}
|
||||
else
|
||||
{
|
||||
//filter.IgnoreOrgRule = true;
|
||||
//filter.IsMultipleDb = true;
|
||||
|
||||
}
|
||||
var user = this.GetUser(request, filter);
|
||||
if (user == null)
|
||||
return BadRequest(new { error = "error Account ", error_description = "用户不存在或者密码错误" }); ;
|
||||
// request access token
|
||||
//var scope = "offline_access oEnergyPF oEnergyBD oEnergyDD oEnergyEA oEnergyED oEnergyEM oEnergyFC oEnergyFM oEnergyKR oEnergyLG" +
|
||||
// " oEnergyMR oEnergyNW oEnergyPM oEnergyQC oEnergyUT oEnergyMT";
|
||||
// oEnergyMT oEnergySO oEnergyCP oEnergyFC oEnergyCM oEnergyCA
|
||||
var scope = "offline_access oEnergyPF oEnergyBD oEnergyDD oEnergyEA oEnergyED oEnergyEM oEnergyFC oEnergyFM oEnergyKR oEnergyLG" +
|
||||
" oEnergyMR oEnergyNW oEnergyPM oEnergyQC oEnergyUT oEnergyMT oEnergySO oEnergyCP oEnergyCM oEnergyCA oEnergyHM oEnergyPP oEnergyFO oEnergyBS oEnergySC";
|
||||
//var scope = GetAllScopes(user.ORG_ID ?? Guid.Empty);
|
||||
var dic = new Dictionary<string, string>();
|
||||
dic.Add("UserId", user.ID.ToString());
|
||||
var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
|
||||
{
|
||||
//Address = disco.TokenEndpoint,
|
||||
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
||||
ClientId = ConfigurationManager.AppSettings["ClientId"],
|
||||
ClientSecret = ConfigurationManager.AppSettings["SecurityKey"],
|
||||
@ -119,32 +85,6 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
return BadRequest(new { error = tokenResponse.Error, error_description = tokenResponse.Error ?? tokenResponse.ErrorDescription });
|
||||
}
|
||||
int second = 60;
|
||||
/*
|
||||
#region 是否发送手机验证码
|
||||
|
||||
var orgId = new Guid(request.orgId);
|
||||
BaseFilter baseFilter = new BaseFilter(orgId);
|
||||
var commonService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<ICommonService>();
|
||||
var baseConfig = commonService.GetEntity<T_FM_BASE_CONFIG>(null, baseFilter, "Nav_MessageTemplate");
|
||||
var belongRoles = commonService.GetEntities<T_FM_USER_BELONG_ROLE>(x => x.USER_ID == user.ID, baseFilter, "Nav_BelongRole");
|
||||
var isCheckPhoneCode = false;
|
||||
|
||||
if (baseConfig != null && baseConfig.IS_CHECK_MESSAGE)//新增用户站点参数为null
|
||||
{
|
||||
foreach (var belongRole in belongRoles)
|
||||
{
|
||||
if (belongRole.Nav_BelongRole.IS_CHECK_MESSAGE)
|
||||
{
|
||||
isCheckPhoneCode = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(user.PHONE))
|
||||
{
|
||||
return BadRequest(new { error = "error phoneNull ", error_description = "已开启手机短信验证,请先维护手机号码!" });
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
*/
|
||||
return Ok(new
|
||||
{
|
||||
access_token = tokenResponse.AccessToken,
|
||||
@ -163,17 +103,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
else if (request.Grant_type == (int)PFGrantTypeEnum.客户端)
|
||||
{
|
||||
var client = new System.Net.Http.HttpClient();
|
||||
//var disco = await client.GetDiscoveryDocumentAsync(ConfigurationManager.AppSettings["IdentityServer"]);
|
||||
//if (disco.IsError)
|
||||
//{
|
||||
// Console.WriteLine(disco.Error);
|
||||
// return BadRequest(new { error = "identity server Error", error_description = "验证服务器无法连接" });
|
||||
//}
|
||||
// request access token
|
||||
//获取clentid的scops
|
||||
var scope = "oEnergyBD oEnergyLG oEnergyFM oEnergyPF oEnergyOP oEnergyPP";
|
||||
//var dataChanel = GetDataChanel(request);
|
||||
//var scope = GetScopes(request);
|
||||
var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
||||
{
|
||||
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
||||
@ -192,7 +122,6 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
token_type = tokenResponse.TokenType,
|
||||
refreshToken = tokenResponse.RefreshToken,
|
||||
expiresIn = tokenResponse.ExpiresIn,
|
||||
//dataChanel = dataChanel,
|
||||
});
|
||||
}
|
||||
if (request.Grant_type == (int)PFGrantTypeEnum.Refresh)
|
||||
@ -201,7 +130,6 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
|
||||
var tokenResponse = await client.RequestRefreshTokenAsync(new RefreshTokenRequest
|
||||
{
|
||||
//Address = disco.TokenEndpoint,
|
||||
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
||||
ClientId = ConfigurationManager.AppSettings["ClientId"],
|
||||
ClientSecret = ConfigurationManager.AppSettings["SecurityKey"],
|
||||
@ -226,10 +154,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(new { error = "excetion", error_description = ex.Message });
|
||||
//return BadRequest(new { error = "excetion", error_description = ex.Message + ex.Source + "," + ex.StackTrace + "," + ex.TargetSite });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
[HttpPost, Route("AppGen")]
|
||||
public async Task<IActionResult> AppGen([FromBody] TokenRequest request)
|
||||
@ -318,10 +243,9 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
filter.IgnoreOrgRule = true;
|
||||
}
|
||||
//}
|
||||
var pwdLower = request.Password.ToLower();
|
||||
var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD).ToUpper();
|
||||
var pwdUpper = request.Password.ToUpper();
|
||||
var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD);
|
||||
if (pwdLower == md5SuperPwd || pwdUpper == md5SuperPwd)
|
||||
if (md5SuperPwd == pwdUpper)
|
||||
{
|
||||
loginUser = commonService.GetEntity<T_FM_USER>(i => (i.CODE == request.UserName
|
||||
|| i.PHONE == request.UserName), filter);
|
||||
@ -334,7 +258,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
||||
|| i.PHONE == request.UserName), filter);
|
||||
if (loginUser == null)
|
||||
throw new Exception("用户信息不存在");
|
||||
if (loginUser.PASSWORD != pwdLower && loginUser.PASSWORD != pwdUpper)
|
||||
if (loginUser.PASSWORD.ToUpper() != pwdUpper)
|
||||
{
|
||||
throw new Exception("用户名或密码错误");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user