public async Task <IActionResult> GetVaultKeys() { if (!CurrentUserIsAdmin) { var authRecord = MakeFailedAuthRecord("User is not admin"); context.Add(authRecord); await context.SaveChangesAsync(); return(Unauthorized()); } var users = await( from user in CurrentSets.ActiveUser join player in CurrentSets.Player on user.PlayerId equals player.PlayerId join tribe in CurrentSets.Ally on player.TribeId equals tribe.TribeId into maybeTribe from tribe in maybeTribe.DefaultIfEmpty() where CurrentUser.KeySource == null || user.KeySource == CurrentUserId || !Configuration.Security.RestrictAccessWithinTribes where (user.PermissionsLevel < (short)Security.PermissionLevel.System) || CurrentUserIsSystem orderby tribe.Tag, player.PlayerName select new { user, playerName = player.PlayerName, tribe = tribe } ).ToListAsync(); if (Configuration.Security.RestrictAccessWithinTribes && !CurrentUserIsSystem) { users = users.Where(u => u.tribe?.TribeId == CurrentTribeId || u.user.AdminAuthToken == CurrentAuthToken).ToList(); } var jsonUsers = users.Select(p => UserConvert.ModelToJson( p.user, p.playerName.UrlDecode(), p.tribe != null ? p.tribe.TribeName.UrlDecode() : null )); return(Ok(jsonUsers)); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (this.IsValid) { IUserService service = ServiceFactory.GetService <IUserService>(); UserInfo entity = null; if (this.IsInsert) { entity = new UserInfo() { UserAccount = this.txtUserAccount.Text.Trim(), UserPwd = this.txtUserPwd.Text.DESEncrypt(), UserNickName = this.txtUserNickName.Text.Trim(), UserEmail = this.txtUserEmail.Text.Trim(), UserPhone = this.txtUserPhone.Text.Trim(), UserStatus = this.ddlUserStatus.SelectedValue.ToByte(0), RoleId = this.ddlUserRole.SelectedValue.ToByte(0), OrgId = this.hfOrgId.Value.ToInt(0) }; if (service.CheckExists_Info(entity)) { this.JscriptMsg("用户帐户已存在", null, "Error"); return; } } else { entity = service.GetObject_Info(this.PkId); if (entity != null) { entity.UserPwd = this.txtUserPwd.Text.DESEncrypt(); entity.UserNickName = this.txtUserNickName.Text.Trim(); entity.UserEmail = this.txtUserEmail.Text.Trim(); entity.UserPhone = this.txtUserPhone.Text.Trim(); entity.UserStatus = this.ddlUserStatus.SelectedValue.ToByte(0); entity.RoleId = this.ddlUserRole.SelectedValue.ToByte(0); entity.OrgId = this.hfOrgId.Value.ToInt(0); } } service.Save_Info(entity); if (this.IsInsert && (sender as Button).CommandName == "SubmitContinue") { this.ReturnUrl = this.Request.Url.AbsolutePath; } this.JscriptMsg("数据保存成功", this.ReturnUrl, "Success"); } UserConvert.ClearCache(); }
protected void btnDelete_Click(object sender, EventArgs e) { IUserService service = ServiceFactory.GetService <IUserService>(); foreach (GridViewRow objGVR in this.gvList.Rows) { if (objGVR.RowType == DataControlRowType.DataRow) { CheckBox cbSelect = objGVR.FindControl("cbSelect") as CheckBox; if (cbSelect != null && cbSelect.Checked) { int pkId = this.gvList.DataKeys[objGVR.RowIndex]["PkId"].ToString().ToInt(); service.Delete_Info(pkId); } } } this.JscriptMsg("数据删除成功", null, "Success"); UserConvert.ClearCache(); }
public async Task <IActionResult> MakeVaultKey([FromBody] JSON.VaultKeyRequest keyRequest) { if (!CurrentUserIsAdmin) { var authRecord = MakeFailedAuthRecord("User is not admin"); context.Add(authRecord); await context.SaveChangesAsync(); return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Scaffold.Player player; if (keyRequest.PlayerId.HasValue) { long playerId = keyRequest.PlayerId.Value; var possiblePlayer = await( from p in CurrentSets.Player where p.PlayerId == playerId select p ).FirstOrDefaultAsync(); if (possiblePlayer == null) { return(BadRequest(new { error = Translate("ADMIN_PLAYER_NOT_FOUND_ID") })); } player = possiblePlayer; } else if (keyRequest.PlayerName != null) { var formattedPlayerName = keyRequest.PlayerName.UrlEncode(); var possiblePlayer = await( from p in CurrentSets.Player where p.PlayerName == formattedPlayerName select p ).FirstOrDefaultAsync(); if (possiblePlayer == null) { return(BadRequest(new { error = Translate("ADMIN_PLAYER_NOT_FOUND_NAME") })); } player = possiblePlayer; } else { return(BadRequest(new { error = Translate("ADMIN_PLAYER_NAME_NOT_SET") })); } if (!CurrentUserIsSystem && player.TribeId != CurrentTribeId && Configuration.Security.RestrictAccessWithinTribes) { return(BadRequest(new { error = Translate("ADMIN_PLAYER_NOT_IN_TRIBE") })); } bool userExists = await( from user in CurrentSets.User where user.PlayerId == player.PlayerId where user.WorldId == null || user.WorldId == CurrentWorldId where user.Enabled select user ).AnyAsync(); if (userExists) { return(BadRequest(new { error = Translate("ADMIN_PLAYER_HAS_KEY") })); } var newAuthUser = new Scaffold.User(); newAuthUser.WorldId = CurrentWorldId; newAuthUser.PlayerId = player.PlayerId; newAuthUser.AccessGroupId = CurrentAccessGroupId; newAuthUser.AuthToken = Guid.NewGuid(); newAuthUser.Enabled = true; newAuthUser.TransactionTime = DateTime.UtcNow; newAuthUser.AdminAuthToken = CurrentAuthToken; newAuthUser.AdminPlayerId = CurrentPlayerId; newAuthUser.KeySource = CurrentUserId; newAuthUser.Label = player.PlayerName; newAuthUser.Tx = BuildTransaction(); if (keyRequest.NewUserIsAdmin) { newAuthUser.PermissionsLevel = (short)Security.PermissionLevel.Admin; } else { newAuthUser.PermissionsLevel = (short)Security.PermissionLevel.Default; } context.User.Add(newAuthUser); await context.SaveChangesAsync(); var jsonUser = UserConvert.ModelToJson(newAuthUser); jsonUser.PlayerName = player.PlayerName.UrlDecode(); var playerTribe = await( from tribe in CurrentSets.Ally where tribe.TribeId == player.TribeId select tribe ).FirstOrDefaultAsync(); jsonUser.TribeName = playerTribe?.TribeName?.UrlDecode(); return(Ok(jsonUser)); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (this.IsValid) { IUserService service = ServiceFactory.GetService <IUserService>(); UserRole entity = null; List <UserRolePermission> rolePermissionList = new List <UserRolePermission>(); if (this.IsInsert) { entity = new UserRole() { RoleName = this.txtRoleName.Text.Trim(), DataFilter = this.ddlDataFilter.SelectedValue.ToByte(0), RoleStatus = this.ddlRoleStatus.SelectedValue.ToByte(0) }; if (service.CheckExists_Role(entity)) { this.JscriptMsg("角色名称已存在", null, "Error"); return; } } else { entity = service.GetObject_Role(this.PkId); if (entity != null) { entity.DataFilter = this.ddlDataFilter.SelectedValue.ToByte(0); entity.RoleStatus = this.ddlRoleStatus.SelectedValue.ToByte(0); } } service.Save_Role(entity); foreach (TreeNode tnOne in this.tvPermission.Nodes) { if (tnOne.Checked) { rolePermissionList.Add(new UserRolePermission() { RoleId = entity.PkId, PermCode = tnOne.Value }); } foreach (TreeNode tnTwo in tnOne.ChildNodes) { if (tnTwo.Checked) { rolePermissionList.Add(new UserRolePermission() { RoleId = entity.PkId, PermCode = tnTwo.Value }); } } } service.Delete_RolePermission(entity.PkId); service.Save_RolePermission(rolePermissionList); if (this.IsInsert && (sender as Button).CommandName == "SubmitContinue") { this.ReturnUrl = this.Request.Url.AbsolutePath; } this.JscriptMsg("数据保存成功", this.ReturnUrl, "Success"); } UserConvert.ClearCache(); }