|
|
|
@ -3,11 +3,14 @@ using Application.Models;
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Email;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Infrastructure.Jwt;
|
|
|
|
|
using Infrastructure.Resources;
|
|
|
|
|
using Infrastructure.Security;
|
|
|
|
|
using Infrastructure.Sms;
|
|
|
|
|
using Infrastructure.Web;
|
|
|
|
|
using Infrastructure.Web.DataAnnotations;
|
|
|
|
|
using JWT.Algorithms;
|
|
|
|
|
using JWT.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
@ -29,6 +32,7 @@ namespace UserCenter.Controllers
|
|
|
|
|
public class AccountController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfiguration _cfg;
|
|
|
|
|
private readonly IJwtHelper _jwtHelper;
|
|
|
|
|
private readonly IRepository<User> _userRepo;
|
|
|
|
|
private readonly IRepository<Site> _siteRepo;
|
|
|
|
|
private readonly IStringLocalizer<Resource> _localizer;
|
|
|
|
@ -37,6 +41,7 @@ namespace UserCenter.Controllers
|
|
|
|
|
private readonly ISmsSender _smsSender;
|
|
|
|
|
|
|
|
|
|
public AccountController(IConfiguration cfg,
|
|
|
|
|
IJwtHelper jwtHelper,
|
|
|
|
|
IRepository<User> userRepo,
|
|
|
|
|
IRepository<Site> siteRepo,
|
|
|
|
|
IEncryptionService encryptionService,
|
|
|
|
@ -45,6 +50,7 @@ namespace UserCenter.Controllers
|
|
|
|
|
ISmsSender smsSender)
|
|
|
|
|
{
|
|
|
|
|
this._cfg = cfg;
|
|
|
|
|
this._jwtHelper = jwtHelper;
|
|
|
|
|
this._userRepo = userRepo;
|
|
|
|
|
this._siteRepo = siteRepo;
|
|
|
|
|
this._encryptionService = encryptionService;
|
|
|
|
@ -176,7 +182,19 @@ namespace UserCenter.Controllers
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
var list = this._siteRepo.ReadOnlyTable().ToList();
|
|
|
|
|
if (!isAppLogin)
|
|
|
|
|
if (isAppLogin)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
Code = 0,
|
|
|
|
|
Token = this._jwtHelper.GetToken(new Dictionary<string, object>() { { nameof(user.UserName), user.UserName } }),
|
|
|
|
|
user.NickName,
|
|
|
|
|
Title = this._cfg["name"],
|
|
|
|
|
IoTServer = list.FirstOrDefault(o => o.Name == "物联网平台").Home
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var userPermissions = this._userRepo.ReadOnlyTable().Where(o => o.UserName == userName)
|
|
|
|
|
.SelectMany(o => o.UserRoles)
|
|
|
|
@ -206,10 +224,6 @@ namespace UserCenter.Controllers
|
|
|
|
|
Response.Headers.Remove("Location");
|
|
|
|
|
return View("JsonpLogin", urls);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Json(new { Code = 0, NickName = user.NickName, IoTServer = list.FirstOrDefault(o => o.Name == "物联网平台").Home });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -232,15 +246,15 @@ namespace UserCenter.Controllers
|
|
|
|
|
message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isAppLogin)
|
|
|
|
|
if (isAppLogin)
|
|
|
|
|
{
|
|
|
|
|
ModelState.AddModelError(key, message);
|
|
|
|
|
ViewData["ReturnUrl"] = returnUrl;
|
|
|
|
|
return View(model);
|
|
|
|
|
return Json(new { Code = 1, Key = key, Message = message });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Json(new { Code = 1, Key = key, Message = message });
|
|
|
|
|
ModelState.AddModelError(key, message);
|
|
|
|
|
ViewData["ReturnUrl"] = returnUrl;
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|