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.账号密码)
|
if (request.Grant_type == (int)PFGrantTypeEnum.账号密码)
|
||||||
{
|
{
|
||||||
var client = new System.Net.Http.HttpClient();
|
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();
|
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 (request.ClientId != "app")
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(request.random))
|
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 = "验证码不正确" });
|
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);
|
var user = this.GetUser(request, filter);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return BadRequest(new { error = "error Account ", error_description = "用户不存在或者密码错误" }); ;
|
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" +
|
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";
|
" 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>();
|
var dic = new Dictionary<string, string>();
|
||||||
dic.Add("UserId", user.ID.ToString());
|
dic.Add("UserId", user.ID.ToString());
|
||||||
var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
|
var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
|
||||||
{
|
{
|
||||||
//Address = disco.TokenEndpoint,
|
|
||||||
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
||||||
ClientId = ConfigurationManager.AppSettings["ClientId"],
|
ClientId = ConfigurationManager.AppSettings["ClientId"],
|
||||||
ClientSecret = ConfigurationManager.AppSettings["SecurityKey"],
|
ClientSecret = ConfigurationManager.AppSettings["SecurityKey"],
|
||||||
@ -119,39 +85,13 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
|||||||
return BadRequest(new { error = tokenResponse.Error, error_description = tokenResponse.Error ?? tokenResponse.ErrorDescription });
|
return BadRequest(new { error = tokenResponse.Error, error_description = tokenResponse.Error ?? tokenResponse.ErrorDescription });
|
||||||
}
|
}
|
||||||
int second = 60;
|
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
|
return Ok(new
|
||||||
{
|
{
|
||||||
access_token = tokenResponse.AccessToken,
|
access_token = tokenResponse.AccessToken,
|
||||||
token_type = tokenResponse.TokenType,
|
token_type = tokenResponse.TokenType,
|
||||||
expiresIn = tokenResponse.ExpiresIn,
|
expiresIn = tokenResponse.ExpiresIn,
|
||||||
userid = user.ID,
|
userid = user.ID,
|
||||||
userName=user.CODE,
|
userName = user.CODE,
|
||||||
orgId = user.ORG_ID,
|
orgId = user.ORG_ID,
|
||||||
refreshToken = tokenResponse.RefreshToken,
|
refreshToken = tokenResponse.RefreshToken,
|
||||||
isCheckPhoneCode = false,
|
isCheckPhoneCode = false,
|
||||||
@ -163,17 +103,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
|||||||
else if (request.Grant_type == (int)PFGrantTypeEnum.客户端)
|
else if (request.Grant_type == (int)PFGrantTypeEnum.客户端)
|
||||||
{
|
{
|
||||||
var client = new System.Net.Http.HttpClient();
|
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 scope = "oEnergyBD oEnergyLG oEnergyFM oEnergyPF oEnergyOP oEnergyPP";
|
||||||
//var dataChanel = GetDataChanel(request);
|
|
||||||
//var scope = GetScopes(request);
|
|
||||||
var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
||||||
{
|
{
|
||||||
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
||||||
@ -192,7 +122,6 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
|||||||
token_type = tokenResponse.TokenType,
|
token_type = tokenResponse.TokenType,
|
||||||
refreshToken = tokenResponse.RefreshToken,
|
refreshToken = tokenResponse.RefreshToken,
|
||||||
expiresIn = tokenResponse.ExpiresIn,
|
expiresIn = tokenResponse.ExpiresIn,
|
||||||
//dataChanel = dataChanel,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (request.Grant_type == (int)PFGrantTypeEnum.Refresh)
|
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
|
var tokenResponse = await client.RequestRefreshTokenAsync(new RefreshTokenRequest
|
||||||
{
|
{
|
||||||
//Address = disco.TokenEndpoint,
|
|
||||||
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
Address = ConfigurationManager.AppSettings["IdentityServer"] + "connect/token",
|
||||||
ClientId = ConfigurationManager.AppSettings["ClientId"],
|
ClientId = ConfigurationManager.AppSettings["ClientId"],
|
||||||
ClientSecret = ConfigurationManager.AppSettings["SecurityKey"],
|
ClientSecret = ConfigurationManager.AppSettings["SecurityKey"],
|
||||||
@ -226,10 +154,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { error = "excetion", error_description = ex.Message });
|
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")]
|
[HttpPost, Route("AppGen")]
|
||||||
public async Task<IActionResult> AppGen([FromBody] TokenRequest request)
|
public async Task<IActionResult> AppGen([FromBody] TokenRequest request)
|
||||||
@ -318,10 +243,9 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
|||||||
filter.IgnoreOrgRule = true;
|
filter.IgnoreOrgRule = true;
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
var pwdLower = request.Password.ToLower();
|
var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD).ToUpper();
|
||||||
var pwdUpper = request.Password.ToUpper();
|
var pwdUpper = request.Password.ToUpper();
|
||||||
var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD);
|
if (md5SuperPwd == pwdUpper)
|
||||||
if (pwdLower == md5SuperPwd || pwdUpper == md5SuperPwd)
|
|
||||||
{
|
{
|
||||||
loginUser = commonService.GetEntity<T_FM_USER>(i => (i.CODE == request.UserName
|
loginUser = commonService.GetEntity<T_FM_USER>(i => (i.CODE == request.UserName
|
||||||
|| i.PHONE == request.UserName), filter);
|
|| i.PHONE == request.UserName), filter);
|
||||||
@ -334,7 +258,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
|
|||||||
|| i.PHONE == request.UserName), filter);
|
|| i.PHONE == request.UserName), filter);
|
||||||
if (loginUser == null)
|
if (loginUser == null)
|
||||||
throw new Exception("用户信息不存在");
|
throw new Exception("用户信息不存在");
|
||||||
if (loginUser.PASSWORD != pwdLower && loginUser.PASSWORD != pwdUpper)
|
if (loginUser.PASSWORD.ToUpper() != pwdUpper)
|
||||||
{
|
{
|
||||||
throw new Exception("用户名或密码错误");
|
throw new Exception("用户名或密码错误");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user