Ejemplo n.º 1
0
 public Organization(Micajah.Common.Bll.Organization org, Micajah.Common.Bll.InstanceCollection insts)
 {
     _innerOrganization = org;
     Instances          = new List <Instance>(insts.Count);
     foreach (Micajah.Common.Bll.Instance inst in insts)
     {
         Instances.Add(new Instance(inst));
     }
 }
Ejemplo n.º 2
0
        public Organization(Micajah.Common.Bll.Organization org, Micajah.Common.Bll.InstanceCollection insts)
        {
            _innerOrganization = org;
            var i = from element in insts
                    orderby element.Active
                    select element;

            Instances = new List <Instance>(insts.Count);
            foreach (Micajah.Common.Bll.Instance inst in i)
            {
                Instances.Add(new Instance(inst));
            }
        }
Ejemplo n.º 3
0
        public object CreateOrg(string name, string url, string email, string firstname, string lastname, string password, string password_confirm, string how, string note
                                , string external_id, bool sendHubSpot
                                , bool is_force_registration, bool is_force_redirect)
        {
            bool isSalesforceProviderRequest = false;

            if (!string.IsNullOrEmpty(how))
            {
                isSalesforceProviderRequest = (how.IndexOf("Salesforce", StringComparison.OrdinalIgnoreCase) > -1);
            }

            //validation
            if (string.IsNullOrWhiteSpace(name))
            {
                return(new HttpResult("Name is required.", HttpStatusCode.Forbidden));
            }

            if (!Utils.IsValidEmail(email))
            {
                return(new HttpResult("Email is required.", HttpStatusCode.Forbidden));
            }

            /*if (OrganizationProvider.GetOrganizationIdByName(name) != Guid.Empty)
             * {
             *  return new HttpResult("Name is already exists.", HttpStatusCode.Forbidden);
             * }
             */

            if (!string.IsNullOrWhiteSpace(url))
            {
                if (url.Length < 3 || url.Length > 20)
                {
                    return(new HttpResult("Url should be between 3 and 20 characters and can contains alphanumeric characters and hyphens", HttpStatusCode.Forbidden));
                }

                if (!CustomUrlProvider.ValidateCustomUrl(url))
                {
                    return(new HttpResult("Url: " + url + " is already exists.", HttpStatusCode.Forbidden));
                }
            }
            else
            {
                url = null;
            }


            bool          isAlreadyRegistered = false;
            LoginProvider lp = new LoginProvider();

            if (isSalesforceProviderRequest)
            {
                if (!string.IsNullOrEmpty(external_id))
                {
                    if (SalesforceSettingProvider.ExternalOrganizationIdExists(external_id))
                    {
                        return(new HttpResult("The organization is already registered.", HttpStatusCode.Conflict));
                    }
                }
            }
            else
            {
                isAlreadyRegistered = lp.ValidateLogin(email, null);

                if (isAlreadyRegistered && !is_force_registration)
                {
                    return(new HttpResult("User already have one registered organization. Please login OR set is_force_registration=true to continue.", HttpStatusCode.Conflict));
                }
            }

            if (string.IsNullOrWhiteSpace(firstname))
            {
                firstname = "Organization";
            }

            if (string.IsNullOrWhiteSpace(lastname))
            {
                lastname = "Administrator";
            }

            //if (string.IsNullOrWhiteSpace(lastname))
            //    return new HttpResult("LastName is required.", HttpStatusCode.Forbidden);

            //if (string.IsNullOrWhiteSpace(password))
            //    return new HttpResult("Password is required.", HttpStatusCode.Forbidden);

            if (!string.IsNullOrWhiteSpace(password))
            {
                if (!Utils.IsValidPassword(password))
                {
                    return(new HttpResult("Password is too weak. It must be at least 5 characters.", HttpStatusCode.Forbidden));
                }

                if (!password.Equals(password_confirm))
                {
                    return(new HttpResult("Passwords not match.", HttpStatusCode.Forbidden));
                }
            }
            else
            {
                password = password_confirm = null;
            }

            /*
             * Future
             *
             * string ip = base.RequestContext.Get<IHttpRequest>().UserHostAddress;
             * if (!Micajah.Common.Bll.Support.ValidateInviteToken(invite_code, ip))
             * {
             *  throw new HttpError(HttpStatusCode.Forbidden, "Invite code is not correct or expired. Please get new one.");
             * }
             */
            Guid organizationId = Guid.Empty;

            Micajah.Common.Bll.Instance inst = null;
            if (!isAlreadyRegistered || is_force_registration)
            {
                Micajah.Common.Bll.Instance           templateInstance = null;
                Micajah.Common.Bll.InstanceCollection insts            = InstanceProvider.GetTemplateInstances();

                if (insts.Count == 0)
                {
                    return(new HttpResult("No Active Template Instances", HttpStatusCode.NotFound));
                }
                else
                {
                    templateInstance = insts[0];
                }

                string howYouHearAboutUs = how;

                NameValueCollection parameters = new NameValueCollection();

                if (isSalesforceProviderRequest)
                {
                    if (!string.IsNullOrEmpty(external_id))
                    {
                        SalesforceSettingProvider.AddExternalOrganizationId(external_id, parameters);
                    }
                }

                organizationId = OrganizationProvider.InsertOrganization(name, null, null
                                                                         , null, null, null, null, null, null, string.Empty, howYouHearAboutUs, note
                                                                         , templateInstance.TimeZoneId, templateInstance.InstanceId
                                                                         , email, password, firstname, lastname, null, null, null
                                                                         , url, parameters
                                                                         , true, true, sendHubSpot);

                inst = InstanceProvider.GetFirstInstance(organizationId);
            }

            if (!is_force_redirect)
            {
                string  api_token = LoginTokenProvider.GetApiToken(email);
                ApiUser hdUser    = new ApiUser(api_token);
                if (string.IsNullOrWhiteSpace(api_token))
                {
                    return(new HttpResult("User is not correct or inactive.", HttpStatusCode.Forbidden));
                }
                return(new HttpResult(GetOrganizations(api_token, inst.PseudoId), organizationId != Guid.Empty ? HttpStatusCode.Created : HttpStatusCode.Found));
            }
            //return new HttpResult(HttpStatusCode.OK, "Already registered");
            url = lp.GetLoginUrl(email, true, organizationId, inst.InstanceId, null);

            //added redirect
            url = url.Replace("mc/login.aspx?", "login/?ReturnUrl=%2Fhome%2Fdefault.aspx%3Ffx%3Demlstp%26org%3D" + organizationId.ToString("N") + "&");

            //Headers ["Location"] = url;
            return("{\"url\" : \"" + url + "\"}");
        }