예제 #1
0
            void InitDepartment(Guid OrgID, int DeptID)
            {
                m_DeptID = DeptID;
                DataRow _row = Companies.SelectOne(OrgID, DeptID);

                if (_row == null)
                {
                    return;
                }
                m_Name     = _row["company_name"].ToString().Trim(' ', '.');
                m_DeptGuid = Guid.Parse(_row["company_guid"].ToString());
                Micajah.Common.Bll.Instance _inst = OrgID != Guid.Empty ? Micajah.Common.Bll.Providers.InstanceProvider.GetInstance(m_DeptGuid, OrgID) : Micajah.Common.Bll.Providers.InstanceProvider.GetInstance(m_DeptGuid);
                m_PseudoDeptID     = _inst.PseudoId;
                m_InstanceName     = _inst.Name;
                m_OrgID            = _inst.OrganizationId;
                m_PseudoOrgID      = _inst.Organization.PseudoId;
                m_OrganizationName = _inst.Organization.Name;
                m_Config           = new Config(OrgID, m_DeptGuid, DeptID);
                m_CustomNames      = CustomNames.GetCustomNames(m_OrgID, DeptID);
            }
예제 #2
0
 public Instance(Micajah.Common.Bll.Instance inst)
 {
     InnerInstance = inst;
 }
예제 #3
0
 public Instance(Micajah.Common.Bll.Instance inst)
 {
     InnerInstance = inst;
 }
예제 #4
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 + "\"}");
        }
예제 #5
0
        public void Load(DataRow companyRow, string loginEmail)
        {
            int     _userId = 0;
            DataRow _row    = null;

            this.IsOk = false;
            string message = null;

            if (!ValidateLoginInCompany(companyRow, OrgID, loginEmail, out _userId, out _row, out message))
            {
                this._errMessage = message;
                return;
            }

            int _did = (int)companyRow["company_id"];

            this.strGDName  = companyRow["company_name"].ToString();
            this._strGDGuid = companyRow["company_guid"].ToString();

            this._strUId   = _userId.ToString();
            this._strDId   = _did.ToString();
            this.strEmail  = loginEmail;
            this.strGFName = _row["FirstName"].ToString();
            this.strGLName = _row["LastName"].ToString();
            this._password = _row["Password"].ToString();
            if (!_row.IsNull("tintTicketTimer"))
            {
                this.tintTicketTimer = (byte)_row["tintTicketTimer"];
            }
            else
            {
                this.tintTicketTimer = (byte)_row["tintDTicketTimer"];
            }
            if (!_row.IsNull("configPartialSetup"))
            {
                this.IsConfigPartialSetup = (bool)_row["configPartialSetup"];
            }
            this._strGSpGrp = _row["SupGroupId"].ToString();
            this._strGFrame = "0";
            switch ((int)_row["UserType_Id"])
            {
            case 1:
                this.strGPerm = ",usr";
                _role         = UserRole.StandardUser;
                break;

            case 2:
                this.strGPerm = ",tch";
                _role         = UserRole.Technician;
                break;

            case 3:
                this.strGPerm = ",tch,adm";
                _role         = UserRole.Administrator;
                break;

            case 4:
                this.strGPerm = ",que";
                _role         = UserRole.StandardUser;
                break;

            case 5:
                this.strGPerm = ",usr";
                _role         = UserRole.StandardUser;
                int    _utype      = 0;
                int    _sutype     = 0;
                int    _suid       = 0;
                string _surlocid   = string.Empty;
                string _surlocname = string.Empty;
                string _sudomain   = string.Empty;
                int    _res        = Data.Logins.SelectSuperUserInfo(OrgID, _did, _userId, ref _utype, ref _sutype, ref _suid, ref _surlocid, ref _surlocname, ref _sudomain);
                if (_res >= 0 && _sutype != 0 && _suid != 0)
                {
                    this.strGPerm                 += ",susr";
                    _role                          = UserRole.SuperUser;
                    this._strGSUserType            = _sutype.ToString();
                    this._strGSUserId              = _suid.ToString();
                    this.vchGSUserDomain           = _sudomain;
                    this.strGSUserRootLocationId   = _surlocid;
                    this.strGSUserRootLocationName = _surlocname;
                }
                break;
            }
            if (!_row.IsNull("btGlobalFilterEnabled") && (bool)_row["btGlobalFilterEnabled"])
            {
                this.strGFilter = ",gf";
            }
            if (!_row.IsNull("btLimitToAssignedTkts") && (bool)_row["btLimitToAssignedTkts"])
            {
                this.strGFilter += ",tkt";
            }
            if (this.strGFilter.IndexOf(",gf") >= 0 && this.strGFilter.IndexOf(",tkt") >= 0 && !_row.IsNull("btDisabledReports") && (bool)_row["btDisabledReports"])
            {
                this.strGFilter += ",rpt";
            }
            this.IsOk = true;
            Micajah.Common.Dal.OrganizationDataSet.UserRow _usrRow = Micajah.Common.Bll.Providers.UserProvider.GetUserRow(loginEmail);
            if (_usrRow != null)
            {
                string timeZoneId = (_usrRow.IsTimeZoneIdNull() ? null : _usrRow.TimeZoneId);
                int?   timeFormat = (_usrRow.IsTimeFormatNull() ? null : new int?(_usrRow.TimeFormat));
                int?   dateFormat = (_usrRow.IsDateFormatNull() ? null : new int?(_usrRow.DateFormat));

                if (string.IsNullOrEmpty(timeZoneId) || (!timeFormat.HasValue) || (!dateFormat.HasValue))
                {
                    Micajah.Common.Bll.Instance inst = Micajah.Common.Bll.Providers.InstanceProvider.GetInstance(this.InstanceID, this.OrgID);
                    if (inst != null)
                    {
                        if (string.IsNullOrEmpty(timeZoneId))
                        {
                            timeZoneId = inst.TimeZoneId;
                        }

                        if (!timeFormat.HasValue)
                        {
                            timeFormat = inst.TimeFormat;
                        }

                        if (!dateFormat.HasValue)
                        {
                            dateFormat = inst.DateFormat;
                        }
                    }
                }

                if (string.IsNullOrEmpty(timeZoneId))
                {
                    timeZoneId = "Eastern Standard Time";
                }

                if (!timeFormat.HasValue)
                {
                    timeFormat = 0;
                }

                if (!dateFormat.HasValue)
                {
                    dateFormat = 0;
                }

                _tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
                _tf  = timeFormat.Value;
                _df  = dateFormat.Value;
            }
        }