protected void btnApplyAutoBan_Click(object sender, EventArgs e) { if (Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.Moderator.ToString()) == true || Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.Administrator.ToString()) == true || Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.ZoneLeader.ToString()) == true || Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.SuperAdministrator.ToString()) == true) { Allegiance.CommunitySecuritySystem.Server.Administration administration = new Allegiance.CommunitySecuritySystem.Server.Administration(); using (var db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, Page.User.Identity.Name); if (login != null) { administration.SetBan(new BanData() { Alias = txtCallsign.Value, BanTypeId = Convert.ToInt32(Request.Form[ddlAutoBanReason.UniqueID]), // For some reason, the post back doesn't get this value back into the control. BanMode = Allegiance.CommunitySecuritySystem.Common.Enumerations.BanMode.Auto, Password = login.Password, Username = login.Username }); } } } BindData(); }
protected void gvGroups_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Data.EditableGroupRole groupRole = (Data.EditableGroupRole)e.Row.DataItem; DropDownList ddlRoles = (DropDownList)e.Row.FindControl("ddlRoles"); HiddenField txtGroupID = (HiddenField)e.Row.FindControl("txtGroupID"); HiddenField txtAliasID = (HiddenField)e.Row.FindControl("txtAliasID"); List <Data.EditableRole> allRoles = new List <ACSSAuth.Management.Users.Data.EditableRole>(); using (var db = new DataAccess.CSSDataContext()) { foreach (var currentGroupRole in db.GroupRoles) { allRoles.Add(new ACSSAuth.Management.Users.Data.EditableRole() { Id = currentGroupRole.Id, Name = currentGroupRole.Name }); } } ddlRoles.DataSource = allRoles; ddlRoles.DataTextField = "Name"; ddlRoles.DataValueField = "Id"; ddlRoles.DataBind(); ddlRoles.SelectedValue = groupRole.SelectedRoleID.ToString(); txtGroupID.Value = groupRole.GroupID.ToString(); txtAliasID.Value = groupRole.AliasID.ToString(); } }
protected void btnSave_Click(object sender, EventArgs e) { int lobbyID = Int32.Parse(ddlLobby.SelectedValue); using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var motdSettings = db.Motds.FirstOrDefault(p => p.LobbyId == lobbyID); if (motdSettings == null) { motdSettings = new DataAccess.Motd(); db.Motds.InsertOnSubmit(motdSettings); motdSettings.LobbyId = lobbyID; } motdSettings.Banner = txtBanner.Text; motdSettings.Details = txtDetails.Text; motdSettings.LastUpdated = DateTime.Now; motdSettings.Logo = ddlLogo.SelectedValue; motdSettings.PaddingCrCount = Int32.Parse(txtPaddingCrCount.Text); motdSettings.PrimaryHeading = txtPrimaryHeading.Text; motdSettings.PrimaryText = txtPrimaryText.Text; motdSettings.SecondaryHeading = txtSecondaryHeading.Text; motdSettings.SecondaryText = txtSecondaryText.Text; db.SubmitChanges(); } lblUpdateStatus.Visible = true; }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { using (var db = new DataAccess.CSSDataContext()) { foreach (string username in usernames) { DataAccess.Login login = db.Logins.FirstOrDefault(p => p.Username == username.Trim()); if (login != null) { foreach(string roleName in roleNames) { DataAccess.Role role = db.Roles.FirstOrDefault(p => p.Name == roleName.Trim()); if (login.Login_Roles.Count(p => p.LoginId == login.Id && p.RoleId == role.Id) > 0) continue; db.Login_Roles.InsertOnSubmit(new DataAccess.Login_Role() { Login = login, LoginId = login.Id, Role = role, RoleId = role.Id }); } } } db.SubmitChanges(); } }
protected void btnSave_Click(object sender, EventArgs e) { using (var db = new DataAccess.CSSDataContext()) { int groupID = Int32.Parse(ddlGroup.SelectedValue); int roleID = Int32.Parse(ddlRole.SelectedValue); if (db.Group_Alias_GroupRoles.FirstOrDefault(p => p.GroupId == groupID && p.GroupRoleId == roleID && p.AliasId == AliasID) != null) { lblErrorMessage.Text = "User is already assigned to this group/role combination."; return; } DataAccess.Group_Alias_GroupRole newGroupRole = new Allegiance.CommunitySecuritySystem.DataAccess.Group_Alias_GroupRole() { AliasId = AliasID, GroupId = groupID, GroupRoleId = roleID }; db.Group_Alias_GroupRoles.InsertOnSubmit(newGroupRole); db.SubmitChanges(); int loginID = db.Alias.FirstOrDefault(p => p.Id == AliasID).LoginId; Response.Redirect(String.Format("~/User/EditUser.aspx?LoginID={0}&AliasID={1}", loginID, AliasID), true); } }
private void DeleteAlias(int aliasID) { using (var db = new DataAccess.CSSDataContext()) { var aliasToDelete = db.Alias.FirstOrDefault(p => p.Id == aliasID); if (aliasToDelete != null) { db.PersonalMessages.DeleteAllOnSubmit(aliasToDelete.PersonalMessages); db.GroupMessages.DeleteAllOnSubmit(aliasToDelete.GroupMessages); db.GroupRequests.DeleteAllOnSubmit(aliasToDelete.GroupRequests); db.Group_Alias_GroupRoles.DeleteAllOnSubmit(aliasToDelete.Group_Alias_GroupRoles); db.GroupMessage_Alias.DeleteAllOnSubmit(aliasToDelete.GroupMessage_Alias); db.AliasBanks.DeleteAllOnSubmit(aliasToDelete.AliasBanks); db.Alias.DeleteOnSubmit(aliasToDelete); db.SubmitChanges(); } } if (OnRequiresDataBind != null) { OnRequiresDataBind(); } ForcePageReload = true; }
private void BindData() { string searchText = txtSearch.Text; if (searchText.Contains("%") == false) { searchText += "%"; } using (var db = new DataAccess.CSSDataContext()) { var group = db.Groups.FirstOrDefault(p => p.Id == GroupID); lblSquadName.Text = group.Name; Group = group.Name; //var matchingUsers = group.Group_Alias_GroupRoles.Where(p => SqlMethods.Like(p.Alias.Callsign, searchText)).OrderBy(p => p.Alias.Callsign).Take(100).Select(p => p.Alias); if (searchText.Length > 1) { var matchingUsers = db.Alias.Where(p => SqlMethods.Like(p.Callsign, searchText) && db.Group_Alias_GroupRoles.Where(q => q.GroupId == GroupID && q.AliasId == p.Id).Count() == 0).OrderBy(p => p.Callsign).Take(100); gvUsers.DataSource = matchingUsers.ToList(); gvUsers.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (Business.Authorization.IsAdminOrSuperAdmin(User) == false) { throw new SecurityException("Access denied"); } using (var db = new DataAccess.CSSDataContext()) { //var unassignedGroups = db.Groups.Where( // p => db.Group_Alias_GroupRoles.Where( // q => q.GroupId == p.Id && q.AliasId == AliasID).Select( // r => r.GroupId).Contains(p.Id) == false); ddlGroup.DataSource = db.Groups; ddlGroup.DataTextField = "Name"; ddlGroup.DataValueField = "Id"; ddlGroup.DataBind(); ddlRole.DataSource = db.GroupRoles; ddlRole.DataTextField = "Name"; ddlRole.DataValueField = "Id"; ddlRole.DataBind(); lblCallsign.Text = db.Alias.FirstOrDefault(p => p.Id == AliasID).Callsign; } }
public override bool RoleExists(string roleName) { using (var db = new DataAccess.CSSDataContext()) { return(db.Roles.Count(p => p.Name == roleName.Trim()) > 0); } }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { using (var db = new DataAccess.CSSDataContext()) { foreach (string username in usernames) { DataAccess.Login login = db.Logins.FirstOrDefault(p => p.Username == username.Trim()); if (login != null) { foreach (string roleName in roleNames) { DataAccess.Role role = db.Roles.FirstOrDefault(p => p.Name == roleName.Trim()); if (login.Login_Roles.Count(p => p.LoginId == login.Id && p.RoleId == role.Id) > 0) { continue; } db.Login_Roles.InsertOnSubmit(new DataAccess.Login_Role() { Login = login, LoginId = login.Id, Role = role, RoleId = role.Id }); } } } db.SubmitChanges(); } }
public static List <DataAccess.Lobby> GetPublications() { using (var db = new DataAccess.CSSDataContext()) { return(db.Lobbies.ToList()); } }
public override string[] FindUsersInRole(string roleName, string usernameToMatch) { List <string> usernamesInRole = new List <string>(); using (var db = new DataAccess.CSSDataContext()) { var role = db.Roles.FirstOrDefault(p => p.Name == roleName.Trim()); if (role != null) { DataAccess.Login_Role loginRole = db.Login_Roles.FirstOrDefault(p => p.RoleId == role.Id); if (loginRole != null) { foreach (var login in db.Logins.Where(p => usernameToMatch == null || SqlMethods.Like(p.Username, usernameToMatch))) { if (login.Login_Roles.Contains(loginRole) == true) { usernamesInRole.Add(login.Username); } } } } } return(usernamesInRole.ToArray()); }
protected void Page_Load(object sender, EventArgs e) { if (Business.Authorization.IsAdminOrSuperAdmin(User) == false) throw new SecurityException("Access denied"); using (var db = new DataAccess.CSSDataContext()) { //var unassignedGroups = db.Groups.Where( // p => db.Group_Alias_GroupRoles.Where( // q => q.GroupId == p.Id && q.AliasId == AliasID).Select( // r => r.GroupId).Contains(p.Id) == false); ddlGroup.DataSource = db.Groups; ddlGroup.DataTextField = "Name"; ddlGroup.DataValueField = "Id"; ddlGroup.DataBind(); ddlRole.DataSource = db.GroupRoles; ddlRole.DataTextField = "Name"; ddlRole.DataValueField = "Id"; ddlRole.DataBind(); lblCallsign.Text = db.Alias.FirstOrDefault(p => p.Id == AliasID).Callsign; } }
private List <ACSSAuth.Management.Enforcer.Data.Player> SearchPlayers(bool canBeUnbanned) { string searchText = SearchText; if (searchText.Contains("%") == false) { searchText += "%"; } List <Data.Player> players = new List <Data.Player>(); using (var db = new DataAccess.CSSDataContext()) { //var aliases = db.Alias.Where(p => SqlMethods.Like(p.Callsign, searchText) || SqlMethods.Like(p.Login.Username, searchText)).OrderBy(p => p.Callsign).Take(100); var aliases = db.Alias.Where(p => SqlMethods.Like(p.Callsign, searchText)).OrderBy(p => p.Callsign).Take(100); foreach (var alias in aliases) { players.Add(new Data.Player() { LoginId = alias.LoginId, Callsign = alias.Callsign, IsBanned = alias.Login.IsBanned, LastContact = DateTime.MinValue, BanImage = (alias.Login.IsBanned == true) ? "~/images/dg_banned.png" : "~/images/dg_notbanned.png", CanBeUnbanned = canBeUnbanned }); } } return(players); }
//protected string LogoUrl; protected void Page_Load(object sender, EventArgs e) { int lobbyID; if (String.IsNullOrEmpty(Request.Params["lobbyID"]) == true || Int32.TryParse(Request.Params["lobbyID"], out lobbyID) == false) throw new Exception("Invalid lobby id."); using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var motd = db.Motds.FirstOrDefault(p => p.LobbyId == lobbyID); if (motd == null) throw new Exception("Lobby id out of range."); //LogoUrl = Page.ResolveUrl("~/Images/motd/" + motd.Logo + ".png"); imgLogo.ImageUrl = "~/Images/motd/" + motd.Logo + ".png"; lblBanner.Text = FormatLineBreaks(motd.Banner); lblDetails.Text = FormatLineBreaks(motd.Details); lblPadding.Text = GeneratePadding(motd.PaddingCrCount); lblPrimaryHeading.Text = FormatLineBreaks(motd.PrimaryHeading); lblPrimaryText.Text = FormatLineBreaks(motd.PrimaryText); lblSecondaryHeading.Text = FormatLineBreaks(motd.SecondaryHeading); lblSecondaryText.Text = FormatLineBreaks(motd.SecondaryText); lblUpdated.Text = FormatLineBreaks(motd.LastUpdated.ToShortDateString()); } }
// When the role dropdown changes in the datagrid. protected void ddlRoles_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddlRoles = (DropDownList)sender; GridViewRow row = (GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent; HiddenField txtGroupID = (HiddenField)row.FindControl("txtGroupID"); HiddenField txtAliasID = (HiddenField)row.FindControl("txtAliasID"); int groupID = Int32.Parse(txtGroupID.Value); int aliasID = Int32.Parse(txtAliasID.Value); int roleID = Int32.Parse(ddlRoles.SelectedValue); //((GridViewRow) ((DataControlFieldCell) ((DropDownList)sender).Parent).Parent).Cells[0].Text using (var db = new DataAccess.CSSDataContext()) { var groupRole = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.AliasId == aliasID && p.GroupId == groupID); if (groupRole == null) { throw new Exception("Couldn't set role for group. Group may have been deleted from alias, or role is no longer available."); } groupRole.GroupRoleId = roleID; db.SubmitChanges(); } if (OnRequiresDataBind != null) { OnRequiresDataBind(); } }
//protected string LogoUrl; protected void Page_Load(object sender, EventArgs e) { int lobbyID; if (String.IsNullOrEmpty(Request.Params["lobbyID"]) == true || Int32.TryParse(Request.Params["lobbyID"], out lobbyID) == false) { throw new Exception("Invalid lobby id."); } using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var motd = db.Motds.FirstOrDefault(p => p.LobbyId == lobbyID); if (motd == null) { throw new Exception("Lobby id out of range."); } //LogoUrl = Page.ResolveUrl("~/Images/motd/" + motd.Logo + ".png"); imgLogo.ImageUrl = "~/Images/motd/" + motd.Logo + ".png"; lblBanner.Text = FormatLineBreaks(motd.Banner); lblDetails.Text = FormatLineBreaks(motd.Details); lblPadding.Text = GeneratePadding(motd.PaddingCrCount); lblPrimaryHeading.Text = FormatLineBreaks(motd.PrimaryHeading); lblPrimaryText.Text = FormatLineBreaks(motd.PrimaryText); lblSecondaryHeading.Text = FormatLineBreaks(motd.SecondaryHeading); lblSecondaryText.Text = FormatLineBreaks(motd.SecondaryText); lblUpdated.Text = FormatLineBreaks(motd.LastUpdated.ToShortDateString()); } }
protected void btnSave_Click(object sender, EventArgs e) { int lobbyID = Int32.Parse(ddlLobby.SelectedValue); using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var motdSettings = db.Motds.FirstOrDefault(p => p.LobbyId == lobbyID); if (motdSettings == null) { motdSettings = new DataAccess.Motd(); db.Motds.InsertOnSubmit(motdSettings); motdSettings.LobbyId = lobbyID; } motdSettings.Banner = txtBanner.Text; motdSettings.Details = txtDetails.Text; motdSettings.LastUpdated = DateTime.Now; motdSettings.Logo = ddlLogo.SelectedValue; motdSettings.PaddingCrCount = Int32.Parse(txtPaddingCrCount.Text); motdSettings.PrimaryHeading = txtPrimaryHeading.Text; motdSettings.PrimaryText = txtPrimaryText.Text; motdSettings.SecondaryHeading = txtSecondaryHeading.Text; motdSettings.SecondaryText = txtSecondaryText.Text; db.SubmitChanges(); } lblUpdateStatus.Visible = true; }
protected void btnApplyAutoBan_Click(object sender, EventArgs e) { if (Page.User.IsInRole(ACSSAuth.Common.Enumerations.RoleType.Moderator.ToString()) == true || Page.User.IsInRole(ACSSAuth.Common.Enumerations.RoleType.Administrator.ToString()) == true || Page.User.IsInRole(ACSSAuth.Common.Enumerations.RoleType.ZoneLeader.ToString()) == true || Page.User.IsInRole(ACSSAuth.Common.Enumerations.RoleType.SuperAdministrator.ToString()) == true) { ACSSAuth.Server.Administration administration = new ACSSAuth.Server.Administration(); using (var db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, Page.User.Identity.Name); if (login != null) { administration.SetBan(new BanData() { Alias = txtCallsign.Value, BanTypeId = Convert.ToInt32(Request.Form[ddlAutoBanReason.UniqueID]), // For some reason, the post back doesn't get this value back into the control. BanMode = ACSSAuth.Common.Enumerations.BanMode.Auto, Password = login.Password, Username = login.Username }); } } } BindData(); }
protected void btnUnban_Click(object sender, EventArgs e) { if (Business.Authorization.IsZoneLeadOrAdminOrSuperAdmin(Page.User) == true) { ACSSAuth.Server.Administration administration = new ACSSAuth.Server.Administration(); using (var db = new DataAccess.CSSDataContext()) { var adminLogin = DataAccess.Login.FindLoginByUsernameOrCallsign(db, Page.User.Identity.Name); var userLogin = DataAccess.Login.FindLoginByUsernameOrCallsign(db, txtCallsign.Value); if (userLogin != null && adminLogin != null) { foreach (DataAccess.Ban ban in userLogin.Bans.Where(p => p.InEffect == true && p.DateExpires > DateTime.Now)) { administration.RemoveBan(new BanData() { Alias = txtCallsign.Value, BanId = ban.Id, Password = adminLogin.Password, Username = adminLogin.Username }); } } } } BindData(); }
private void BindData() { string searchText = txtSearch.Text; if (searchText.Contains("%") == false) searchText += "%"; using (var db = new DataAccess.CSSDataContext()) { var group = db.Groups.FirstOrDefault(p => p.Id == GroupID); lblSquadName.Text = group.Name; Group = group.Name; //var matchingUsers = group.Group_Alias_GroupRoles.Where(p => SqlMethods.Like(p.Alias.Callsign, searchText)).OrderBy(p => p.Alias.Callsign).Take(100).Select(p => p.Alias); if (searchText.Length > 1) { var matchingUsers = db.Alias.Where(p => SqlMethods.Like(p.Callsign, searchText) && db.Group_Alias_GroupRoles.Where(q => q.GroupId == GroupID && q.AliasId == p.Id).Count() == 0).OrderBy(p => p.Callsign).Take(100); gvUsers.DataSource = matchingUsers.ToList(); gvUsers.DataBind(); } } }
protected void btnSave_Click(object sender, EventArgs e) { using (var db = new DataAccess.CSSDataContext()) { int groupID = Int32.Parse(ddlGroup.SelectedValue); int roleID = Int32.Parse(ddlRole.SelectedValue); if (db.Group_Alias_GroupRoles.FirstOrDefault(p => p.GroupId == groupID && p.GroupRoleId == roleID && p.AliasId == AliasID) != null) { lblErrorMessage.Text = "User is already assigned to this group/role combination."; return; } DataAccess.Group_Alias_GroupRole newGroupRole = new Allegiance.CommunitySecuritySystem.DataAccess.Group_Alias_GroupRole() { AliasId = AliasID, GroupId = groupID, GroupRoleId = roleID }; db.Group_Alias_GroupRoles.InsertOnSubmit(newGroupRole); db.SubmitChanges(); int loginID = db.Alias.FirstOrDefault(p => p.Id == AliasID).LoginId; Response.Redirect(String.Format("~/User/EditUser.aspx?LoginID={0}&AliasID={1}", loginID, AliasID), true); } }
private void BindData() { using (var db = new DataAccess.CSSDataContext()) { DataAccess.Lobby lobby = db.Lobbies.FirstOrDefault(p => p.Id == PublicationID); txtBasePath.Text = lobby.BasePath; txtHost.Text = lobby.Host; txtLobbyName.Text = lobby.Name; chkEnabled.Checked = lobby.IsEnabled; chkRestrictive.Checked = lobby.IsRestrictive; } List <FileInfo> packageInfos = AutoUpdateManager.GetPackages(); List <Data.EditablePublication> packages = new List <Data.EditablePublication>(); foreach (FileInfo packageInfo in packageInfos) { packages.Add(new Data.EditablePublication() { IsIncluded = AutoUpdateManager.IsPackageExcludedFromPublication(PublicationID, packageInfo.Name) == false, Name = packageInfo.Name }); } gvPackages.DataSource = packages; gvPackages.DataBind(); }
private void UnbankAlias(DataAccess.CSSDataContext db, DataAccess.Alias alias) { if (alias.AliasBanks.Count() > 0) { alias.Callsign = alias.AliasBanks.FirstOrDefault().Callsign; db.AliasBanks.DeleteAllOnSubmit(alias.AliasBanks); } }
protected void OnDataChanged(object sender, EventArgs e) { using (var db = new DataAccess.CSSDataContext()) { var assignedRoles = db.Roles //.Where(p => p.Name != "SuperAdministrator" && p.Name != "Administrator") .Select ( r => new { Id = r.Id, Name = r.Name, Assigned = (r.Login_Roles.Where(p => (p.RoleId == r.Id && p.LoginId == LoginID)).Count() > 0), Login_Role = r.Login_Roles.FirstOrDefault(p => (p.RoleId == r.Id && p.LoginId == LoginID)) } ); foreach (var assignedRole in assignedRoles) { if (cblLoginRoles.Items.FindByValue(assignedRole.Id.ToString()).Selected != assignedRole.Assigned) { if (assignedRole.Assigned == true) { db.Login_Roles.DeleteOnSubmit(assignedRole.Login_Role); } else { db.Login_Roles.InsertOnSubmit(new ACSSAuth.DataAccess.Login_Role() { LoginId = LoginID, RoleId = assignedRole.Id }); } } } var login = db.Logins.FirstOrDefault(p => p.Id == LoginID); if (login == null) { throw new Exception("Couldn't find login for loginID: " + LoginID); } login.Email = txtEmail.Text.Trim(); login.Username = txtUsername.Text.Trim(); login.AllowVirtualMachineLogin = chkAllowVirtualMachine.Checked; // Keep the first alias the same as the user's login name. login.Aliases.OrderBy(p => p.DateCreated).First().Callsign = txtUsername.Text.Trim(); db.SubmitChanges(); lblSaveMessage.Text = "Data saved."; BindData(); } }
public override int GetNumberOfUsersOnline() { using (var db = new DataAccess.CSSDataContext()) { var logins = db.Logins.Where(p => p.FindCurrentSession() != null); return(logins.Count()); } }
public void SendMessageToGroup(int groupID, string subject, string message, string sendOnOrAfterDateTime, string expiresAfterDateTime) { ValidateMessage(subject, message); using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, HttpContext.Current.User.Identity.Name); // Get the groups the login has rights to send messages to. var availableGroups = DataAccess.Group.GetGroupsForLogin(db, login.Username, false); // Get the target group. var group = availableGroups.FirstOrDefault(p => p.Id == groupID); if (group == null) { throw new Exception("Couldn't find group id: " + groupID); } // Get the GAGR for the login assigned to the group that has the SL or ASL role. var gagrSender = group.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.Login.Username.Equals(login.Username, StringComparison.InvariantCultureIgnoreCase) && (p.GroupRole.Name == "Squad Leader" || p.GroupRole.Name == "Assistant Squad Leader" || p.GroupRole.Name == "Zone Lead")); if (gagrSender == null) { throw new Exception(HttpContext.Current.User.Identity.Name + " does not have rights to send this message."); } DateTime dateToSend = DateTime.Parse(sendOnOrAfterDateTime); DateTime dateExpires = DateTime.Parse(expiresAfterDateTime); DataAccess.GroupMessage groupMessage = new ACSSAuth.DataAccess.GroupMessage() { DateCreated = DateTime.Now, DateExpires = dateExpires, DateToSend = dateToSend, GroupId = group.Id, Message = message, SenderAliasId = gagrSender.Alias.Id, Subject = subject }; db.GroupMessages.InsertOnSubmit(groupMessage); db.SubmitChanges(); foreach (var targetAlias in group.Group_Alias_GroupRoles.Select(p => p.Alias).Distinct()) { db.GroupMessage_Alias.InsertOnSubmit(new DataAccess.GroupMessage_Alias() { Alias = targetAlias, DateViewed = null, GroupMessage = groupMessage }); } db.SubmitChanges(); } }
public override bool ValidateUser(string username, string password) { using (var db = new DataAccess.CSSDataContext()) { var login = db.Logins.FirstOrDefault(p => p.Username == username.Trim()); if (login == null) { var alias = DataAccess.Alias.GetAliasByCallsign(db, username); if (alias != null) { login = alias.Login; } } if (login == null) { return(false); } if (Settings.Default.UseIPConverge == true) { var connect = new IPConvergeProvider.Connect(); AuthenticationStatus authenticationStatus; string email; connect.Authenticate(login.Username, password, out authenticationStatus, out email); // Always update the user's email to the IPBoard email if the CSS email is different. // This way if the user uses the forgot password features, then the email will go to // their forum email which is the system of record. if (login.Email != email) { login.Email = email; db.SubmitChanges(); } return(authenticationStatus == AuthenticationStatus.Success); } else { try { // Supports calling this provider from both the CSS Server service and the web interface. return(login != null && (PasswordHash.ValidatePassword(password, login.Password) == true || login.Password == password)); } catch (FormatException) { Log.Write(LogType.AuthenticationServer, "LoginId: " + login.Id + ", loginName: " + login.Username + ", Legacy password couldn't be decoded. This is normal for a beta account."); return(false); } } } }
public void BindData() { lblErrorMessage.Text = String.Empty; using (var db = new DataAccess.CSSDataContext()) { var alias = db.Alias.FirstOrDefault(p => p.Id == AliasID); if (alias == null) { return; } List <Data.EditableGroupRole> groupRoles = new List <Data.EditableGroupRole>(); foreach (var groupRole in alias.Group_Alias_GroupRoles) { groupRoles.Add(new Data.EditableGroupRole() { GroupID = groupRole.GroupId, AliasID = groupRole.AliasId, GroupName = groupRole.Group.Name, SelectedRoleID = groupRole.GroupRole.Id, Tag = groupRole.Group.Tag, Token = groupRole.GroupRole.Token }); } gvGroups.DataSource = groupRoles; gvGroups.DataBind(); //pGroups.Visible = (groupRoles.Count > 0); pNoGroupRolesAssigned.Visible = (groupRoles.Count == 0); var availableGroups = db.Groups.Where(p => db.Group_Alias_GroupRoles.Where(r => r.AliasId == AliasID).Select(s => s.GroupId).Contains(p.Id) == false); if (availableGroups.Count() > 0) { pAddGroup.Visible = true; ddlGroup.DataSource = availableGroups; ddlGroup.DataTextField = "Name"; ddlGroup.DataValueField = "Id"; ddlGroup.DataBind(); ddlRole.DataSource = db.GroupRoles; ddlRole.DataTextField = "Name"; ddlRole.DataValueField = "Id"; ddlRole.DataBind(); } else { pAddGroup.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { if (Business.Authorization.IsZoneLeadOrAdminOrSuperAdmin(User) == false) Response.Redirect("~/Default.aspx"); if (Master.Breadcrumb != null) Master.Breadcrumb.Visible = true; using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var login = db.Logins.FirstOrDefault(p => p.Id == LoginID); if (login == null) throw new Exception("Couldn't look up login by id: " + LoginID); List<Business.IPReportItem> exactMatches = new List<Business.IPReportItem>(); List<Business.IPReportItem> subnetMatches = new List<Business.IPReportItem>(); foreach(var loggedIP in login.Identity.LogIPs) { foreach(var matchedUser in db.LogIPs.Where(p => p.IdentityId != login.IdentityId && p.IPAddress == loggedIP.IPAddress)) { exactMatches.Add(new Business.IPReportItem() { IPAddress = loggedIP.IPAddress, User1 = login.Identity.Logins.OrderBy(p => p.DateCreated).FirstOrDefault().Username, User1Date = loggedIP.LastAccessed, User2 = matchedUser.Identity.Logins.OrderBy(p => p.DateCreated).FirstOrDefault().Username, User2Date = matchedUser.LastAccessed }); } string subNetLabel = loggedIP.IPAddress.Substring(0, loggedIP.IPAddress.LastIndexOf('.')) + ".*"; string subNetPart = loggedIP.IPAddress.Substring(0, loggedIP.IPAddress.LastIndexOf('.')) + ".%"; foreach (var subnetMatch in db.LogIPs.Where(p => p.IdentityId != login.IdentityId && System.Data.Linq.SqlClient.SqlMethods.Like(p.IPAddress, subNetPart) == true)) { subnetMatches.Add(new Business.IPReportItem() { IPAddress = subNetLabel, User1 = login.Identity.Logins.OrderBy(p => p.DateCreated).FirstOrDefault().Username, User1Date = loggedIP.LastAccessed, User2 = subnetMatch.Identity.Logins.OrderBy(p => p.DateCreated).FirstOrDefault().Username, User2Date = subnetMatch.LastAccessed }); } } gvUserIpMatches.DataSource = exactMatches; gvUserIpMatches.DataBind(); gvUserSubnetMatches.DataSource = subnetMatches; gvUserSubnetMatches.DataBind(); } }
public override bool ValidateUser(string username, string password) { string hashedPassword = Allegiance.CommunitySecuritySystem.Common.Utility.Encryption.SHA256Hash(password); using (var db = new DataAccess.CSSDataContext()) { var login = db.Logins.FirstOrDefault(p => p.Username == username.Trim()); return(login != null && login.Password == hashedPassword); } }
public override void CreateRole(string roleName) { using (var db = new DataAccess.CSSDataContext()) { db.Roles.InsertOnSubmit(new Allegiance.CommunitySecuritySystem.DataAccess.Role() { Name = roleName }); db.SubmitChanges(); } }
public override void CreateRole(string roleName) { using (var db = new DataAccess.CSSDataContext()) { db.Roles.InsertOnSubmit(new ACSSAuth.DataAccess.Role() { Name = roleName }); db.SubmitChanges(); } }
public void SendMessageToGroup(int groupID, string subject, string message, string sendOnOrAfterDateTime, string expiresAfterDateTime) { ValidateMessage(subject, message); using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, HttpContext.Current.User.Identity.Name); // Get the groups the login has rights to send messages to. var availableGroups = DataAccess.Group.GetGroupsForLogin(db, login.Username, false); // Get the target group. var group = availableGroups.FirstOrDefault(p => p.Id == groupID); if (group == null) throw new Exception("Couldn't find group id: " + groupID); // Get the GAGR for the login assigned to the group that has the SL or ASL role. var gagrSender = group.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.Login.Username.Equals(login.Username, StringComparison.InvariantCultureIgnoreCase) && (p.GroupRole.Name == "Squad Leader" || p.GroupRole.Name == "Assistant Squad Leader" || p.GroupRole.Name == "Zone Lead")); if (gagrSender == null) throw new Exception(HttpContext.Current.User.Identity.Name + " does not have rights to send this message."); DateTime dateToSend = DateTime.Parse(sendOnOrAfterDateTime); DateTime dateExpires = DateTime.Parse(expiresAfterDateTime); DataAccess.GroupMessage groupMessage = new Allegiance.CommunitySecuritySystem.DataAccess.GroupMessage() { DateCreated = DateTime.Now, DateExpires = dateExpires, DateToSend = dateToSend, GroupId = group.Id, Message = message, SenderAliasId = gagrSender.Alias.Id, Subject = subject }; db.GroupMessages.InsertOnSubmit(groupMessage); db.SubmitChanges(); foreach (var targetAlias in group.Group_Alias_GroupRoles.Select(p => p.Alias).Distinct()) { db.GroupMessage_Alias.InsertOnSubmit(new DataAccess.GroupMessage_Alias() { Alias = targetAlias, DateViewed = null, GroupMessage = groupMessage }); } db.SubmitChanges(); } }
public override void CreateRole(string roleName) { using (var db = new DataAccess.CSSDataContext()) { db.Roles.InsertOnSubmit(new Allegiance.CommunitySecuritySystem.DataAccess.Role() { Name = roleName }); db.SubmitChanges(); } }
public void BindData() { lblErrorMessage.Text = String.Empty; using (var db = new DataAccess.CSSDataContext()) { var alias = db.Alias.FirstOrDefault(p => p.Id == AliasID); if (alias == null) return; List<Data.EditableGroupRole> groupRoles = new List<Data.EditableGroupRole>(); foreach (var groupRole in alias.Group_Alias_GroupRoles) { groupRoles.Add(new Data.EditableGroupRole() { GroupID = groupRole.GroupId, AliasID = groupRole.AliasId, GroupName = groupRole.Group.Name, SelectedRoleID = groupRole.GroupRole.Id, Tag = groupRole.Group.Tag, Token = groupRole.GroupRole.Token }); } gvGroups.DataSource = groupRoles; gvGroups.DataBind(); //pGroups.Visible = (groupRoles.Count > 0); pNoGroupRolesAssigned.Visible = (groupRoles.Count == 0); var availableGroups = db.Groups.Where(p => db.Group_Alias_GroupRoles.Where(r => r.AliasId == AliasID).Select(s => s.GroupId).Contains(p.Id) == false); if (availableGroups.Count() > 0) { pAddGroup.Visible = true; ddlGroup.DataSource = availableGroups; ddlGroup.DataTextField = "Name"; ddlGroup.DataValueField = "Id"; ddlGroup.DataBind(); ddlRole.DataSource = db.GroupRoles; ddlRole.DataTextField = "Name"; ddlRole.DataValueField = "Id"; ddlRole.DataBind(); } else { pAddGroup.Visible = false; } } }
private Business.GroupRole GetGroupRoleForCallsign(string callsign, int groupID) { Business.GroupRole groupRole; using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var gagrUser = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.Callsign == callsign && p.GroupId == groupID); groupRole = GetGroupRoleByRoleName(gagrUser.GroupRole.Name); } return(groupRole); }
public static string GetPublicationName(int publicationID) { using (var db = new DataAccess.CSSDataContext()) { var lobby = db.Lobbies.FirstOrDefault(p => p.Id == publicationID); if (lobby != null) { return(lobby.Name); } } return(null); }
private void BindBanReasons() { ddlAutoBanReason.Items.Clear(); ddlAutoBanReason.Items.Add(new ListItem("-- Rules of Conduct --", "0")); using (var db = new DataAccess.CSSDataContext()) { //var banTypes = db.BanTypes.OrderBy(p => p, new BanTypeComparer()); var banTypes = db.BanTypes.OrderBy(p => p.RocNumber.GetValueOrDefault(9999)).ThenBy(p => p.SrNumber.GetValueOrDefault(9999)); bool addedSrHeader = false; bool addedOtherHeader = false; bool defaultItemSelected = false; foreach (var banType in banTypes) { if (banType.RocNumber != null) { ddlAutoBanReason.Items.Add(new ListItem(" RoC #" + banType.RocNumber.ToString() + ": " + banType.Description, banType.Id.ToString())); if (defaultItemSelected == false) { ddlAutoBanReason.SelectedIndex = ddlAutoBanReason.Items.Count - 1; defaultItemSelected = true; } } else if (banType.SrNumber != null) { if (addedSrHeader == false) { ddlAutoBanReason.Items.Add(new ListItem("", "0")); ddlAutoBanReason.Items.Add(new ListItem("-- Supplementary Rules --", "0")); addedSrHeader = true; } ddlAutoBanReason.Items.Add(new ListItem(" SR #" + banType.SrNumber.ToString() + ": " + banType.Description, banType.Id.ToString())); } else { if (addedOtherHeader == false) { ddlAutoBanReason.Items.Add(new ListItem("", "0")); ddlAutoBanReason.Items.Add(new ListItem("-- Other --", "0")); addedOtherHeader = true; } ddlAutoBanReason.Items.Add(new ListItem(" " + banType.Description, banType.Id.ToString())); } } } }
private void BindData() { string searchText = txtSearch.Text; if (searchText.Contains("%") == false) { searchText += "%"; } using (var db = new DataAccess.CSSDataContext()) { var matchingUsers = db.Logins.Where( p => p.Aliases.Count(q => SqlMethods.Like(q.Callsign, searchText)) > 0 || SqlMethods.Like(p.Email, searchText) || SqlMethods.Like(p.Username, searchText) ).OrderBy(p => p.Username).Take(100).Select(p => new { DateCreated = p.DateCreated, Email = p.Email, Id = p.Id, LastLogin = p.Identity.DateLastLogin, Username = p.Username, LinkManagementLabel = p.Identity.Logins.Count() > 1 ? "Unlink" : "Link" }); //List<Data.EditableUser> editableUsers = new List<Allegiance.CommunitySecuritySystem.Management.Users.Data.EditableUser>(); //foreach (var matchingUser in matchingUsers) //{ // editableUsers.Add(new Allegiance.CommunitySecuritySystem.Management.Users.Data.EditableUser() // { // DateCreated = matchingUser.DateCreated, // Email = matchingUser.Email, // Id = matchingUser.Id, // LastLogin = matchingUser.Identity.DateLastLogin, // Username = matchingUser.Username, // LinkManagementLabel = matchingUser.Identity.Links.Count() > 0 ? "Unlink" : "Link" // }); //} if (matchingUsers.Count() > 0) { gvUsers.Visible = true; gvUsers.DataSource = matchingUsers; gvUsers.DataBind(); } else { gvUsers.Visible = false; } } }
protected void OnDataChanged(object sender, EventArgs e) { using (var db = new DataAccess.CSSDataContext()) { var assignedRoles = db.Roles //.Where(p => p.Name != "SuperAdministrator" && p.Name != "Administrator") .Select ( r => new { Id = r.Id, Name = r.Name, Assigned = (r.Login_Roles.Where(p => (p.RoleId == r.Id && p.LoginId == LoginID)).Count() > 0), Login_Role = r.Login_Roles.FirstOrDefault(p => (p.RoleId == r.Id && p.LoginId == LoginID)) } ); foreach (var assignedRole in assignedRoles) { if (cblLoginRoles.Items.FindByValue(assignedRole.Id.ToString()).Selected != assignedRole.Assigned) { if (assignedRole.Assigned == true) db.Login_Roles.DeleteOnSubmit(assignedRole.Login_Role); else db.Login_Roles.InsertOnSubmit(new Allegiance.CommunitySecuritySystem.DataAccess.Login_Role() { LoginId = LoginID, RoleId = assignedRole.Id }); } } var login = db.Logins.FirstOrDefault(p => p.Id == LoginID); if (login == null) throw new Exception("Couldn't find login for loginID: " + LoginID); login.Email = txtEmail.Text.Trim(); login.Username = txtUsername.Text.Trim(); login.AllowVirtualMachineLogin = chkAllowVirtualMachine.Checked; // Keep the first alias the same as the user's login name. login.Aliases.OrderBy(p => p.DateCreated).First().Callsign = txtUsername.Text.Trim(); db.SubmitChanges(); lblSaveMessage.Text = "Data saved."; BindData(); } }
public static MembershipUser FindUserByPredicate(this Expression<Func<DataAccess.Login, bool>> predicate) { MembershipUser membershipUser = null; using (var db = new DataAccess.CSSDataContext()) { var login = db.Logins.FirstOrDefault(predicate); if (login != null) membershipUser = MembershipUserUtility.CreateMembershipUserFromLogin(login); } return membershipUser; }
private void BankAlias(DataAccess.CSSDataContext db, DataAccess.Alias alias) { if (alias.AliasBanks.Count() == 0) { db.AliasBanks.InsertOnSubmit(new DataAccess.AliasBank() { AliasId = alias.Id, Callsign = alias.Callsign, DateCreated = DateTime.Now }); alias.Callsign = "ACS_" + new Random().Next(100, 999); } }
private void BindData() { string searchText = txtSearch.Text; if (searchText.Contains("%") == false) searchText += "%"; using (var db = new DataAccess.CSSDataContext()) { var matchingUsers = db.Logins.Where( p => p.Aliases.Count(q => SqlMethods.Like(q.Callsign, searchText)) > 0 || SqlMethods.Like(p.Email, searchText) || SqlMethods.Like(p.Username, searchText) ).OrderBy(p => p.Username).Take(100).Select( p => new { DateCreated = p.DateCreated, Email = p.Email, Id = p.Id, LastLogin = p.Identity.DateLastLogin, Username = p.Username, LinkManagementLabel = p.Identity.Logins.Count() > 1 ? "Unlink" : "Link" }); //List<Data.EditableUser> editableUsers = new List<Allegiance.CommunitySecuritySystem.Management.Users.Data.EditableUser>(); //foreach (var matchingUser in matchingUsers) //{ // editableUsers.Add(new Allegiance.CommunitySecuritySystem.Management.Users.Data.EditableUser() // { // DateCreated = matchingUser.DateCreated, // Email = matchingUser.Email, // Id = matchingUser.Id, // LastLogin = matchingUser.Identity.DateLastLogin, // Username = matchingUser.Username, // LinkManagementLabel = matchingUser.Identity.Links.Count() > 0 ? "Unlink" : "Link" // }); //} if (matchingUsers.Count() > 0) { gvUsers.Visible = true; gvUsers.DataSource = matchingUsers; gvUsers.DataBind(); } else { gvUsers.Visible = false; } } }
protected void btnSave_Click(object sender, EventArgs e) { using (var db = new DataAccess.CSSDataContext()) { DataAccess.Lobby lobby = db.Lobbies.FirstOrDefault(p => p.Id == PublicationID); lobby.Host = txtHost.Text.Trim(); lobby.BasePath = txtBasePath.Text.Trim(); lobby.IsEnabled = chkEnabled.Checked; lobby.IsRestrictive = chkRestrictive.Checked; db.SubmitChanges(); } BindData(); }
private void BindData() { string searchText = txtSearch.Text; if (searchText.Contains("%") == false) searchText += "%"; using (var db = new DataAccess.CSSDataContext()) { var primaryLogin = db.Logins.FirstOrDefault(p => p.Id == PrimaryLoginID); var unlinkedLoginIds = db.Login_UnlinkedLogins .Where(p => p.LoginId1 == PrimaryLoginID) .Select(p => p.LoginId2) .Union(db.Login_UnlinkedLogins .Where(p => p.LoginId2 == PrimaryLoginID) .Select(p => p.LoginId1) ); var matchingUsers = db.Logins.Where( p => (p.Aliases.Count(q => SqlMethods.Like(q.Callsign, searchText)) > 0 || SqlMethods.Like(p.Email, searchText) || SqlMethods.Like(p.Username, searchText)) && p.IdentityId != primaryLogin.IdentityId && unlinkedLoginIds.Contains(p.Id) == false ).OrderBy(p => p.Username).Take(100).Select(p => new { DateCreated = p.DateCreated, Email = p.Email, Id = p.Id, LastLogin = p.Identity.DateLastLogin, Username = p.Username }); if (matchingUsers.Count() > 0) { gvLogins.Visible = true; gvLogins.DataSource = matchingUsers; gvLogins.DataBind(); } else { gvLogins.Visible = false; } } }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { using (var db = new DataAccess.CSSDataContext()) { var role = db.Roles.FirstOrDefault(p => p.Name == roleName.Trim()); if (role == null) return false; if (role.Login_Roles.Count() > 0 && throwOnPopulatedRole == true) throw new ProviderException("This role is being used by one or more logins!"); db.Roles.DeleteOnSubmit(role); db.SubmitChanges(); } return true; }
public static MembershipUserCollection FindUsersByPredicate(this Expression<Func<DataAccess.Login, bool>> predicate, int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection returnValue = new MembershipUserCollection(); totalRecords = 0; using (var db = new DataAccess.CSSDataContext()) { var logins = db.Logins.Where(predicate); totalRecords = logins.Count(); foreach (var login in logins.Skip(pageIndex * pageSize).Take(pageSize)) { returnValue.Add(MembershipUserUtility.CreateMembershipUserFromLogin(login)); } } return returnValue; }
protected void btnApplyManualBan_Click(object sender, EventArgs e) { if (Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.Moderator.ToString()) == true || Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.ZoneLeader.ToString()) == true || Page.User.IsInRole(Allegiance.CommunitySecuritySystem.Common.Enumerations.RoleType.SuperAdministrator.ToString()) == true) { Allegiance.CommunitySecuritySystem.Server.Administration administration = new Allegiance.CommunitySecuritySystem.Server.Administration(); DateTime banDate = DateTime.MinValue; banDate = banDate.AddYears(Int32.Parse(ddlManualBanYears.SelectedValue)); banDate = banDate.AddMonths(Int32.Parse(ddlManualBanMonths.SelectedValue)); banDate = banDate.AddDays(Int32.Parse(ddlManualBanDays.SelectedValue)); banDate = banDate.AddHours(Int32.Parse(ddlManualBanHours.SelectedValue)); banDate = banDate.AddMinutes(Int32.Parse(ddlManualBanMinutes.SelectedValue)); TimeSpan banTime = banDate.Subtract(DateTime.MinValue); using (var db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, Page.User.Identity.Name); if (login != null) { administration.SetBan(new BanData() { Alias = txtCallsign.Value, BanMode = Allegiance.CommunitySecuritySystem.Common.Enumerations.BanMode.Custom, Duration = banTime, Reason = txtBanReason.Text, Password = login.Password, Username = login.Username }); } } } BindData(); }
public void SendMessageToCallsigns(string [] callsigns, string subject, string message, string sendOnOrAfterDateTime, string expiresAfterDateTime) { ValidateMessage(subject, message); List<string> callsignsToTest = new List<string>(callsigns); using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, HttpContext.Current.User.Identity.Name); // Get the groups the login has rights to send messages to. var availableSquads = DataAccess.Group.GetGroupsForLogin(db, login.Username, false); List<int> loginIDsAlreadyMessaged = new List<int>(); foreach(DataAccess.Group group in availableSquads) { // Get the alias assigned to the login that is tied to the group. the alias must be an ASL or SL. var gagrSender = group.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.Login.Username.Equals(login.Username, StringComparison.InvariantCultureIgnoreCase) && (p.GroupRole.Name == "Squad Leader" || p.GroupRole.Name == "Assistant Squad Leader" || p.GroupRole.Name == "Zone Lead")); if(gagrSender != null) { // Get all the callsigns assigned to the group that are also in the target list that have not already been messaged. var loginIDsToSendMessageTo = group.Group_Alias_GroupRoles.Where(p => callsigns.Contains(p.Alias.Callsign) == true && loginIDsAlreadyMessaged.Contains(p.Alias.LoginId) == false).Select(p => p.Alias.LoginId).Distinct(); foreach (var loginID in loginIDsToSendMessageTo) { SendMessageToCallsign(db, subject, message, gagrSender.Alias, loginID, sendOnOrAfterDateTime, expiresAfterDateTime); loginIDsAlreadyMessaged.Add(loginID); } } } db.SubmitChanges(); } }
protected void gvMembers_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Data.SquadMember squadMemeber = (Data.SquadMember)e.Row.DataItem; DropDownList ddlRoles = (DropDownList)e.Row.FindControl("ddlRoles"); HiddenField txtGroupID = (HiddenField)e.Row.FindControl("txtGroupID"); HiddenField txtAliasID = (HiddenField)e.Row.FindControl("txtAliasID"); Label lblRoleName = (Label)e.Row.FindControl("lblRoleName"); Panel pRemoveLink = (Panel)e.Row.FindControl("pRemoveLink"); Panel pMessageLink = (Panel)e.Row.FindControl("pMessageLink"); Panel pSelectMember = (Panel)e.Row.FindControl("pSelectMember"); List<DataAccess.GroupRole> allRoles; Business.GroupRole groupRole = GetCurrentUserGroupRole(Int32.Parse(ddlSquads.SelectedValue)); using (var db = new DataAccess.CSSDataContext()) { var group = db.Groups.FirstOrDefault(p => p.Id == Int32.Parse(ddlSquads.SelectedValue)); if (group == null) throw new Exception("Invalid groupID"); switch (groupRole) { // Squad leaders can edit all roles on the squad. case Business.GroupRole.SquadLeader: case Business.GroupRole.ZoneLead: if (group.IsSquad == true) allRoles = db.GroupRoles.Where(p => p.Name == "Pilot" || p.Name == "Assistant Squad Leader" || p.Name == "Squad Leader").ToList(); else allRoles = db.GroupRoles.ToList(); break; // ASLs can only add/remove pilots. case Business.GroupRole.AssistantSquadLeader: if (group.IsSquad == true) { allRoles = db.GroupRoles.Where(p => p.Name == "Pilot" || p.Name == "Assistant Squad Leader").ToList(); } else { //allRoles = db.GroupRoles.Where(p => p.Name != "Zone Lead" && p.Name != "Squad Leader" && p.Name != "Developer").ToList(); // Only Zone Leaders can modify roles. allRoles = db.GroupRoles.Where(p => p.Name == "Pilot").ToList(); pRemoveLink.Visible = false; ddlRoles.Visible = false; pMessageLink.Visible = false; pSelectMember.Visible = false; } if (squadMemeber.SelectedRoleName == "Squad Leader") { pRemoveLink.Visible = false; ddlRoles.Visible = false; } break; // Pilots can only view the list. default: allRoles = db.GroupRoles.Where(p => p.Name == "Pilot").ToList(); pRemoveLink.Visible = false; ddlRoles.Visible = false; pMessageLink.Visible = false; pSelectMember.Visible = false; break; } // Prevent user from editing their own account. if(squadMemeber.Callsign.Equals(User.Identity.Name, StringComparison.CurrentCultureIgnoreCase) == true) ddlRoles.Visible = false; } if (ddlRoles.Visible == false) { lblRoleName.Visible = true; lblRoleName.Text = squadMemeber.SelectedRoleName; } ddlRoles.DataSource = allRoles; ddlRoles.DataTextField = "Name"; ddlRoles.DataValueField = "Id"; ddlRoles.DataBind(); ddlRoles.SelectedValue = squadMemeber.SelectedRoleID.ToString(); txtGroupID.Value = squadMemeber.GroupID.ToString(); txtAliasID.Value = squadMemeber.AliasID.ToString(); } }
private void AddCallsignToGroup(string callsign, int groupID) { Business.GroupRole currentUserGroupRole = GetCurrentUserGroupRole(groupID); if (currentUserGroupRole != Business.GroupRole.AssistantSquadLeader && currentUserGroupRole != Business.GroupRole.SquadLeader && currentUserGroupRole != Business.GroupRole.ZoneLead) throw new Exception("Access denied."); using (var db = new DataAccess.CSSDataContext()) { var group = db.Groups.FirstOrDefault(p => p.Id == groupID); if (group == null) throw new Exception("Invalid groupID"); var alias = db.Alias.FirstOrDefault(p => p.Callsign == callsign); if (alias == null) throw new Exception("Invalid callsign"); var targetRole = db.GroupRoles.FirstOrDefault(p => p.Name == "Pilot"); if (targetRole == null) throw new Exception("No pilot role."); DataAccess.Group_Alias_GroupRole gagrTarget = new DataAccess.Group_Alias_GroupRole() { AliasId = alias.Id, GroupId = group.Id, GroupRoleId = targetRole.Id }; db.Group_Alias_GroupRoles.InsertOnSubmit(gagrTarget); // If the group name is the Moderators group, then add the Moderator role to the group member. if (group.Name.Equals("Moderators", StringComparison.InvariantCultureIgnoreCase) == true) { var moderatorRole = db.Roles.FirstOrDefault(p => p.Name == "Moderator"); var loginRole = db.Login_Roles.FirstOrDefault(p => p.LoginId == alias.LoginId && p.RoleId == moderatorRole.Id); if (loginRole == null) { db.Login_Roles.InsertOnSubmit(new DataAccess.Login_Role() { LoginId = alias.LoginId, RoleId = moderatorRole.Id }); } } // If the group is ACS, then bank the original alias, and swap the alias to an ACS_COM_XXX hider. if (group.Tag.Equals("acs", StringComparison.InvariantCultureIgnoreCase) == true) { BankAlias(db, alias); } db.SubmitChanges(); } Response.Redirect("~/Squads/Default.aspx?groupID=" + groupID, true); }
private void BindData(int selectedSquadID) { txtSendDate.Text = DateTime.Now.ToShortDateString(); txtExpirationDate.Text = DateTime.Now.AddYears(1).ToShortDateString(); using (var db = new DataAccess.CSSDataContext()) { var currentLogin = DataAccess.Login.FindLoginByUsernameOrCallsign(db, User.Identity.Name); var aliases = db.Alias.Where(p => p.LoginId == currentLogin.Id); var availableSquads = DataAccess.Group.GetGroupsForLogin(db, currentLogin.Username, false); pNoSquadsAvailable.Visible = availableSquads.Count() == 0; pSquadList.Visible = availableSquads.Count() != 0; ddlSquads.Items.Clear(); foreach (var availableSquad in availableSquads) { ddlSquads.Items.Add(new ListItem() { Text = availableSquad.Name, Value = availableSquad.Id.ToString(), Selected = (availableSquad.Id == selectedSquadID) }); } int selectedGroupID; if (Int32.TryParse(ddlSquads.SelectedValue, out selectedGroupID) == true) { Business.GroupRole currentUserGroupRole = GetCurrentUserGroupRole(selectedGroupID); if (currentUserGroupRole == Business.GroupRole.AssistantSquadLeader || currentUserGroupRole == Business.GroupRole.SquadLeader || currentUserGroupRole == Business.GroupRole.ZoneLead) UserIsAslOrBetter = true; pAslOptions.Visible = UserIsAslOrBetter; var gagrSquadMembers = db.Group_Alias_GroupRoles.Where(p => p.GroupId == selectedGroupID); List<Data.SquadMember> squadMembers = new List<Data.SquadMember>(); foreach (var squadMember in gagrSquadMembers) squadMembers.Add(new Data.SquadMember() { Callsign = squadMember.Alias.Callsign, Token = squadMember.GroupRole.Token.GetValueOrDefault(), AliasID = squadMember.Alias.Id, SelectedRoleID = squadMember.GroupRole.Id, SelectedRoleName = squadMember.GroupRole.Name, GroupID = squadMember.GroupId, }); squadMembers.Sort(delegate(Data.SquadMember left, Data.SquadMember right) { if (left.Token != right.Token) { if (left.Token == '*') return -1; if (right.Token == '*') return 1; if (left.Token == '^') return -1; if (right.Token == '^') return 1; } return left.Callsign.CompareTo(right.Callsign); }); gvMembers.DataSource = squadMembers; gvMembers.DataBind(); } } }
//private Business.GroupRole? _userGroupRole = null; //protected Business.GroupRole UserGroupRole //{ // get // { // if (_userGroupRole == null) // { // using(DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) // { // int groupID = Int32.Parse(ddlSquads.SelectedItem.Value); // var login = db.Logins.FirstOrDefault(p => p.Username == User.Identity.Name); // var gagrLogin = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.LoginId == login.Id && p.GroupId == groupID); // switch (gagrLogin.GroupRole.Name) // { // case "Assistant Squad Leader": // _userGroupRole = Business.GroupRole.AssistantSquadLeader; // break; // case "Squad Leader": // _userGroupRole = Business.GroupRole.SquadLeader; // break; // default: // _userGroupRole = Business.GroupRole.Pilot; // break; // } // } // } // return _userGroupRole.Value; // } //} private Business.GroupRole GetCurrentUserGroupRole(int groupID) { Business.GroupRole groupRole = Business.GroupRole.Pilot; using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, User.Identity.Name); if (login != null) { var gagrLogin = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.LoginId == login.Id && p.GroupId == groupID); groupRole = GetGroupRoleByRoleName(gagrLogin.GroupRole.Name); } } return groupRole; }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { using (var db = new DataAccess.CSSDataContext()) { DataAccess.Login login; if (Settings.Default.UseIPConverge == true) { login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, username); if (login == null) return false; var connect = new IPConvergeProvider.Connect(); // TODO: If IP Converge is to be used ever, then working around IPC's MD5 password hashs will need to be done. //connect.ChangePassword(login.Email, newPasswordHash); } else { login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, username); if (login == null) return false; if (PasswordHash.ValidatePassword(oldPassword, login.Password) == false) return false; } login.Password = PasswordHash.CreateHash(newPassword); db.SubmitChanges(); } return true; }
public static List<DataAccess.Lobby> GetPublications() { using (var db = new DataAccess.CSSDataContext()) { return db.Lobbies.ToList(); } }
public static string GetPublicationName(int publicationID) { using (var db = new DataAccess.CSSDataContext()) { var lobby = db.Lobbies.FirstOrDefault(p => p.Id == publicationID); if (lobby != null) return lobby.Name; } return null; }
public static bool DeployPublication(int publicationID) { using (var db = new DataAccess.CSSDataContext()) { DataAccess.Lobby lobby = db.Lobbies.FirstOrDefault(p => p.Id == publicationID); if(lobby == null) throw new Exception("Couldn't get lobby for publication id: " + publicationID); if (Directory.Exists(lobby.BasePath) == false) Directory.CreateDirectory(lobby.BasePath); List<FileCollision> fileCollisions = new List<FileCollision>(); Dictionary<string, UpdateItem> filesInPublication = new Dictionary<string, UpdateItem>(); // Remove physical files from the directory. Not doing this with a recursive directory delete because // I don't want someone to put in a bad path into the content manager web UI, and then drill the // whole drive. foreach (DataAccess.AutoUpdateFile_Lobby file in db.AutoUpdateFile_Lobbies.Where(p => p.LobbyId == lobby.Id)) { string fileToDelete = Path.Combine(lobby.BasePath, file.AutoUpdateFile.Filename); if (File.Exists(fileToDelete) == true) File.Delete(fileToDelete); } // Clear all files for the lobby. db.AutoUpdateFile_Lobbies.DeleteAllOnSubmit(db.AutoUpdateFile_Lobbies.Where(p => p.LobbyId == lobby.Id)); db.SubmitChanges(); if (AutoUpdateManager.TryGetPublicationFiles(publicationID, out filesInPublication, out fileCollisions) == true) { foreach (UpdateItem fileInfo in filesInPublication.Values) { string checksum; using (SHA1 hasher = SHA1.Create()) { using (FileStream fs = new FileStream(fileInfo.FileInfo.FullName, FileMode.Open, FileAccess.Read)) checksum = Convert.ToBase64String(hasher.ComputeHash(fs)); } string fileVersion = String.Empty; FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileInfo.FileInfo.FullName); // Doing it this way, as sometimes there is product or vendor info at the // end of the file version spec. ProductVersion may not correctly reflect the actual // version of the file all the time. if (fileVersionInfo != null && fileVersionInfo.FileVersion != null) fileVersion = String.Format("{0}.{1}.{2}.{3}", fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart); string relativeFilePath = Path.Combine(fileInfo.RelativeDirectory, fileInfo.Name); DataAccess.AutoUpdateFile autoUpdateFile = db.AutoUpdateFiles.FirstOrDefault(p => p.Filename == relativeFilePath); if (autoUpdateFile == null) { autoUpdateFile = new Allegiance.CommunitySecuritySystem.DataAccess.AutoUpdateFile() { Filename = relativeFilePath, IsProtected = fileInfo.IsProtected }; db.AutoUpdateFiles.InsertOnSubmit(autoUpdateFile); db.SubmitChanges(); } else { if (autoUpdateFile.IsProtected != fileInfo.IsProtected) { autoUpdateFile.IsProtected = fileInfo.IsProtected; db.SubmitChanges(); } } DataAccess.AutoUpdateFile_Lobby lobbyFile = db.AutoUpdateFile_Lobbies.FirstOrDefault(p => p.AutoUpdateFileId == autoUpdateFile.Id && p.LobbyId == lobby.Id); if (lobbyFile == null) { lobbyFile = new Allegiance.CommunitySecuritySystem.DataAccess.AutoUpdateFile_Lobby() { AutoUpdateFileId = autoUpdateFile.Id, CurrentVersion = fileVersion, DateCreated = fileInfo.FileInfo.CreationTime, DateModified = fileInfo.FileInfo.LastWriteTime, ValidChecksum = checksum, LobbyId = lobby.Id }; db.AutoUpdateFile_Lobbies.InsertOnSubmit(lobbyFile); db.SubmitChanges(); } string targetFilePath = Path.Combine(lobby.BasePath, relativeFilePath); string targetFileDirectory = Path.GetDirectoryName(targetFilePath); if (Directory.Exists(targetFileDirectory) == false) Directory.CreateDirectory(targetFileDirectory); File.Copy(fileInfo.FileInfo.FullName, targetFilePath, true); } GenerateFileListForAutoUpdate(lobby); } // Clean up any unused AutoUpdateFile records. //db.AutoUpdateFiles.DeleteAllOnSubmit(db.AutoUpdateFiles.Where(p => db.AutoUpdateFile_Lobbies.Select(r => r.AutoUpdateFileId).Contains(p.Id) == false)); //db.SubmitChanges(); } return true; }
private Business.GroupRole GetGroupRoleForCallsign(string callsign, int groupID) { Business.GroupRole groupRole; using (DataAccess.CSSDataContext db = new DataAccess.CSSDataContext()) { var gagrUser = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.Callsign == callsign && p.GroupId == groupID); groupRole = GetGroupRoleByRoleName(gagrUser.GroupRole.Name); } return groupRole; }
// When the role dropdown changes in the datagrid. protected void ddlRoles_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddlRoles = (DropDownList)sender; GridViewRow row = (GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent; HiddenField txtGroupID = (HiddenField)row.FindControl("txtGroupID"); HiddenField txtAliasID = (HiddenField)row.FindControl("txtAliasID"); int groupID = Int32.Parse(txtGroupID.Value); int aliasID = Int32.Parse(txtAliasID.Value); int roleID = Int32.Parse(ddlRoles.SelectedValue); bool requiresSquadLeader = false; // Only a SL can grant SL to another user. if (ddlRoles.SelectedItem.Text == "Squad Leader") requiresSquadLeader = true; using (var db = new DataAccess.CSSDataContext()) { var group = db.Groups.FirstOrDefault(p => p.Id == groupID); var groupRole = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.AliasId == aliasID && p.GroupId == groupID); if (groupRole == null) throw new Exception("Couldn't set role for group. Group may have been deleted from alias, or role is no longer available."); var login = DataAccess.Login.FindLoginByUsernameOrCallsign(db, User.Identity.Name); var gagrLogin = groupRole.Group.Group_Alias_GroupRoles.FirstOrDefault(p => p.Alias.LoginId == login.Id); if (group.IsSquad == true) { // Only a SL can remove rights to another SL. if (groupRole.GroupRole.Name.Equals("Squad Leader", StringComparison.InvariantCultureIgnoreCase) == true) requiresSquadLeader = true; bool isSquadLeader = gagrLogin.GroupRole.Name.Equals("Squad Leader", StringComparison.InvariantCultureIgnoreCase); bool isAssistantSquadLeader = gagrLogin.GroupRole.Name.Equals("Assistant Squad Leader", StringComparison.InvariantCultureIgnoreCase); if ((isSquadLeader == false && isAssistantSquadLeader == false) || (requiresSquadLeader == true && isSquadLeader == false)) { lblErrorMessage.Text = "You don't have rights to perform this action."; return; } } else { //var moderatorRole = db.Roles.FirstOrDefault(p => p.Name == "Moderator"); //bool requiresZoneLeader = false; //if (groupRole.GroupRole.Name.Equals("Zone Lead", StringComparison.InvariantCultureIgnoreCase) == true) // requiresZoneLeader = true; bool requiresZoneLeader = true; if (login.HasAnyRole(new Common.Enumerations.RoleType[] { Common.Enumerations.RoleType.ZoneLeader, Common.Enumerations.RoleType.Administrator, Common.Enumerations.RoleType.SuperAdministrator }) == false && requiresZoneLeader == true) { lblErrorMessage.Text = "You must be a Zone Leader or better to perform this action."; return; } } } // Can't use groupRole from above, some of the queries against it cause it to lock to a foreign key. using (var db = new DataAccess.CSSDataContext()) { var groupRoleToUpdate = db.Group_Alias_GroupRoles.FirstOrDefault(p => p.AliasId == aliasID && p.GroupId == groupID); groupRoleToUpdate.GroupRoleId = roleID; // If the group is ACS, then bank the alias if the user is going into the pilot role, // otherwise unbank it if they are going into a token'd role. if (groupRoleToUpdate.Group.Tag.Equals("acs", StringComparison.InvariantCultureIgnoreCase) == true) { if (groupRoleToUpdate.GroupRole.Token == null) BankAlias(db, groupRoleToUpdate.Alias); else UnbankAlias(db, groupRoleToUpdate.Alias); } db.SubmitChanges(); } BindData(groupID); }