protected void Page_Load(object sender, EventArgs e) { Micajah.Common.Pages.MasterPage.SetPageTitle(this.Page, ActionProvider.PagesAndControls.FindByActionId(ActionProvider.SignUpOrganizationPageActionId)); if (!this.Page.IsPostBack) { this.LoadResources(); ErrorPanel.Visible = false; if (GoogleProvider.IsGoogleProviderRequest(this.Request)) { string returnUrl = null; OAuth2Parameters parameters = null; try { GoogleProvider.ProcessAuthorization(this.Context, ref parameters, ref returnUrl); this.OAuth2Parameters = JsonConvert.SerializeObject(parameters); } catch (System.Security.Authentication.AuthenticationException ex) { ErrorContinueLink.NavigateUrl = returnUrl; ErrorLabel.Text = ex.Message; ErrorPanel.Visible = true; return; } string email = null; string firstName = null; string lastName = null; GoogleProvider.GetUserProfile(parameters.AccessToken, out email, out firstName, out lastName); if (!string.IsNullOrEmpty(email)) { Email.Text = email; Email.ReadOnly = true; } if (!string.IsNullOrEmpty(firstName)) { this.UserFirstName = firstName; } if (!string.IsNullOrEmpty(lastName)) { this.UserLastName = lastName; } } OrganizationUrlRow.Visible = FrameworkConfiguration.Current.WebApplication.CustomUrl.Enabled; OrganizationName.Focus(); Control captchaTextBoxLabel = Captcha.FindControl("CaptchaTextBoxLabel"); if (captchaTextBoxLabel != null) { captchaTextBoxLabel.Visible = false; } } ResourceProvider.RegisterValidatorScriptResource(this.Page); }
private void Authenticate() { string password = Request.QueryString["p"]; string isPersistentString = Request.QueryString["cp"]; string loginName = this.LoginName; bool isPersistent = true; if (isPersistentString != null) { if (!Boolean.TryParse(isPersistentString, out isPersistent)) { isPersistent = false; } } Guid organizationId = this.OrganizationId; Guid instanceId = this.InstanceId; bool isCustomUrlEnabled = FrameworkConfiguration.Current.WebApplication.CustomUrl.Enabled; if (isCustomUrlEnabled) { if (organizationId == Guid.Empty) { string host = Request.Url.Host; if (!CustomUrlProvider.IsDefaultVanityUrl(host)) { CustomUrlProvider.ParseHost(host, ref organizationId, ref instanceId); } } else if (!GoogleProvider.IsGoogleProviderRequest(Request)) { this.VerifyVanityUrl(organizationId, instanceId); } } if (!(string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password) || (organizationId == Guid.Empty))) { if (!isCustomUrlEnabled) { LoginProvider loginProvider = new LoginProvider(); loginProvider.SignOut(true, false); } try { LoginProvider.Current.Authenticate(loginName, Support.Decrypt(password), false, isPersistent, organizationId, instanceId); this.RedirectAfterLogOn(); } catch (AuthenticationException ex) { ShowErrorMessage(ex.Message); } } else { if (GoogleProvider.IsGoogleProviderRequest(Request)) { try { string accessToken = GoogleProvider.ProcessAuthorization(this.Context, ref organizationId, ref instanceId); string firstName = null; string lastName = null; GoogleProvider.GetUserProfile(accessToken, out loginName, out firstName, out lastName); } catch (AuthenticationException ex) { ShowErrorMessage(ex.Message); } if (!string.IsNullOrEmpty(loginName)) { m_EmailToLink = loginName; string message = null; try { string domain = GoogleProvider.GetDomain(Request); if (!string.IsNullOrEmpty(domain)) { EmailSuffixProvider.ParseEmailSuffixName(domain, ref organizationId, ref instanceId); } if (LoginProvider.Current.Authenticate(loginName, null, false, true, organizationId, instanceId)) { this.RedirectAfterLogOn(); } } catch (AuthenticationException ex) { message = ex.Message; } if (!string.IsNullOrEmpty(message)) { if (LoginProvider.Current.GetLogin(loginName) == null) { message = string.Format(CultureInfo.InvariantCulture, Resources.UserContext_ErrorMessage_YourAccountIsNotFound, loginName); } } if (!string.IsNullOrEmpty(message)) { this.ShowErrorMessage(message); this.EnableCustomHandling = false; } } } } }
private void CreateNewOrganization() { if (string.Compare((string)Session["NewOrg"], "1", StringComparison.OrdinalIgnoreCase) == 0) { string url = null; UserContext user = UserContext.Current; if (user != null) { if (string.Compare(user.Email, Email.Text, StringComparison.OrdinalIgnoreCase) == 0) { url = LoginProvider.Current.GetLoginUrl(user.Email, true, user.OrganizationId, user.InstanceId, null); Response.Redirect(url); } } url = LoginProvider.Current.GetLoginUrl(); Response.Redirect(url); } else { Instance templateInstance = null; InstanceCollection insts = Micajah.Common.Bll.Providers.InstanceProvider.GetTemplateInstances(); if (insts.Count == 0) { throw new NotImplementedException(Resources.SignupOrganizationControl_NoActiveTemplateInstances); } else { templateInstance = insts[0]; } string howYouHearAboutUs = null; bool isGoogleProviderRequest = GoogleProvider.IsGoogleProviderRequest(this.Request); if (isGoogleProviderRequest) { howYouHearAboutUs = Resources.SignupOrganizationControl_HowYouHearAboutUs_Text; } Guid orgId = OrganizationProvider.InsertOrganization(OrganizationName.Text, null, null , null, null, null, null, null, null, string.Empty, howYouHearAboutUs , templateInstance.TimeZoneId, templateInstance.InstanceId , Email.Text, null, this.UserFirstName, this.UserLastName, null, null, null , OrganizationUrl.Text, this.Request , true); Session["NewOrg"] = "1"; Instance inst = InstanceProvider.GetFirstInstance(orgId); if (isGoogleProviderRequest) { string returnUrl = null; OAuth2Parameters parameters = JsonConvert.DeserializeObject <OAuth2Parameters>(this.OAuth2Parameters); GoogleProvider.ProcessAuthorization(this.Context, ref parameters, ref returnUrl); } string url = LoginProvider.Current.GetLoginUrl(Email.Text, true, orgId, inst.InstanceId, null); Response.Redirect(url); } }