protected void RegisterLinkButton_Click(object sender, EventArgs e) { PasswordMismatchLabel.Visible = false; if (PasswordTextBox.Text != ConfirmPasswordTextBox.Text || PasswordTextBox.Text.Trim().Length < 6) { PasswordMismatchLabel.Visible = true; return; } else { using (PlexingFleetDataContext context = new PlexingFleetDataContext(WebConfigurationManager.ConnectionStrings["PlexManagerConnectionString"].ConnectionString)) { PlexUser plexUser = context.PlexUsers.FirstOrDefault(x => x.CharacterId == CharacterId); if (plexUser != null) { ShowRegistryInformation(false, "Your character have already been registered."); //User already exists, dont register again return; } else { plexUser = new PlexUser(); }; plexUser.CharacterId = CharacterId; plexUser.CharacterName = CharacterName; plexUser.CorpId = CorpId; plexUser.CorpName = CorpName; plexUser.AllianceId = AllianceId; plexUser.AllianceName = AllianceName; plexUser.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordTextBox.Text, "md5"); plexUser.Enabled = true; context.PlexUsers.InsertOnSubmit(plexUser); Corp corp = context.Corps.FirstOrDefault(x => x.CorpId == CorpId); //Check to see if the person registring belongs to a corp that have not previously been added if (corp == null) { corp = new Corp() { CorpId = CorpId, CorpName = CorpName, AllianceId = AllianceId, AllianceName = AllianceName, Enabled = false }; context.Corps.InsertOnSubmit(corp); } context.SubmitChanges(); Response.Redirect(PageReferrer.Page_Login); } } }
public static Dictionary <string, string> CreatePlexRequest(PlexUser user = null, string userName = null, string password = null) { var headers = new Dictionary <string, string> { { "X-Plex-Platform", "Windows" }, { "X-Plex-Platform-Version", "NT" }, { "X-Plex-Provides", "player" }, { "X-Plex-Client-Identifier", "RestAndRelaxForPlex" }, { "X-Plex-Product", "PlexWMC" }, { "X-Plex-Version", "0" } }; if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { var authBytes = Encoding.UTF8.GetBytes(userName + ":" + password); headers.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes)); } if (user != null) { headers.Add("X-Plex-Token", user.AuthenticationToken); } return(headers); }
private static void CreatePlexRequest(HttpHeaders headers, PlexUser user) { headers.Add("X-Plex-Platform", "Windows"); headers.Add("X-Plex-Platform-Version", "NT"); headers.Add("X-Plex-Provides", "player"); headers.Add("X-Plex-Client-Identifier", "Complexion"); headers.Add("X-Plex-Product", "PlexWMC"); headers.Add("X-Plex-Version", "0"); if (user != null) { headers.Add("X-Plex-Token", user.AuthenticationToken); } }
protected void UpdateLinkButton_Click(object sender, EventArgs e) { using (PlexingFleetDataContext context = new PlexingFleetDataContext(ConnectionString)) { PlexUser user = context.PlexUsers.FirstOrDefault(x => x.CharacterId == CharacterIdLabel.Text.ToInt()); user.Enabled = !BannedCheckBox.Checked; if (user.CorpId != CorporationDropDownList.SelectedValue.ToInt()) { var corp = context.Corps.FirstOrDefault(x => x.CorpId == CorporationDropDownList.SelectedValue.ToInt()); if (corp != null) { user.CorpId = corp.CorpId; user.AllianceId = corp.AllianceId; user.CorpName = corp.CorpName; user.AllianceName = corp.AllianceName; } } if (NewPasswordTextBox.Text.Trim() != string.Empty && NewPasswordTextBox.Text == ConfirmPasswordTextBox.Text) { user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(NewPasswordTextBox.Text, "md5"); } PlexUserRole role = context.PlexUserRoles.FirstOrDefault(x => x.CharacterId == CharacterIdLabel.Text.ToInt()); SetPermission(context, role, SuperAdminCheckBox.Checked, "Super"); SetPermission(context, role, AdministratorCheckBox.Checked, "Admin"); SetPermission(context, role, AllianceCheckBox.Checked, "Alliance"); SetPermission(context, role, CorporationCheckBox.Checked, "Corporation"); context.SubmitChanges(); } Response.Redirect(string.Format("{0}?{1}=1", PageReferrer.Page_Admin_Users, Origin)); }
public PlexServerConnection(IRestConnection restConnection, string uri, PlexUser user = null) : this(restConnection) { User = user; ConnectionUri = TidyUrl(uri); }
public PlexServerConnection(IRestConnection restConnection, Device device, PlexUser user = null) : this(restConnection) { User = user; Device = device; }
partial void DeletePlexUser(PlexUser instance);
partial void UpdatePlexUser(PlexUser instance);
partial void InsertPlexUser(PlexUser instance);
public async Task <T> MakeRequestAsync <T>(Method method, string baseUrl, string resource = "/", string username = null, string password = null, int timeout = 5000, PlexUser user = null) where T : class, new() { using (var clientHandler = new HttpClientHandler { UseCookies = false }) { if (user == null && !string.IsNullOrEmpty(username)) { clientHandler.Credentials = new NetworkCredential(username, password); } using (var client = new HttpClient(clientHandler)) { try { client.BaseAddress = new Uri(baseUrl); client.Timeout = new TimeSpan(0, 0, 0, 0, timeout); CreatePlexRequest(client.DefaultRequestHeaders, user); var requestUri = new Uri(resource, UriKind.Relative); switch (method) { case Method.Get: var responseBody = await client.GetStringAsync(requestUri); if (string.IsNullOrEmpty(responseBody)) { return(null); } return(DeserializeResponse <T>(responseBody)); case Method.Post: var response = await client.PostAsync(requestUri, new StringContent(string.Empty)); response.EnsureSuccessStatusCode(); var postResponseBody = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(postResponseBody)) { return(null); } return(DeserializeResponse <T>(postResponseBody)); } return(null); } catch (Exception ex) { return(null); } } } }
private void CreateUser(PlexingFleetDataContext context, bool newCorp) { PlexUser user = context.PlexUsers.FirstOrDefault(x => x.CharacterId == CharacterId); if (user == null) { user = new PlexUser() { CharacterId = this.CharacterId, CharacterName = this.CharacterName, AllianceId = this.AllianceId, CorpId = this.CorpId, AllianceName = this.AllianceName, CorpName = this.CorpName, Password = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordTextBox.Text.Trim(), "md5"), Enabled = true }; context.PlexUsers.InsertOnSubmit(user); if (newCorp) { PlexUserRole role = new PlexUserRole() { CharacterId = this.CharacterId, Roles = "Corporation" }; context.PlexUserRoles.InsertOnSubmit(role); } } else { //Only do this if the user enabled. if (user.Enabled) { user.AllianceId = this.AllianceId; user.CorpId = this.CorpId; user.AllianceName = this.AllianceName; user.CorpName = this.CorpName; if (newCorp) { var userRoles = context.PlexUserRoles.FirstOrDefault(x => x.CharacterId == CharacterId); //If no roles were found then add the one registring the corp admin rights for that corp. if (userRoles == null) { PlexUserRole role = new PlexUserRole(); role.CharacterId = CharacterId; role.Roles = "Corporation"; context.PlexUserRoles.InsertOnSubmit(role); } else { //Only add the corporation role if it is missing. if (!userRoles.Roles.Contains("Corporation")) { userRoles.Roles += ",Corporation"; } } } } else { user.AllianceId = this.AllianceId; user.CorpId = this.CorpId; user.AllianceName = this.AllianceName; user.CorpName = this.CorpName; } } context.SubmitChanges(); }