11
This commit is contained in:
@@ -14,9 +14,15 @@ namespace Application.Web.Controllers.Login
|
||||
public class LoginController : ControllerBase
|
||||
{
|
||||
private readonly IGameAccountService _accountService;
|
||||
public LoginController(IGameAccountService accountService)
|
||||
private readonly IAreaService _areaService;
|
||||
private readonly IUnitUserService _userService;
|
||||
|
||||
public LoginController(IGameAccountService accountService, IAreaService areaService,
|
||||
IUnitUserService userService)
|
||||
{
|
||||
_accountService = accountService;
|
||||
_areaService = areaService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -27,8 +33,6 @@ namespace Application.Web.Controllers.Login
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> Login([FromBody] LoginParms parms)
|
||||
{
|
||||
|
||||
|
||||
return PoAction.Ok(parms.code);
|
||||
}
|
||||
|
||||
@@ -38,14 +42,15 @@ namespace Application.Web.Controllers.Login
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> TwLogin( string code)
|
||||
public async Task<IPoAction> TwLogin(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
return PoAction.Message("code值错误!");
|
||||
}
|
||||
|
||||
AutoLogin login = new AutoLogin();
|
||||
var loginInfo = await login.TwLogin(code);
|
||||
var loginInfo = await login.TwLogin(code);
|
||||
if (loginInfo.code == 0)
|
||||
{
|
||||
dynamic twInfo = JsonConvert.DeserializeObject<dynamic>(loginInfo.data.ToString());
|
||||
@@ -54,14 +59,14 @@ namespace Application.Web.Controllers.Login
|
||||
var accInfo = await _accountService.GetAccInfoByOpenId(openId);
|
||||
if (accInfo == null)
|
||||
{
|
||||
var userData = await _accountService.Regist("", nick, "", "", openId);
|
||||
var userData = await _accountService.Regist("", nick, "", "", openId);
|
||||
if (userData == null)
|
||||
{
|
||||
return PoAction.Message("登录失败,请联系客服!");
|
||||
}
|
||||
else
|
||||
{
|
||||
object ret =new { token = userData.token };
|
||||
object ret = new { token = userData.token };
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
}
|
||||
@@ -73,7 +78,7 @@ namespace Application.Web.Controllers.Login
|
||||
}
|
||||
else
|
||||
{
|
||||
object ret =new { token = accInfo.token };
|
||||
object ret = new { token = accInfo.token };
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
}
|
||||
@@ -112,5 +117,60 @@ namespace Application.Web.Controllers.Login
|
||||
return PoAction.Message("退出失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册基础账号信息
|
||||
/// </summary>
|
||||
/// <param name="sid"></param>
|
||||
/// <param name="area"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> Register(string sid, int area)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sid))
|
||||
{
|
||||
return PoAction.Message("未登录账号!");
|
||||
}
|
||||
|
||||
var accInfo = await _accountService.GetAccInfoByToken(sid);
|
||||
if (accInfo == null)
|
||||
{
|
||||
return PoAction.Message("未登录账号!");
|
||||
}
|
||||
|
||||
var areaInfo = await _areaService.GetAreaInfo(area);
|
||||
if (areaInfo == null)
|
||||
{
|
||||
return PoAction.Message("区服不存在!");
|
||||
}
|
||||
|
||||
if (areaInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("当前区繁忙,无法进入!");
|
||||
}
|
||||
|
||||
//判断是否已经注册
|
||||
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
|
||||
if (userData.Any(it => it.areaId == area))
|
||||
{
|
||||
return PoAction.Message("该区已存在角色!");
|
||||
}
|
||||
|
||||
var userInfo = await _userService.Register(areaInfo.areaId, accInfo.accId);
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("注册失败,请稍后尝试!");
|
||||
}
|
||||
|
||||
Dictionary<string, object> loadData = new Dictionary<string, object>();
|
||||
loadData.Add("userId", userInfo.userId);
|
||||
loadData.Add("accId", userInfo.accId);
|
||||
|
||||
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
|
||||
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
|
||||
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
|
||||
string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, 300);
|
||||
return PoAction.Ok(new { token = token, refToken = userInfo.token, userId = userInfo.userId });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user