|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
using Infrastructure.Application.Services.Settings;
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Email;
|
|
|
|
@ -6,7 +7,6 @@ using Infrastructure.Security;
|
|
|
|
|
using Infrastructure.Sms;
|
|
|
|
|
using Infrastructure.Web;
|
|
|
|
|
using Infrastructure.Web.DataAnnotations;
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
using IoT.Shared.Application.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
@ -17,8 +17,8 @@ using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
@ -27,7 +27,6 @@ using System.Security.Claims;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
|
|
|
|
|
namespace Platform.Controllers
|
|
|
|
|
{
|
|
|
|
@ -201,10 +200,10 @@ namespace Platform.Controllers
|
|
|
|
|
//new Claim("RealName", user.RealName),
|
|
|
|
|
//new Claim("Avatar", user.Avatar)
|
|
|
|
|
};
|
|
|
|
|
var mainOrgan = user.OrganUsers.FirstOrDefault(o => o.IsDefault)?.Organ ?? user.OrganUsers.OrderBy(o => o.Organ.Name).FirstOrDefault()?.Organ;
|
|
|
|
|
if(mainOrgan!=null)
|
|
|
|
|
var userMainOrgan = user.OrganUsers.OrderByDescending(o=>o.IsDefault).ThenBy(o => o.OrganId).FirstOrDefault();
|
|
|
|
|
if (userMainOrgan != null)
|
|
|
|
|
{
|
|
|
|
|
claims.Add(new Claim(ClaimTypes.UserData, mainOrgan.Id.ToString()));
|
|
|
|
|
claims.Add(new Claim("OrganId", userMainOrgan.OrganId.ToString()));
|
|
|
|
|
}
|
|
|
|
|
if (this.IsJsonRequest())
|
|
|
|
|
{
|
|
|
|
@ -945,13 +944,52 @@ namespace Platform.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult ChangeOrgan(string userCurrentOrganNumber, string returnUrl)
|
|
|
|
|
{
|
|
|
|
|
var claims = new List<Claim> {
|
|
|
|
|
new Claim(this._parameters.NameClaimType, User.Identity.Name),
|
|
|
|
|
new Claim(ClaimTypes.UserData,userCurrentOrganNumber)
|
|
|
|
|
};
|
|
|
|
|
this.HttpContext.JwtSignOut();
|
|
|
|
|
this.HttpContext.JwtSignIn(claims, false);
|
|
|
|
|
return Redirect(returnUrl);
|
|
|
|
|
var message = string.Empty;
|
|
|
|
|
if (Guid.TryParse(userCurrentOrganNumber, out var organId))
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.Name;
|
|
|
|
|
var user = this._userRepo.ReadOnlyTable().Where(o => o.UserName == userName).Include(o => o.OrganUsers).FirstOrDefault();
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
if (user.OrganUsers.Any(o => o.OrganId == organId))
|
|
|
|
|
{
|
|
|
|
|
var claims = new List<Claim> {
|
|
|
|
|
new Claim(this._parameters.NameClaimType, User.Identity.Name),
|
|
|
|
|
new Claim("OrganId",userCurrentOrganNumber)
|
|
|
|
|
};
|
|
|
|
|
if (Request.IsJsonRequest())
|
|
|
|
|
{
|
|
|
|
|
return Json(this.CreateToken(claims));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.HttpContext.JwtSignOut();
|
|
|
|
|
this.HttpContext.JwtSignIn(claims, false);
|
|
|
|
|
return Redirect(returnUrl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
message = "当前用户不是该机构成员";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
message = "用户不存在";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
message = "机构Id格式错误";
|
|
|
|
|
}
|
|
|
|
|
if (this.Request.IsJsonRequest())
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return RedirectTo(returnUrl: returnUrl, rawMesage: message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region tools
|
|
|
|
@ -1002,4 +1040,4 @@ namespace Platform.Controllers
|
|
|
|
|
|
|
|
|
|
#endregion tools
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|