public void ReturnsLogout() { var options = new StuntmanOptions(); var html = new UserPicker(options).GetHtml(new TestPrincipal(), "https://return-url"); Assert.Contains("Logout", html); }
public void ReturnsExpectedNumberOfTotalItems() { var options = new StuntmanOptions() .AddUser(new StuntmanUser("user-1", "User 1")); var html = new UserPicker(options).GetHtml(new TestPrincipal(), "https://return-url"); Assert.Equal(2, Regex.Matches(html, "<li.*?>", RegexOptions.Multiline).Count); }
public void ReturnsExpectedNumberOfTotalItems() { var options = new StuntmanOptions() .AddUser(new StuntmanUser("user-1", "User 1")); var html = new UserPicker(options).GetHtml(new TestPrincipal(), "https://return-url"); Assert.Equal(2, Regex.Matches(html, "<li.*>", RegexOptions.Multiline).Count); }
public void ReturnsExpectedItemFormat() { var options = new StuntmanOptions() .AddUser(new StuntmanUser("user-1", "User 1")); var returnUrl = "https://return-url"; var html = new UserPicker(options).GetHtml(new TestPrincipal(), returnUrl); Assert.Contains( $"/stuntman/{Constants.StuntmanOptions.SignInEndpoint}?{Constants.StuntmanOptions.OverrideQueryStringKey}=user-1&{Constants.StuntmanOptions.ReturnUrlQueryStringKey}={WebUtility.UrlEncode(returnUrl)}", html); }
public void ReturnsUsers() { var options = new StuntmanOptions() .AddUser(new StuntmanUser("user-1", "User 1")) .AddUser(new StuntmanUser("user-2", "User 2")); var html = new UserPicker(options).GetHtml(new TestPrincipal(), "https://return-url"); Assert.Contains("user-1", html); Assert.Contains("User 1", html); Assert.Contains("user-2", html); Assert.Contains("User 2", html); }
private void OnAdClick(object sender, EventArgs e) { DirectoryObject[] users = UserPicker.ShowUserObjectPicker(this); if (users != null) { foreach (var user in users) { Property.Value = user.Sid; buttonAdSelect.Text = user.Name; break; } } }
public async void OnSelectUser(object sender, RoutedEventArgs args) { if (UserPicker.IsSupported()) { var picker = new UserPicker { AllowGuestAccounts = true }; var user = await picker.PickSingleUserAsync(); var profileImage = await user.GetPictureAsync(UserPictureSize.Size424x424); } }
public void ReturnsExpectedReturnUrls() { var options = new StuntmanOptions() .AddUser(new StuntmanUser("user-1", "User 1")) .AddUser(new StuntmanUser("user-2", "User 2")); var returnUrl = "https://return-url/test"; var html = new UserPicker(options).GetHtml(new TestPrincipal(), returnUrl); var matches = Regex.Matches(html, WebUtility.UrlEncode(Regex.Escape(returnUrl))); // 2 Stuntman users + 1 logout = 3 total Assert.Equal(3, matches.Count); }
private bool IsMultiUserApplication() { if (isSupported == null) { try { bool APIExist = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.System.UserPicker", "IsSupported"); isSupported = (APIExist && UserPicker.IsSupported()) ? true : false; } catch (Exception) { isSupported = false; } } return(isSupported == true); }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // Because a form can have its data-context (= workitem data that is linked to it) changed multiple times, we set a flag after the first execution to prevent our code from firing more than once. if (flag == false) { // Find the tab-control of our form (it is important when adding our custom usercontrol in the MP XML to use a parent that is in the general tabcontrol) DependencyObject doTabControl = GetParentDependancyObject(this, "Microsoft.EnterpriseManagement.ServiceManager.Applications.ProblemManagement.Forms.GeneralTabControl"); GeneralTabControl tabitem_general = (GeneralTabControl)doTabControl; // Get the existing assigned-to field, and get its parent container, which is a stackpanel. A stackpanel adds controls right after another, so is ideal for adding extra controls without worrying too much about layout. UserPicker userPicker = (UserPicker)tabitem_general.FindName("AssignedToUserPicker"); System.Windows.Controls.StackPanel parent = (System.Windows.Controls.StackPanel)userPicker.Parent; // Define the extra controls and bind them to the data lp = new ListPicker(new Guid("e24ffbc7-78fd-a2da-e4b1-32312a8035ce")); myBinding = new Binding(); myBinding.Source = this.DataContext as IDataItem; myBinding.Path = new PropertyPath("SupportGroup"); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; lp.Name = "SupportGroupListPicker"; lp.Width = Double.NaN; // AUTO lp.Height = Double.NaN; // AUTO lp.HorizontalAlignment = HorizontalAlignment.Stretch; lp.VerticalAlignment = VerticalAlignment.Center; Label lbl = new Label(); lbl.HorizontalAlignment = HorizontalAlignment.Left; lbl.VerticalAlignment = VerticalAlignment.Center; lbl.Content = "Support Group:"; // Add the controls to the stackpanel parent.Children.Add(lbl); parent.Children.Add(lp); flag = true; } // Update the binding when data is changed else { myBinding = new Binding(); myBinding.Source = this.DataContext as IDataItem; myBinding.Path = new PropertyPath("SupportGroup"); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; lp.SetBinding(ListPicker.SelectedItemProperty, myBinding); } }
private async void ShowUserPicker(object sender, RoutedEventArgs e) { var availableUsers = new List <User>(); using (var connection = new SqlConnection(Helpers.FunctionsAndInterfaces.connectionString)) { connection.Open(); var query = $"SELECT UserID, Name, Surname, Email FROM Users WHERE UserID != {currentUserId};"; using (var command = new SqlCommand(query, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { availableUsers.Add(new User { UserID = reader.GetInt32(0), Name = reader.GetString(1), Surname = reader.GetString(2), Email = reader.GetString(3) }); } } } connection.Close(); } if (availableUsers.Count < 1) { currentUserId = -1; } else { UserSelectList.ItemsSource = availableUsers; await UserPicker.ShowAsync(); } }
private Control GetVariableEditor(IDictionary variable) { var value = variable["Value"]; var name = (string)variable["Name"]; var editor = variable["Editor"] as string; var type = value.GetType(); if (type == typeof(DateTime) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("date", StringComparison.OrdinalIgnoreCase) > -1 || editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1))) { var dateTimePicker = new DateTimePicker { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), ShowTime = (variable["ShowTime"] != null && (bool)variable["ShowTime"]) || (!string.IsNullOrEmpty(editor) && editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1) }; if (value is DateTime) { var date = (DateTime)value; if (date != DateTime.MinValue && date != DateTime.MaxValue) { dateTimePicker.Value = date.Kind != DateTimeKind.Utc ? DateUtil.ToIsoDate(TypeResolver.Resolve <IDateConverter>().ToServerTime(date)) : DateUtil.ToIsoDate(date); } } else { dateTimePicker.Value = value as string ?? string.Empty; } return(dateTimePicker); } if (!string.IsNullOrEmpty(editor) && editor.IndexOf("rule", StringComparison.OrdinalIgnoreCase) > -1) { var editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); Sitecore.Context.ClientPage.ServerProperties[editorId] = value; var rulesBorder = new Border { Class = "rulesWrapper", ID = editorId }; var rulesEditButton = new Button { Header = Texts.PowerShellMultiValuePrompt_GetVariableEditor_Edit_rule, Class = "scButton edit-button rules-edit-button", Click = "EditConditionClick(\\\"" + editorId + "\\\")" }; rulesBorder.Controls.Add(rulesEditButton); var rulesRender = new Literal { ID = editorId + "_renderer", Text = GetRuleConditionsHtml( string.IsNullOrEmpty(value as string) ? "<ruleset />" : value as string) }; rulesRender.Class = rulesRender.Class + " varRule"; rulesBorder.Controls.Add(rulesRender); return(rulesBorder); } if (!string.IsNullOrEmpty(editor) && (editor.IndexOf("treelist", StringComparison.OrdinalIgnoreCase) > -1 || (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) || (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1) || (editor.IndexOf("droptree", StringComparison.OrdinalIgnoreCase) > -1))) { Item item = null; var strValue = string.Empty; if (value is Item) { item = (Item)value; strValue = item.ID.ToString(); } else if (value is IEnumerable <object> ) { var items = (value as IEnumerable <object>).Cast <Item>().ToList(); item = items.FirstOrDefault(); strValue = string.Join("|", items.Select(i => i.ID.ToString()).ToArray()); } var dbName = item == null ? Sitecore.Context.ContentDatabase.Name : item.Database.Name; if (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) { var multiList = new MultilistExtended { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = strValue, Database = dbName, ItemID = ItemIDs.RootID.ToString(), Source = variable["Source"] as string ?? "/sitecore", }; multiList.SetLanguage(Sitecore.Context.Language.Name); multiList.Class += " treePicker"; return(multiList); } if (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1) { if (Sitecore.Context.ContentDatabase?.Name != dbName) { // this control will crash if if content database is different than the items fed to it. return(new Literal { Text = "<span style='color: red'>" + Translate.Text( Texts .PowerShellMultiValuePrompt_GetVariableEditor_DropList_control_cannot_render_items_from_the_database___0___because_it_its_not_the_same_as___1___which_is_the_current_content_database__, dbName, Sitecore.Context.ContentDatabase?.Name) + "</span>", Class = "varHint" }); } var lookup = new LookupEx { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Database = dbName, ItemID = item?.ID.ToString() ?? ItemIDs.RootID.ToString(), Source = variable["Source"] as string ?? "/sitecore", ItemLanguage = Sitecore.Context.Language.Name, Value = item?.ID.ToString() ?? ItemIDs.RootID.ToString() }; lookup.Class += " textEdit"; return(lookup); } if (editor.IndexOf("droptree", StringComparison.OrdinalIgnoreCase) > -1) { var tree = new Tree { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Database = dbName, ItemID = item?.ID.ToString() ?? ItemIDs.Null.ToString(), Source = variable["Source"] as string ?? "", ItemLanguage = Sitecore.Context.Language.Name, Value = item?.ID.ToString() ?? "" }; tree.Class += " textEdit"; return(tree); } var treeList = new TreeList { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = strValue, AllowMultipleSelection = true, DatabaseName = dbName, Database = dbName, Source = variable["Source"] as string ?? "/sitecore", DisplayFieldName = variable["DisplayFieldName"] as string ?? "__DisplayName" }; treeList.Class += " treePicker"; return(treeList); } if (type == typeof(Item) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("item", StringComparison.OrdinalIgnoreCase) > -1))) { var item = value as Item; var source = variable["Source"] as string; var root = variable["Root"] as string; var sourceRoot = string.IsNullOrEmpty(source) ? "/sitecore" : StringUtil.ExtractParameter("DataSource", source); var dataContext = item != null ? new DataContext { DefaultItem = item.Paths.Path, ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"), Parameters = string.IsNullOrEmpty(source) ? "databasename=" + item.Database.Name : source, DataViewName = "Master", Root = string.IsNullOrEmpty(root) ? sourceRoot : root, Database = item.Database.Name, Selected = new[] { new DataUri(item.ID, item.Language, item.Version) }, Folder = item.ID.ToString(), Language = item.Language, Version = item.Version } : new DataContext { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"), Parameters = string.IsNullOrEmpty(source) ? "databasename=master" : source, DataViewName = "Master", Root = string.IsNullOrEmpty(root) ? sourceRoot : root }; DataContextPanel.Controls.Add(dataContext); var treePicker = new TreePicker { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = item != null?item.ID.ToString() : string.Empty, DataContext = dataContext.ID, AllowNone = !string.IsNullOrEmpty(editor) && (editor.IndexOf("allownone", StringComparison.OrdinalIgnoreCase) > -1) }; treePicker.Class += " treePicker"; return(treePicker); } if (type == typeof(bool) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1))) { var checkboxBorder = new Border { Class = "checkBoxWrapper", ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_") }; var checkBox = new Checkbox { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Header = (string)variable["Title"], HeaderStyle = "display:inline-block;", Checked = (bool)value, Class = "varCheckbox" }; checkboxBorder.Controls.Add(checkBox); return(checkboxBorder); } if (!string.IsNullOrEmpty(editor)) { var showRoles = editor.IndexOf("role", StringComparison.OrdinalIgnoreCase) > -1; var showUsers = editor.IndexOf("user", StringComparison.OrdinalIgnoreCase) > -1; var multiple = editor.IndexOf("multiple", StringComparison.OrdinalIgnoreCase) > -1; if (showRoles || showUsers) { var picker = new UserPicker(); picker.Style.Add("float", "left"); picker.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); picker.Class += " scContentControl textEdit clr" + value.GetType().Name; picker.Value = value is IEnumerable <object> ?string.Join("|", ((IEnumerable <object>)value).Select(x => x.ToString()).ToArray()) : value.ToString(); picker.ExcludeRoles = !showRoles; picker.ExcludeUsers = !showUsers; picker.DomainName = variable["Domain"] as string ?? variable["DomainName"] as string; picker.Multiple = multiple; picker.Click = "UserPickerClick(" + picker.ID + ")"; return(picker); } } Sitecore.Web.UI.HtmlControls.Control edit; if (!string.IsNullOrEmpty(editor) && editor.IndexOf("info", StringComparison.OrdinalIgnoreCase) > -1) { return(new Literal { Text = value.ToString(), Class = "varHint" }); } if (variable["lines"] != null && ((int)variable["lines"] > 1)) { edit = new Memo(); edit.Attributes.Add("rows", variable["lines"].ToString()); var placeholder = variable["Placeholder"]; if (placeholder is string) { edit.Attributes.Add("Placeholder", placeholder.ToString()); } } else if (variable["Options"] != null) { var psOptions = variable["Options"].BaseObject(); var options = new OrderedDictionary(); if (psOptions is OrderedDictionary) { options = psOptions as OrderedDictionary; } else if (psOptions is string) { var strOptions = ((string)variable["Options"]).Split('|'); var i = 0; while (i < strOptions.Length) { options.Add(strOptions[i++], strOptions[i++]); } } else if (psOptions is Hashtable) { var hashOptions = variable["Options"] as Hashtable; foreach (var key in hashOptions.Keys) { options.Add(key, hashOptions[key]); } } else { throw new Exception("Checklist options format unrecognized."); } if (!string.IsNullOrEmpty(editor)) { if (editor.IndexOf("radio", StringComparison.OrdinalIgnoreCase) > -1) { var radioList = new Groupbox { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), // Header = (string) variable["Title"], Class = "scRadioGroup" }; foreach (var option in options.Keys) { var optionName = option.ToString(); var optionValue = options[optionName].ToString(); var item = new Radiobutton { Header = optionName, Value = optionValue, ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(radioList.ID), Name = radioList.ID, Checked = optionValue == value.ToString() }; radioList.Controls.Add(item); radioList.Controls.Add(new Literal("<br/>")); } return(radioList); } if (editor.IndexOf("check", StringComparison.OrdinalIgnoreCase) > -1) { var checkBorder = new Border { Class = "checkListWrapper", ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_") }; var editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); var link = new Literal( @"<div class='checkListActions'>" + @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:checkall(id=" + editorId + @")')"">" + Translate.Text("Select all") + "</a> | " + @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:uncheckall(id=" + editorId + @")')"">" + Translate.Text("Unselect all") + "</a> | " + @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:invert(id=" + editorId + @")')"">" + Translate.Text("Invert selection") + "</a>" + @"</div>"); checkBorder.Controls.Add(link); var checkList = new PSCheckList { ID = editorId, HeaderStyle = "margin-top:20px; display:inline-block;", ItemID = ItemIDs.RootID.ToString() }; checkList.SetItemLanguage(Sitecore.Context.Language.Name); string[] values; if (value is string) { values = value.ToString().Split('|'); } else if (value is IEnumerable) { values = (value as IEnumerable).Cast <object>() .Select(s => s == null ? "" : s.ToString()) .ToArray(); } else { values = new[] { value.ToString() }; } foreach (var item in from object option in options.Keys select option.ToString() into optionName let optionValue = options[optionName].ToString() select new ChecklistItem { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(checkList.ID), Header = optionName, Value = optionValue, Checked = values.Contains(optionValue, StringComparer.OrdinalIgnoreCase) }) { checkList.Controls.Add(item); } checkList.TrackModified = false; checkList.Disabled = false; checkBorder.Controls.Add(checkList); return(checkBorder); } } edit = new Combobox(); var placeholder = variable["Placeholder"]; if (placeholder is string) { var option = new ListItem { Header = placeholder.ToString(), Value = "", Selected = true }; edit.Controls.Add(option); } foreach (var option in options.Keys) { var optionName = option.ToString(); var optionValue = options[optionName].ToString(); var item = new ListItem { Header = optionName, Value = optionValue }; edit.Controls.Add(item); } } else { var placeholder = variable["Placeholder"]; if (!string.IsNullOrEmpty(editor) && editor.IndexOf("pass", StringComparison.OrdinalIgnoreCase) > -1) { edit = new PasswordExtended(); if (placeholder is string) { ((PasswordExtended)edit).PlaceholderText = placeholder.ToString(); } } else { edit = new EditExtended(); if (placeholder is string) { ((EditExtended)edit).PlaceholderText = placeholder.ToString(); } } } var tip = variable["Tooltip"] as string; if (!string.IsNullOrEmpty(tip)) { edit.ToolTip = tip.RemoveHtmlTags(); } edit.Style.Add("float", "left"); edit.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); edit.Class += " scContentControl textEdit clr" + value.GetType().Name; edit.Value = value.ToString(); return(edit); }
public void Configuration(IAppBuilder app) { var options = new StuntmanOptions() .AddUser(new StuntmanUser("user-1", "User 1") .SetAccessToken("user-1-token") .AddClaim("given_name", "John") .AddClaim("family_name", "Doe")) .AddUser(new StuntmanUser("user-2", "User 2") .AddClaim("given_name", "Jane") .AddClaim("family_name", "Doe")) .AddUser(new StuntmanUser("user-3", "User 3") .AddClaim("given_name", "Sam") .AddClaim("family_name", "Smith")); if (System.Web.HttpContext.Current.IsDebuggingEnabled) { app.UseStuntman(options); } var userPicker = new UserPicker(options); app.Map("/secure", secure => { AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" }); secure.Run(context => { var userName = context.Request.User.Identity.Name; if (string.IsNullOrEmpty(userName)) { userName = "******"; } context.Response.ContentType = "text/html"; context.Response.WriteAsync(string.Format( "Hello, {0}. This is the /secure endpoint.", userName)); if (System.Web.HttpContext.Current.IsDebuggingEnabled) { context.Response.WriteAsync( userPicker.GetHtml(context.Request.User, context.Request.Uri.AbsoluteUri)); } return(Task.FromResult(true)); }); }); app.Map("/logout", logout => { logout.Run(context => { context.Authentication.SignOut(); return(Task.FromResult(true)); }); }); app.Map("", nonSecure => { nonSecure.Run(context => { var userName = context.Request.User.Identity.Name; if (string.IsNullOrEmpty(userName)) { userName = "******"; } context.Response.ContentType = "text/html"; context.Response.WriteAsync(string.Format( "Hello, {0}.", userName)); if (System.Web.HttpContext.Current.IsDebuggingEnabled) { context.Response.WriteAsync( userPicker.GetHtml(context.Request.User, context.Request.Uri.AbsoluteUri)); } return(Task.FromResult(true)); }); }); }