/// <summary> /// Gets the display name of the user. /// </summary> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static string GetUserDisplayName(string userName) { if (string.IsNullOrEmpty(userName)) { throw new ArgumentNullException("userName"); } var displayName = new WebProfile().GetProfile(userName).DisplayName; return(!string.IsNullOrEmpty(displayName) ? displayName : userName); }
/// <summary> /// Binds a data source to the invoked server control and all its child controls. /// </summary> public override void DataBind() { //get this user and bind the data MembershipUser user = UserManager.GetUser(UserId); if (user != null) { lblUserName.Text = user.UserName; WebProfile Profile = new WebProfile().GetProfile(user.UserName); FirstName.Text = Profile.FirstName; LastName.Text = Profile.LastName; DisplayName.Text = Profile.DisplayName; //Fax.Text = Profile.ContactInfo.Fax; //Mobile.Text = Profile.ContactInfo.Mobile; //Telephone.Text = Profile.ContactInfo.Telephone; } }
/// <summary> /// Handles the Click event of the Submit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Submit_Click(object sender, EventArgs e) { if (Page.IsValid) { // get the user by the reset token var token = Request.QueryString["token"]; if (!string.IsNullOrWhiteSpace(token)) { var user = UserManager.GetUserByPasswordResetToken(token); if (user != null) { try { // update the users password to the new password provided user.ChangePassword(user.ResetPassword(), Password.Text.Trim()); // update profile to clear the reset token and date var profile = new WebProfile().GetProfile(user.UserName); profile.PasswordVerificationToken = null; profile.PasswordVerificationTokenExpirationDate = null; profile.Save(); Response.Redirect("~/Account/PasswordResetSuccess.aspx"); } catch (System.Web.Security.MembershipPasswordException ex) { Message = ex.Message; message.Visible = !String.IsNullOrEmpty(Message); } } else { Message = GetLocalResourceObject("InvalidTokenMessage").ToString(); message.Visible = !String.IsNullOrEmpty(Message); } } else { Message = GetLocalResourceObject("InvalidTokenMessage").ToString(); message.Visible = !String.IsNullOrEmpty(Message); } } }
/// <summary> /// Handles the Click event of the SubmitButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void SubmitButton_Click(object sender, EventArgs e) { if(Page.IsValid) { var user = Membership.GetUser(UserName.Text.Trim()); if (user != null && user.IsApproved) { var profile = new WebProfile().GetProfile(UserName.Text.Trim()); string token = GenerateToken(); profile.PasswordVerificationToken = token; profile.PasswordVerificationTokenExpirationDate = DateTime.Now.AddMinutes(1440); profile.Save(); // Email the user the password reset token UserManager.SendForgotPasswordEmail(user, token); } forgotPassword.Visible = false; successMessage.Visible = true; } }
protected void RegisterUser_CreatedUser(object sender, EventArgs e) { string continueUrl = RegisterUser.ContinueDestinationPageUrl; if (!OpenAuth.IsLocalUrl(continueUrl)) { continueUrl = "~/"; } var user = UserManager.GetUser(RegisterUser.UserName); var profile = new WebProfile().GetProfile(user.UserName); var displayName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayName"); var firstName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"); var lastName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName"); profile.DisplayName = displayName.Text; profile.FirstName = firstName.Text; profile.LastName = lastName.Text; profile.Save(); // add users to all auto assigned roles var roles = RoleManager.GetAll(); foreach (var r in roles.Where(r => r.AutoAssign)) { RoleManager.AddUser(user.UserName, r.Id); } //send notification this user was created UserManager.SendUserRegisteredNotification(user.UserName); // send user verification email if enabled if (HostSettingManager.Get(HostSettingNames.UserRegistration, (int)UserRegistration.Verified) == (int)UserRegistration.Verified) { UserManager.SendUserVerificationNotification(user); } else { Response.Redirect(continueUrl); } }
/// <summary> /// Handles the Click event of the cmdUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void cmdUpdate_Click(object sender, EventArgs e) { try { MembershipUser user = UserManager.GetUser(UserId); if (user != null) { WebProfile Profile = new WebProfile().GetProfile(user.UserName); Profile.DisplayName = DisplayName.Text; Profile.FirstName = FirstName.Text; Profile.LastName = LastName.Text; //Profile.ContactInfo.Fax = Fax.Text; //Profile.ContactInfo.Mobile = Mobile.Text; //Profile.ContactInfo.Telephone = Telephone.Text; Profile.Save(); } } catch { lblError.Text = LoggingManager.GetErrorMessageResource("ProfileUpdateError"); } }
/// <summary> /// Handles the CreatedUser event of the CreateUserWizard1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { string userName = CreateUserWizard1.UserName; MembershipUser user = UserManager.GetUser(userName); if (user != null) { TextBox FirstName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("FirstName"); TextBox LastName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("LastName"); TextBox FullName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("FullName"); WebProfile Profile = new WebProfile().GetProfile(user.UserName); Profile.FirstName = FirstName.Text; Profile.LastName = LastName.Text; Profile.DisplayName = FullName.Text; Profile.Save(); //auto assign user to roles List<Role> roles = RoleManager.GetAll(); foreach (Role r in roles) { if (r.AutoAssign) RoleManager.AddUser(user.UserName, r.Id); } if (Convert.ToBoolean(HostSettingManager.Get(HostSettingNames.UserRegistration,(int)Globals.UserRegistration.Verified))) { UserManager.SendUserVerificationNotification(user); } //send notification this user was created UserManager.SendUserRegisteredNotification(user.UserName); } }
/// <summary> /// Determines whether [is notification type enabled] [the specified username]. /// </summary> /// <param name="username">The username.</param> /// <param name="notificationType">Type of the notification.</param> /// <returns> /// <c>true</c> if [is notification type enabled] [the specified username]; otherwise, <c>false</c>. /// </returns> public static bool IsNotificationTypeEnabled(string username, string notificationType) { if (string.IsNullOrEmpty(username)) throw new ArgumentNullException("username"); if (string.IsNullOrEmpty(notificationType)) throw new ArgumentNullException("notificationType"); var profile = new WebProfile().GetProfile(username); if (profile != null) { var notificationTypes = profile.NotificationTypes.Split(';'); return notificationTypes.Any(s => s.Equals(notificationType)); } return false; }
/// <summary> /// Gets the display name of the user. /// </summary> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static string GetUserDisplayName(string userName) { if (string.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName"); var displayName = new WebProfile().GetProfile(userName).DisplayName; return !string.IsNullOrEmpty(displayName) ? displayName : userName; }
/// <summary> /// Installs the bug NET. /// </summary> /// <returns></returns> private bool InstallBugNET() { try { string providerPath = UpgradeManager.GetProviderPath(); if (!providerPath.StartsWith("ERROR")) { WriteMessage(string.Format("Installing Version: {0}<br/>", UpgradeManager.GetCurrentVersion()), 0, true); WriteMessage("Installing Membership Provider:<br/>", 0, true); ExecuteSqlInFile(string.Format("{0}InstallCommon.sql",providerPath)); ExecuteSqlInFile(string.Format("{0}InstallMembership.sql",providerPath)); ExecuteSqlInFile(string.Format("{0}InstallProfile.sql",providerPath)); ExecuteSqlInFile(string.Format("{0}InstallRoles.sql",providerPath)); WriteMessage("Installing BugNET Database:<br/>", 0, true); ExecuteSqlInFile(string.Format("{0}BugNET.Schema.SqlDataProvider.sql",providerPath)); WriteMessage("Installing BugNET Default Data:<br/>", 0, true); ExecuteSqlInFile(string.Format("{0}BugNET.Data.SqlDataProvider.sql",providerPath)); WriteMessage("Creating Administrator Account", 0, true); //create admin user MembershipCreateStatus status = MembershipCreateStatus.Success; MembershipUser NewUser = Membership.CreateUser("Admin", "password", "*****@*****.**", "no question", "no answer", true, out status); if (NewUser != null) { //add the admin user to the Super Users role. RoleManager.AddUser("Admin", 1); //add user profile information WebProfile Profile = new WebProfile().GetProfile("Admin"); Profile.FirstName = "Admin"; Profile.LastName = "Admin"; Profile.DisplayName = "Administrator"; Profile.Save(); } WriteScriptSuccessError(true); UpgradeManager.UpdateDatabaseVersion(UpgradeManager.GetCurrentVersion()); } else { //upgrade error Response.Write("<h2>Upgrade Error: " + providerPath + "</h2>"); return false; } } catch (Exception e) { WriteErrorMessage(e.Message); return false; } return true; }
/// <summary> /// Handles the AuthenticateRequest event of the context control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> void context_AuthenticateRequest(object sender, EventArgs e) { //check if we are upgrading/installing if (HttpContext.Current.Request.Url.LocalPath.ToLower().EndsWith("install.aspx")) return; //get host settings bool enabled = HostSettingManager.Get(HostSettingNames.UserAccountSource) == "ActiveDirectory" || HostSettingManager.Get(HostSettingNames.UserAccountSource) == "WindowsSAM"; //check if windows authentication is enabled in the host settings if (enabled) { if (System.Web.HttpContext.Current.User != null) MDC.Set("user", System.Web.HttpContext.Current.User.Identity.Name); // This was moved from outside "if enabled" to only happen when we need it. HttpRequest request = HttpContext.Current.Request; // not needed to be removed // HttpResponse response = HttpContext.Current.Response; if (request.IsAuthenticated) { if ((HttpContext.Current.User.Identity.AuthenticationType == "NTLM" || HttpContext.Current.User.Identity.AuthenticationType == "Negotiate")) { //check if the user exists in the database MembershipUser user = UserManager.GetUser(HttpContext.Current.User.Identity.Name); if (user == null) { try { UserProperties userprop = GetUserProperties(HttpContext.Current.User.Identity.Name); MembershipUser mu = null; MembershipCreateStatus createStatus = MembershipCreateStatus.Success; //create a new user with the current identity and a random password. if (Membership.RequiresQuestionAndAnswer) mu = Membership.CreateUser(HttpContext.Current.User.Identity.Name, Membership.GeneratePassword(7, 2), userprop.Email, "WindowsAuth", "WindowsAuth", true, out createStatus); else mu = Membership.CreateUser(HttpContext.Current.User.Identity.Name, Membership.GeneratePassword(7, 2), userprop.Email); if (createStatus == MembershipCreateStatus.Success && mu != null) { WebProfile Profile = new WebProfile().GetProfile(HttpContext.Current.User.Identity.Name); if (!string.IsNullOrWhiteSpace(userprop.DisplayName)) Profile.DisplayName = userprop.DisplayName; else Profile.DisplayName = String.Format("{0} {1}", userprop.FirstName, userprop.LastName); Profile.FirstName = userprop.FirstName; Profile.LastName = userprop.LastName; Profile.Save(); //auto assign user to roles List<Role> roles = RoleManager.GetAll().FindAll(r => r.AutoAssign == true); foreach (Role r in roles) RoleManager.AddUser(mu.UserName, r.Id); } user = Membership.GetUser(HttpContext.Current.User.Identity.Name); } catch (Exception ex) { if (Log.IsErrorEnabled) Log.Error(String.Format("Unable to add new user '{0}' to BugNET application. Authentication Type='{1}'.", HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.AuthenticationType), ex); } } else { //update the user's last login date. user.LastLoginDate = DateTime.Now; Membership.UpdateUser(user); } } } } }
/// <summary> /// Creates the syndication items from issue list. /// </summary> /// <param name="issueList">The issue list.</param> /// <returns></returns> private IEnumerable<SyndicationItem> CreateSyndicationItemsFromIssueList(IEnumerable<Issue> issueList) { var feedItems = new List<SyndicationItem>(); foreach (Issue issue in issueList.Take(maxItemsInFeed)) { // Atom items MUST have an author, so if there are no authors for this content item then go to next item in loop //if (outputAtom && t.TitleAuthors.Count == 0) // continue; var item = new SyndicationItem { Title = SyndicationContent.CreatePlaintextContent(string.Format("{0} - {1}", issue.FullId, issue.Title)) }; item.Links.Add( SyndicationLink.CreateAlternateLink( new Uri( GetFullyQualifiedUrl(string.Format("~/Issues/IssueDetail.aspx?id={0}", issue.Id))))); item.Summary = SyndicationContent.CreatePlaintextContent(issue.Description); item.Categories.Add(new SyndicationCategory(issue.CategoryName)); item.PublishDate = issue.DateCreated; // Add a custom element. var doc = new XmlDocument(); var itemElement = doc.CreateElement("milestone"); itemElement.InnerText = issue.MilestoneName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("project"); itemElement.InnerText = issue.ProjectName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("issueType"); itemElement.InnerText = issue.IssueTypeName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("priority"); itemElement.InnerText = issue.PriorityName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("status"); itemElement.InnerText = issue.StatusName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("resolution"); itemElement.InnerText = issue.ResolutionName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("assignedTo"); itemElement.InnerText = issue.AssignedDisplayName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("owner"); itemElement.InnerText = issue.OwnerDisplayName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("dueDate"); itemElement.InnerText = issue.DueDate.ToShortDateString(); item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("progress"); itemElement.InnerText = issue.Progress.ToString(); item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("estimation"); itemElement.InnerText = issue.Estimation.ToString(); item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("lastUpdated"); itemElement.InnerText = issue.LastUpdate.ToShortDateString(); item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("lastUpdateBy"); itemElement.InnerText = issue.LastUpdateDisplayName; item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("created"); itemElement.InnerText = issue.DateCreated.ToShortDateString(); item.ElementExtensions.Add(itemElement); itemElement = doc.CreateElement("createdBy"); itemElement.InnerText = issue.CreatorDisplayName; item.ElementExtensions.Add(itemElement); //foreach (TitleAuthor ta in t.TitleAuthors) //{ // SyndicationPerson authInfo = new SyndicationPerson(); // authInfo.Email = ta.Author.au_lname + "@example.com"; // authInfo.Name = ta.Author.au_fullname; // item.Authors.Add(authInfo); // // RSS feeds can only have one author, so quit loop after first author has been added // if (outputRss) // break; //} var profile = new WebProfile().GetProfile(issue.CreatorUserName); var authInfo = new SyndicationPerson {Name = profile.DisplayName}; //authInfo.Email = Membership.GetUser(IssueCreatorUserId).Email; item.Authors.Add(authInfo); // Add the item to the feed feedItems.Add(item); } return feedItems; }
/// <summary> /// Installs the BugNET. /// </summary> /// <returns></returns> private bool InstallBugNET() { try { var providerPath = UpgradeManager.GetProviderPath(); if (!providerPath.StartsWith("ERROR")) { WriteMessage(string.Format("Installing Version: {0}<br/>", UpgradeManager.GetCurrentVersion()), 0, true); WriteMessage("Installing BugNET Database:<br/>", 0, true); ExecuteSqlInFile(string.Format("{0}BugNET.Schema.SqlDataProvider.sql", providerPath)); WriteMessage("Installing BugNET Default Data:<br/>", 0, true); ExecuteSqlInFile(string.Format("{0}BugNET.Data.SqlDataProvider.sql", providerPath)); WriteMessage("Creating Administrator Account<br/>", 0, true); //create admin user MembershipCreateStatus status; var newUser = Membership.CreateUser("Admin", "password", "*****@*****.**", "no question", "no answer", true, out status); switch (status) { case MembershipCreateStatus.Success: WriteMessage("Created Administrator Account", 0, true); WriteScriptSuccessError(true); break; case MembershipCreateStatus.InvalidUserName: case MembershipCreateStatus.InvalidPassword: case MembershipCreateStatus.InvalidQuestion: case MembershipCreateStatus.InvalidAnswer: case MembershipCreateStatus.InvalidEmail: case MembershipCreateStatus.DuplicateUserName: case MembershipCreateStatus.DuplicateEmail: case MembershipCreateStatus.UserRejected: case MembershipCreateStatus.InvalidProviderUserKey: case MembershipCreateStatus.DuplicateProviderUserKey: case MembershipCreateStatus.ProviderError: var message = string.Format("Creating Administrator Account Failed, status returned: {0} <br/>", status); WriteMessage(message, 0, true); break; default: throw new ArgumentOutOfRangeException(); } WriteMessage("Creating Administrator Account default profile <br/>", 0, true); if (status == MembershipCreateStatus.Success) { //add the admin user to the Super Users role. RoleManager.AddUser("Admin", 1); //add user profile information var profile = new WebProfile().GetProfile("Admin"); profile.FirstName = "Admin"; profile.LastName = "Admin"; profile.DisplayName = "Administrator"; profile.PasswordVerificationTokenExpirationDate = null; profile.Save(); WriteMessage("Created Administrator Account default profile", 0, true); WriteScriptSuccessError(true); } else { WriteMessage("Created Administrator Account default profile failed, due to status returned from account creation", 0, true); WriteScriptSuccessError(false); } UpgradeManager.UpdateDatabaseVersion(UpgradeManager.GetCurrentVersion()); } else { //upgrade error Response.Write("<h2>Upgrade Error: " + providerPath + "</h2>"); return false; } } catch (Exception e) { WriteErrorMessage(e.Message); return false; } return true; }
/// <summary> /// Sends the forgot password email. /// </summary> /// <param name="user">The user.</param> /// <param name="token">The token.</param> /// <exception cref="System.ArgumentNullException"> /// user /// or /// user /// </exception> public static void SendForgotPasswordEmail(MembershipUser user, string token) { if (user == null) throw new ArgumentNullException("user"); if (user.ProviderUserKey == null) throw new ArgumentNullException("user"); IMailDeliveryService mailService = new SmtpMailDeliveryService(); var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text); var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML"; const string subjectKey = "ForgotPasswordSubject"; var bodyKey = string.Concat("ForgotPassword", emailFormatKey); var profile = new WebProfile().GetProfile(user.UserName); var nc = new CultureNotificationContent().LoadContent(profile.PreferredLocale, subjectKey, bodyKey); var notificationUser = new NotificationUser { Id = (Guid)user.ProviderUserKey, CreationDate = user.CreationDate, Email = user.Email, UserName = user.UserName, DisplayName = profile.DisplayName, FirstName = profile.FirstName, LastName = profile.LastName, IsApproved = user.IsApproved }; var data = new Dictionary<string, object> { {"Token", token} }; var emailSubject = nc.CultureContents .First(p => p.ContentKey == subjectKey) .FormatContent(); var bodyContent = nc.CultureContents .First(p => p.ContentKey == bodyKey) .TransformContent(data); var message = new MailMessage { Subject = emailSubject, Body = bodyContent, IsBodyHtml = true }; mailService.Send(user.Email, message, null); }
/// <summary> /// Sends the user registered notification. /// </summary> /// <param name="userName">The user.</param> public static void SendUserRegisteredNotification(string userName) { if (userName == "") throw new ArgumentNullException("userName"); var user = GetUser(userName); if (user.ProviderUserKey == null) throw new ArgumentNullException("userName"); // TODO - create this via dependency injection at some point. IMailDeliveryService mailService = new SmtpMailDeliveryService(); var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text); var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML"; const string subjectKey = "UserRegisteredSubject"; var bodyKey = string.Concat("UserRegistered", emailFormatKey); var profile = new WebProfile().GetProfile(user.UserName); var nc = new CultureNotificationContent().LoadContent(profile.PreferredLocale, subjectKey, bodyKey); var notificationUser = new NotificationUser { Id = (Guid)user.ProviderUserKey, CreationDate = user.CreationDate, Email = user.Email, UserName = user.UserName, DisplayName = profile.DisplayName, FirstName = profile.FirstName, LastName = profile.LastName, IsApproved = user.IsApproved }; var data = new Dictionary<string, object> { { "User", notificationUser } }; var emailSubject = nc.CultureContents .First(p => p.ContentKey == subjectKey) .FormatContent(); var bodyContent = nc.CultureContents .First(p => p.ContentKey == bodyKey) .TransformContent(data); var message = new MailMessage { Subject = emailSubject, Body = bodyContent, IsBodyHtml = true }; mailService.Send(user.Email, message, null); }
/// <summary> /// Handles the LoggedIn event of the OpenIdLogin1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DotNetOpenAuth.OpenId.RelyingParty.OpenIdEventArgs"/> instance containing the event data.</param> protected void OpenIdLogin1_LoggedIn(object sender, OpenIdEventArgs e) { try { // Clear previously remembered OpenID state Session["isDoingOpenIDLogin"] = ""; // May 30 2010 // BGN-1356 // // Added by smoss for security. // User shouldnt be able to use this method if OpenID is off. if (!HostSettingManager.Get(HostSettingNames.OpenIdAuthentication, false)) { throw new UnauthorizedAccessException(); } if (e.Response != null) { switch (e.Response.Status) { case AuthenticationStatus.Authenticated: // This is where you would look for any OpenID extension responses included // in the authentication assertion. // var extension = openid.Response.GetExtension<someextensionresponsetype>(); // TODO : check for linked account via user profile settings if Desired // May 31 2010 // WARNING: There is no logging in this method! string email = string.Empty; string alias = string.Empty; string fullname = string.Empty; ClaimsResponse fetch = e.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse; if (fetch != null) { alias = fetch.Nickname; // set size limits email = fetch.Email; // no validation of email fullname = fetch.FullName; // set size limits } if (string.IsNullOrEmpty(alias)) alias = e.Response.ClaimedIdentifier; // Warning: Invalid email address if (string.IsNullOrEmpty(email)) email = e.Response.ClaimedIdentifier; if (string.IsNullOrEmpty(fullname)) fullname = e.Response.ClaimedIdentifier; //Now see if the user already exists, if not create them MembershipUser TestUser = Membership.GetUser(e.Response.ClaimedIdentifier); if (TestUser != null) { // BGN-1867 // Banned users are not allowed to login via OpenID // See if this user is allowed on the system. Also dont allow users // who are still logged in to try and login. if ((!TestUser.IsApproved) || (TestUser.IsLockedOut) || (TestUser.IsOnline)) { loginFailedLabel.Text += " " + GetLocalResourceObject("NotAuthorized.Text").ToString(); loginFailedLabel.Visible = true; e.Cancel = true; break; } } else { // Part of BGN-1860 if (Convert.ToInt32(HostSettingManager.Get(HostSettingNames.UserRegistration)) == (int)Globals.UserRegistration.None) { loginFailedLabel.Text += GetLocalResourceObject("RegistrationDisabled").ToString(); loginFailedLabel.Visible = true; e.Cancel = true; break; // unsecure break should be a return } MembershipCreateStatus membershipCreateStatus; MembershipUser user = Membership.CreateUser(e.Response.ClaimedIdentifier, Membership.GeneratePassword(7, 2), email, GetLocalResourceObject("OpenIDPasswordQuestion").ToString(), Membership.GeneratePassword(12, 4), true, out membershipCreateStatus); if (membershipCreateStatus != MembershipCreateStatus.Success) { loginFailedLabel.Text += GetLocalResourceObject("CreateAccountFailed").ToString() + membershipCreateStatus.ToString(); loginFailedLabel.Visible = true; e.Cancel = true; break;// unsecure break should be a return } //save profile info WebProfile Profile = new WebProfile().GetProfile(user.UserName); Profile.DisplayName = fullname; Profile.Save(); user.Comment = alias; Membership.UpdateUser(user); //auto assign user to roles List<Role> roles = RoleManager.GetAll(); foreach (Role r in roles) { if (r.AutoAssign) RoleManager.AddUser(user.UserName, r.Id); } //send notification this user was created UserManager.SendUserRegisteredNotification(user.UserName); } // NB NB Only do the redirect when e.Cancel != true // There is a very very slim chance this code will be reached with // e.Cancel == true if (e.Cancel == false) { // Use FormsAuthentication to tell ASP.NET that the user is now logged in, // with the OpenID Claimed Identifier as their username. FormsAuthentication.RedirectFromLoginPage(e.Response.ClaimedIdentifier, false); } break; case AuthenticationStatus.Canceled: loginCanceledLabel.Visible = true; e.Cancel = true; break; // unsecure break should be a return // extra enums detected and force a default case // They all mean failures case AuthenticationStatus.Failed: case AuthenticationStatus.ExtensionsOnly: case AuthenticationStatus.SetupRequired: default: loginFailedLabel.Visible = true; e.Cancel = true; break; // unsecure break should be a return } } else { // response is null } } finally { // This finally block covers all the code if (e.Cancel) { // make sure we stay focused on the openid control Session["isDoingOpenIDLogin"] = "******"; } } }
private void MonitoredFeed(ref SyndicationFeed feed) { bool excludeClosedIssues = false; //get feed id if (Request.QueryString["ec"] != null) excludeClosedIssues = Convert.ToBoolean(Request.Params["ec"]); var issueList = IssueManager.GetMonitoredIssuesByUserName(Security.GetUserName(), excludeClosedIssues); var feedItems = CreateSyndicationItemsFromIssueList(issueList); var profile = new WebProfile().GetProfile(Security.GetUserName()); feed.Title = SyndicationContent.CreatePlaintextContent( string.Format(GetLocalResourceObject("MonitoredIssuesTitle").ToString(), profile.DisplayName)); feed.Description = SyndicationContent.CreatePlaintextContent( string.Format(GetLocalResourceObject("MonitoredIssuesDescription").ToString(), profile.DisplayName)); feed.Items = feedItems; }
/// <summary> /// Saves the issue /// </summary> /// <param name="entity">The issue to save.</param> /// <returns></returns> public static bool SaveOrUpdate(Issue entity) { if (entity == null) { throw new ArgumentNullException("entity"); } if (entity.ProjectId <= Globals.NEW_ID) { throw (new ArgumentException("The issue project id is invalid")); } if (string.IsNullOrEmpty(entity.Title)) { throw (new ArgumentException("The issue title cannot be empty or null")); } try { if (entity.Id <= Globals.NEW_ID) { var tempId = DataProviderManager.Provider.CreateNewIssue(entity); if (tempId > 0) { entity.Id = tempId; return(true); } return(false); } // this is here due to issue with updating the issue from the Mailbox reader // to fix the inline images. we don't have an http context so we are limited to what we can // do from here. in any case the mailbox reader is creating and updating concurrently so // we are not missing anything. if (HttpContext.Current != null) { //existing issue entity.LastUpdate = DateTime.Now; entity.LastUpdateUserName = Security.GetUserName(); var issueChanges = GetIssueChanges(GetById(entity.Id), entity); DataProviderManager.Provider.UpdateIssue(entity); UpdateHistory(issueChanges); IssueNotificationManager.SendIssueNotifications(entity.Id, issueChanges); if (entity.SendNewAssigneeNotification) { //add this user to notifications and send them a notification var notification = new IssueNotification { IssueId = entity.Id, NotificationUsername = entity.AssignedUserName, NotificationCulture = string.Empty }; var profile = new WebProfile().GetProfile(entity.AssignedUserName); if (profile != null && !string.IsNullOrWhiteSpace(profile.PreferredLocale)) { notification.NotificationCulture = profile.PreferredLocale; } IssueNotificationManager.SaveOrUpdate(notification); IssueNotificationManager.SendNewAssigneeNotification(notification); } } else { DataProviderManager.Provider.UpdateIssue(entity); } return(true); } catch (Exception ex) { Log.Error(LoggingManager.GetErrorMessageResource("SaveIssueError"), ex); return(false); } }
/// <summary> /// Saves the issue /// </summary> /// <param name="entity">The issue to save.</param> /// <returns></returns> public static bool SaveOrUpdate(Issue entity) { if (entity == null) throw new ArgumentNullException("entity"); if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("The issue project id is invalid")); if (string.IsNullOrEmpty(entity.Title)) throw (new ArgumentException("The issue title cannot be empty or null")); try { if (entity.Id <= Globals.NEW_ID) { var tempId = DataProviderManager.Provider.CreateNewIssue(entity); if (tempId > 0) { entity.Id = tempId; return true; } return false; } // this is here due to issue with updating the issue from the Mailbox reader // to fix the inline images. we don't have an http context so we are limited to what we can // do from here. in any case the mailbox reader is creating and updating concurrently so // we are not missing anything. if (HttpContext.Current != null) { //existing issue entity.LastUpdate = DateTime.Now; entity.LastUpdateUserName = Security.GetUserName(); var issueChanges = GetIssueChanges(GetById(entity.Id), entity); DataProviderManager.Provider.UpdateIssue(entity); UpdateHistory(issueChanges); IssueNotificationManager.SendIssueNotifications(entity.Id, issueChanges); if (entity.SendNewAssigneeNotification) { //add this user to notifications and send them a notification var notification = new IssueNotification { IssueId = entity.Id, NotificationUsername = entity.AssignedUserName, NotificationCulture = string.Empty }; var profile = new WebProfile().GetProfile(entity.AssignedUserName); if (profile != null && !string.IsNullOrWhiteSpace(profile.PreferredLocale)) { notification.NotificationCulture = profile.PreferredLocale; } IssueNotificationManager.SaveOrUpdate(notification); IssueNotificationManager.SendNewAssigneeNotification(notification); } } else { DataProviderManager.Provider.UpdateIssue(entity); } return true; } catch (Exception ex) { Log.Error(LoggingManager.GetErrorMessageResource("SaveIssueError"), ex); return false; } }