public IActionResult LoadMenu() { SmartHttpResult result = new SmartHttpResult(); try { var entityList = DAL.SystemManage.SmartMenu.getMenuByUserName(HttpContext.User.Identity.Name); List <Models.JsonTreeNode> menuList = new List <Models.JsonTreeNode>(); foreach (var entity in entityList) { if (entity.ParentIdx == null) { Models.JsonTreeNode node = new Models.JsonTreeNode(); //node.Idx = entity.Idx; node.text = entity.ModuleName; node.link = entity.Link; node.icon = entity.Icon; Common.Helper.SmartMenuTreeHelper.LoadTree(entityList.ToList(), node, entity.Idx); menuList.Add(node); } } result.Set(true, menuList); } catch (Exception err) { result.Set(false, err.Message); } return(JsonEx(result)); }
public IActionResult Authenticate([FromBody] OAuthModel login) { SmartHttpResult result = new SmartHttpResult(); try { var entity = DAL.SmartUser.GetEntityByName(login.UserName); if (entity != null) { var encrypted = EncryptProvider.AESEncrypt(login.PassWord, entity.Salt); if (entity.PassWord == encrypted) { //重新加密 var Saltkey = Guid.NewGuid().ToString("N"); var decrypted = EncryptProvider.AESEncrypt(login.PassWord, Saltkey); //替换密码与密钥 DAL.SmartUser.utlSmartUserByName(login.UserName, decrypted, Saltkey); var claims = new Claim[] { new Claim(ClaimTypes.Name, login.UserName), new Claim(ClaimTypes.Role, entity.Role) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(setting.SecretKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var tokenModel = new JwtSecurityToken( setting.Issuer, setting.Audience, claims, DateTime.Now, DateTime.Now.AddMinutes(setting.TokenExpires), creds); var jwtToken = new JwtTokenModel(); jwtToken.Token = new JwtSecurityTokenHandler().WriteToken(tokenModel); var tokenUser = new TokenUserModel(); tokenUser.UserName = entity.UserName; tokenUser.Email = entity.Email; tokenUser.Phone = entity.Phone; tokenUser.Avatar = entity.Avatar; jwtToken.User = tokenUser; result.Set(true, jwtToken); return(new JsonResult(result)); } else { result.Set(false, "用户密码不正确!"); } } else { result.Set(false, "用户不存在!"); } } catch (Exception err) { result.Set(false, err.Message); } return(new JsonResult(result)); }
public IActionResult Logout() { SmartHttpResult result = new SmartHttpResult(); HttpContext.SignOutAsync(Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerDefaults.AuthenticationScheme); result.Set(false, "用户已注销!"); return(new JsonResult(result)); }
public IActionResult Get() { SmartHttpResult <List <Models.SystemManage.SmartPagesModel> > result = new SmartHttpResult <List <Models.SystemManage.SmartPagesModel> >(); result.status = true; result.data = DAL.SystemManage.SmartPages.GetPages(); return(JsonEx(result)); }