提交 5be81dba 编写于 作者: 麦壳饼's avatar 麦壳饼

modify for vue admin

上级 5c75b9b0
......@@ -331,3 +331,4 @@ ASALocalRun/
/healthchecksdb
/.vscode
/Clients/MQTTClient/.vscode
/IoTSharp/ClientApp.rar
[submodule "IoTSharp/ClientApp"]
path = IoTSharp/ClientApp
url = https://github.com/IoTSharp/IoTSharp.ClientApp.git
......@@ -44,14 +44,21 @@ namespace IoTSharp.Controllers
_logger = logger;
_context = context;
}
[HttpGet]
public ActionResult<ApiResult<UserInfoDto>> MyInfo()
public async Task<ActionResult<ApiResult<UserInfoDto>>> MyInfo()
{
string custid = _signInManager.Context.User.FindFirstValue(IoTSharpClaimTypes.Customer);
var user = await _userManager.GetUserAsync(_signInManager.Context.User);
var Customer = _context.Customer.FirstOrDefault(c => c.Id.ToString() == custid);
var rooles= await _userManager.GetRolesAsync(user );
var uidto = new UserInfoDto()
{
Code = ApiCode.OK,
Roles = string.Join(',',rooles).ToLower().Contains("admin")?"admin":"editor",//TODO: Permission control
Name = user.UserName,
Avatar = user.Gravatar(),
Introduction = user.NormalizedUserName,
Customer = Customer,
Tenant = Customer.Tenant
};
......@@ -72,6 +79,7 @@ namespace IoTSharp.Controllers
var roles = await _userManager.GetRolesAsync(appUser);
return Ok(new LoginResult()
{
Code = ApiCode.OK,
Succeeded = result.Succeeded,
Token = token,
UserName = appUser.UserName,
......
......@@ -17,6 +17,8 @@ namespace IoTSharp.Data
public enum ApiCode : int
{
OK=2000,
NotFound=404,
Success = 10000,
LoginError = 10001,
Exception = 10002,
......
using System;
using IoTSharp.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
......@@ -14,6 +15,7 @@ namespace IoTSharp.Dtos
public class LoginResult
{
public ApiCode Code { get; set; }
public string UserName { get; set; }
public Microsoft.AspNetCore.Identity.SignInResult SignIn { get; set; }
public bool Succeeded { get; set; }
......
......@@ -8,6 +8,11 @@ namespace IoTSharp.Dtos
{
public class UserInfoDto
{
public ApiCode Code { get; set; }
public string Roles {get; set;}
public string Name { get; set; }
public string Avatar { get; set; }
public string Introduction { get; set; }
public Customer Customer { get; set; }
public Tenant Tenant { get; set; }
}
......
......@@ -12,6 +12,7 @@ using System.Diagnostics;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
......@@ -155,5 +156,30 @@ namespace IoTSharp
{
return jwtSecurityToken.Payload[Key] as string;
}
/// Hashes an email with MD5. Suitable for use with Gravatar profile
/// image urls
public static string Gravatar( this IdentityUser user)
{
string email = user.Email;
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(email));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return string.Format("http://www.gravatar.com/avatar/{0}", sBuilder.ToString()); ; // Return the hexadecimal string.
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册