Esempio n. 1
0
    //-----------------------------------------------------------------------------
    /// <summary>
    ///
    /// </summary>
    private void NormalLogin(string[] companies)
    {
        if (companies != null && companies.Length == 1)
        {
            cmbCompany.Items.Clear();
            cmbCompany.Items.Add(companies[0]);
        }

        string loginText = txtUser.Text.Trim();
        string userName  = PXDatabase.Companies.Length > 0 ? loginText + "@" +
                           (cmbCompany.SelectedIndex != -1 ? cmbCompany.SelectedItem.Value : PXDatabase.Companies[0]) : loginText;

        if (!PXLogin.LoginUser(ref userName, txtPass.Text))
        {
            // we will change password during next round-trip
            PXContext.Session.SetString("ChangingPassword", txtPass.Text);

            DisablingUserPassword();
            EnablingChangingPassword();

            this.Master.Message = string.Empty;
        }
        else
        {
            PXLogin.InitUserEnvironment(userName, cmbLang.SelectedValue);
        }
    }
        public static void Process(EMailAccountSyncFilter filter, List <EMailSyncAccount> accounts, Object uid, string screenid)
        {
            //Check that process is singleton
            foreach (RowTaskInfo info in PXLongOperation.GetTaskList())
            {
                if (Object.Equals(uid, info.NativeKey))
                {
                    continue;
                }

                PXLongRunStatus status = PXLongOperation.GetStatus(info.NativeKey);
                if (status != PXLongRunStatus.InProcess)
                {
                    continue;
                }

                string company = PXLogin.ExtractCompany(info.User);
                string screen  = (info.Screen ?? String.Empty).Replace(".", "");
                if (screen == screenid && company == PXAccess.GetCompanyName())
                {
                    throw new PXException(ErrorMessages.PrevOperationNotCompleteYet);
                }
            }

            EmailsSyncMaint graph = CreateInstance <EmailsSyncMaint>();

            using (new PXUTCTimeZoneScope())
            {
                graph.ProcessInternal(new ProcessingContext(filter, accounts, graph.GetPolicies()));
            }
        }
Esempio n. 3
0
        protected void _(Events.RowDeleting <POOrder> e)
        {
            var row = e.Row as POOrder;

            if (row == null)
            {
                return;
            }

            var        curPOOrder = (POOrder)Base.Caches[typeof(POOrder)].Current;
            POOrderExt pOOrderExt = curPOOrder.GetExtension <POOrderExt>();

            if ((bool)pOOrderExt.UsrICSOCreated)
            {
                var curUserName   = PXLogin.ExtractUsername(PXContext.PXIdentity.IdentityName);
                var curLMICVendor = PXSelect <LMICVendor, Where <LMICVendor.vendorid, Equal <Required <LMICVendor.vendorid> > > > .Select(Base, curPOOrder.VendorID).TopFirst;

                using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICVendor.LoginName}"))
                {
                    SOOrderEntry sOOrderEntry = PXGraph.CreateInstance <SOOrderEntry>();

                    // check the shipment base on this SO is created or not
                    var isShipmentCreated = PXSelect <SOOrderShipment, Where <SOOrderShipment.orderNbr, Equal <Required <SOOrderShipment.orderNbr> > > > .Select(sOOrderEntry, row.VendorRefNbr).Count() > 0 ? true : false;

                    if (isShipmentCreated)
                    {
                        throw new PXException("You cannot delete the PO because there is shipment created in IC SO.");
                    }
                }
            }
        }
Esempio n. 4
0
    //-----------------------------------------------------------------------------
    /// <summary>
    ///
    /// </summary>
    private void NormalLogin(string[] companies)
    {
        if (companies != null && companies.Length == 1)
        {
            cmbCompany.Items.Clear();
            cmbCompany.Items.Add(companies[0]);
        }

        string loginText = txtUser.Text.Trim();
        string userName  = PXDatabase.Companies.Length > 0 ? loginText + "@" +
                           (cmbCompany.SelectedIndex != -1 ? cmbCompany.SelectedItem.Value : PXDatabase.Companies[0]) : loginText;
        Tuple <int, Guid, bool> user;
        ErrorReason?            reason;

        if (_multifactorService.IsAccessCodeValid(userName, txtPass.Text, oneTimePasswordText.Text, (object)Request, out user, out reason))
        {
            try
            {
                if (!PXLogin.LoginUser(ref userName, txtPass.Text))
                {
                    // we will change password during next round-trip
                    PXContext.Session.SetString("ChangingPassword", txtPass.Text);
                    if (user != null && user.Item3)
                    {
                        PXContext.Session.SetValueType(Ismultifactorpasswordchange, user.Item3);
                    }

                    DisablingUserPassword();
                    EnablingChangingPassword();

                    this.Master.Message = string.Empty;
                }
                else
                {
                    PXLogin.InitUserEnvironment(userName, cmbLang.SelectedValue);
                    if (this.rememberDevice.Checked && !string.IsNullOrWhiteSpace(oneTimePasswordText.Text))  //we should not update remember cookie if we authenticate using it
                    {
                        _multifactorService.RememberDevice(userName, txtPass.Text, HttpContext.Current);
                    }
                }
            }
            catch (PXException)
            {
                this.MultiFactorPipelineNotStarted.Value = "true";
                throw;
            }
        }
        else
        {
            this.MultiFactorPipelineNotStarted.Value = "true";
            var cookie = Response.Cookies[_multifactorService.GetCookieName(userName)];
            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddDays(-1);
            }
            this.oneTimePasswordText.Text = string.Empty;
            throw new PXException(PX.Data.ErrorMessages.LoginOTPInvalid);
        }
    }
Esempio n. 5
0
	//-----------------------------------------------------------------------------
	/// <summary>
	/// Perform the user password changing.
	/// </summary>
	protected void ChangingPassword()
	{
		string loginText = txtUser.Text;
		if (txtRecoveryAnswer.Visible && !PXLogin.ValidateAnswer(PXDatabase.Companies.Length > 0 ?
			loginText + "@" + cmbCompany.SelectedItem.Value : loginText, txtRecoveryAnswer.Text))
		{
			this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.InvalidRecoveryAnswer);
		}
		if (txtNewPassword.Text != txtConfirmPassword.Text)
		{
			this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.PasswordNotConfirmed);
		}
		if ((string)PXContext.Session["ChangingPassword"] == txtNewPassword.Text)
		{
			this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.NewPasswordMustDiffer);
		}
		if (string.IsNullOrEmpty(txtNewPassword.Text))
		{
			this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.PasswordBlank);
		}

		string changingPass = (string)PXContext.Session["ChangingPassword"];
		if (!String.IsNullOrEmpty(this.Master.Message))
		{
			txtVeryDummyPass.Value = changingPass;
			DisablingUserPassword();
			EnablingChangingPassword();
			return;
		}

		string gk = Request.QueryString.Get("gk");

		if (gk == null && changingPass == null)
			return;

		string userName = PXDatabase.Companies.Length > 0
			? loginText + "@" + (cmbCompany.SelectedIndex != -1 ? cmbCompany.SelectedItem.Value : PXDatabase.Companies[0])
			: loginText;

		try
		{
			PXLogin.LoginUser(
				ref userName,
				gk ?? changingPass,
				txtNewPassword.Text);
		}
		catch
		{
			txtVeryDummyPass.Value = changingPass;
			DisablingUserPassword();
			EnablingChangingPassword();

			throw;
		}

		PXLogin.InitUserEnvironment(userName, cmbLang.SelectedValue);
		AgreeToEula(loginText);
	}
Esempio n. 6
0
 protected override void Dispose(bool disposing)
 {
     if (HttpContext.Current != null && HttpContext.Current.Session != null)
     {
         PXLogin.LogoutUser(PXAccess.GetUserName(), HttpContext.Current.Session.SessionID);
     }
     FormsAuthenticationModule.SignOut();
     base.Dispose(disposing);
 }
Esempio n. 7
0
    private void AgreeToEula(string username)
    {
        var fullname = (string)PXContext.Session["EulaRequired"];

        if (username == "admin" && !string.IsNullOrEmpty(fullname))
        {
            PXLogin.AgreeToEula(fullname);
        }
    }
Esempio n. 8
0
	private void HandleEula(string username, string company)
	{
		string fullname = string.IsNullOrEmpty(company) ?
												username :
												string.Format("{0}@{1}", username, company);
		if (username == "admin" && PXLogin.EulaRequired(fullname))
		{
			PXContext.Session.SetString("EulaRequired", fullname);
			lbEula.Visible = hlEula.Visible = chkEula.Visible = true;
			this.btnLogin.Enabled = this.chkEula.Checked;
		}
	}
Esempio n. 9
0
        private bool TryAuthorize(UserAccountViewModel viewModel)
        {
            viewModel.ParseToken();
            var userName = PXLogin.ConcatLogin(viewModel.Username, viewModel.Company);
            var retVal   = PXLogin.LoginUser(ref userName, viewModel.Password);

            if (retVal)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
    //-----------------------------------------------------------------------------
    /// <summary>
    ///
    /// </summary>
    private void RemindUserPassword()
    {
        string login = "";
        string cid   = null;

        if (PXDatabase.Companies.Length > 0 && Request.QueryString.GetValues("cid") != null)
        {
            cid   = Request.QueryString.Get("cid");
            login = "******" + cid;
        }
        try
        {
            string username = PXLogin.FindUserByHash(Request.QueryString.Get("gk"), login);
            if (username != null)
            {
                _passwordRecoveryLinkExpired = false;
                txtUser.Text      = username;
                txtPass.Text      = Request.QueryString.Get("gk");
                txtUser.ReadOnly  = true;
                txtUser.BackColor = System.Drawing.Color.LightGray;

                lnkForgotPswd.Visible  = false;
                txtPass.Visible        = false;
                txtPass.TextMode       = TextBoxMode.SingleLine;
                txtDummyPass.Text      = txtPass.Text;
                txtDummyPass.Visible   = true;
                txtNewPassword.Visible = txtConfirmPassword.Visible = true;

                txtRecoveryQuestion.Text = PXLogin.FindQuestionByUsername(username, login);
                if (!string.IsNullOrEmpty(txtRecoveryQuestion.Text))
                {
                    txtRecoveryQuestion.ReadOnly  = true;
                    txtRecoveryQuestion.BackColor = System.Drawing.Color.LightGray;
                    txtRecoveryQuestion.Visible   = true;
                    txtRecoveryAnswer.Visible     = true;
                }

                //this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.PleaseChangePassword);
                if (cid != null)
                {
                    this.cmbCompany.SelectedValue = cid;
                    this.cmbCompany.Enabled       = false;
                    this.txtDummyCpny.Value       = this.cmbCompany.SelectedValue;
                }
            }
        }
        catch (PXPasswordRecoveryExpiredException)
        {
            _passwordRecoveryLinkExpired = true;
        }
    }
Esempio n. 11
0
        public override void Persist()
        {
            bool requestRelogin = Accessinfo.BranchID == null;

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (BranchBAccount item in BAccount.Cache.Deleted)
                {
                    Branch branch = PXSelect <Branch, Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > > .Select(this, item.BranchBranchCD);

                    if (branch != null)
                    {
                        if (Accessinfo.BranchID == branch.BranchID)
                        {
                            requestRelogin = true;
                        }
                        PXDatabase.Update <Ledger>(
                            new PXDataFieldAssign <Ledger.defBranchID>(null),
                            new PXDataFieldRestrict <Ledger.defBranchID>(branch.BranchID));
                    }
                }
                base.Persist();
                ts.Complete();
            }
            using (PXTransactionScope tran = new PXTransactionScope())
            {
                PXResultset <Branch> activeBranches = PXSelect <Branch> .Select(this);

                bool clearRoleNames = true;
                foreach (Branch branch in PXSelect <Branch> .Select(this))
                {
                    if (branch.RoleName != null)
                    {
                        clearRoleNames = false;
                    }
                }
                using (PXReadDeletedScope rds = new PXReadDeletedScope())
                {
                    if (clearRoleNames)
                    {
                        PXDatabase.Update <Branch>(new PXDataFieldAssign <Branch.roleName>(null));
                    }
                }
                tran.Complete();
            }
            if (requestRelogin)
            {
                PXAccess.ResetBranchSlot();
                PXLogin.SetBranchID(CreateInstance <PX.SM.SMAccessPersonalMaint>().GetDefaultBranchId());
            }
        }
Esempio n. 12
0
        public void RunStepGroup()
        {
            Guid?longOperationKey = null;

            if (this._longOperationKey != null)
            {
                longOperationKey = (Guid)this._longOperationKey;
            }

            if (_singleThread == false)
            {
                using (var ls = new PXLoginScope(CurrentStepGroup.MainContext.UserNameForLoginScope))
                {
                    PXSessionContextFactory.AuthenticateRequest();
                    PXLogin.SetBranchID(CurrentStepGroup.MainContext.BranchID);

                    CurrentStepGroup.MainContext.SetContextValues();
                    ls.Keep();
                }

                lock (CurrentStepGroup.MainContext.childLongOperations)
                {
                    if (longOperationKey != null)
                    {
                        CurrentStepGroup.MainContext.childLongOperations.Add((Guid)longOperationKey);
                    }
                }

                PXLongOperation.StartOperation(
                    longOperationKey,
                    () =>
                {
                    if (Thread.CurrentThread.Name == null)
                    {
                        Thread.CurrentThread.Name = "Child - " + longOperationKey.ToString();
                    }

                    CurrentStepGroup.RunAllSteps(longOperationKey);
                });
            }
            else
            {
                CurrentStepGroup.RunAllSteps(longOperationKey);
            }
        }
Esempio n. 13
0
 protected void Logout(object sender, EventArgs e)
 {
     try
     {
         PXLogin.LogoutUser(PXAccess.GetUserName(), Session.SessionID);
         PXContext.Session.SetString("UserLogin", string.Empty);
         Session.Abandon();
         PX.Data.Auth.ExternalAuthHelper.SignOut(Context, "~/Frames/Outlook/FirstRun.html");
         PXDatabase.Delete <PX.SM.UserIdentity>(
             new PXDataFieldRestrict <PX.SM.UserIdentity.providerName>(PXDbType.VarChar, "ExchangeIdentityToken"),
             new PXDataFieldRestrict <PX.SM.UserIdentity.userID>(PXDbType.UniqueIdentifier, PXAccess.GetUserID())
             );
     }
     finally
     {
         PX.Data.Redirector.Redirect(System.Web.HttpContext.Current, "~/Frames/Outlook/FirstRun.html");
     }
 }
Esempio n. 14
0
        protected void _(Events.RowDeleted <POOrder> e)
        {
            var row = e.Row as POOrder;

            if (row == null)
            {
                return;
            }

            var        curPOOrder = (POOrder)Base.Caches[typeof(POOrder)].Current;
            POOrderExt pOOrderExt = curPOOrder.GetExtension <POOrderExt>();

            if ((bool)pOOrderExt.UsrICSOCreated)
            {
                var curPOLines    = (POLine)Base.Caches[typeof(POLine)].Current;
                var curUserName   = PXLogin.ExtractUsername(PXContext.PXIdentity.IdentityName);
                var curLMICVendor = PXSelect <LMICVendor, Where <LMICVendor.vendorid, Equal <Required <LMICVendor.vendorid> > > > .Select(Base, curPOOrder.VendorID)?.TopFirst;

                if (curLMICVendor != null)
                {
                    using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICVendor.LoginName}"))
                    {
                        // set SOorder.ICPOCreated = False, SOOrder.Customerordernbr = Blank
                        SOOrderEntry sOOrderEntry = PXGraph.CreateInstance <SOOrderEntry>();
                        SOOrder      sOOrder      = PXSelect <SOOrder, Where <SOOrder.orderNbr, Equal <Required <SOOrder.orderNbr> > > > .Select(sOOrderEntry, row.VendorRefNbr)?.TopFirst;

                        sOOrder.CustomerOrderNbr = "IC PO had been deleted";
                        SOOrderExt sOOrderExt = sOOrder.GetExtension <SOOrderExt>();
                        sOOrderExt.UsrICPOCreated = false;
                        sOOrder = sOOrderEntry.Document.Update(sOOrder);
                        sOOrderEntry.Actions.PressSave();
                    }
                    Base.Document.Delete(curPOOrder);
                    Base.Transactions.Delete(curPOLines);
                    Base.Actions.PressSave();
                }
            }
        }
Esempio n. 15
0
    //-----------------------------------------------------------------------------
    /// <summary>
    /// Perform the user password changing.
    /// </summary>
    protected void ChangingPassword()
    {
        string loginText = txtUser.Text;

        if (txtRecoveryAnswer.Visible && !PXLogin.ValidateAnswer(PXDatabase.Companies.Length > 0 ?
                                                                 loginText + "@" + cmbCompany.SelectedItem.Value : loginText, txtRecoveryAnswer.Text))
        {
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.InvalidRecoveryAnswer);
        }
        if (txtNewPassword.Text != txtConfirmPassword.Text)
        {
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.PasswordNotConfirmed);
        }
        if ((string)PXContext.Session["ChangingPassword"] == txtNewPassword.Text)
        {
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.NewPasswordMustDiffer);
        }
        if (string.IsNullOrEmpty(txtNewPassword.Text))
        {
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.PasswordBlank);
        }

        string changingPass = (string)PXContext.Session["ChangingPassword"];

        if (!String.IsNullOrEmpty(this.Master.Message))
        {
            txtVeryDummyPass.Value = changingPass;
            DisablingUserPassword();
            EnablingChangingPassword();
            return;
        }

        string gk = Request.QueryString.Get("gk");

        if (gk == null && changingPass == null)
        {
            return;
        }

        string userName = PXDatabase.Companies.Length > 0
                        ? loginText + "@" + (cmbCompany.SelectedIndex != -1 ? cmbCompany.SelectedItem.Value : PXDatabase.Companies[0])
                        : loginText;

        try
        {
            PXLogin.LoginUser(
                ref userName,
                gk ?? changingPass,
                txtNewPassword.Text);
        }
        catch
        {
            txtVeryDummyPass.Value = changingPass;
            DisablingUserPassword();
            EnablingChangingPassword();

            throw;
        }

        bool isMultiFactorEnabled;

        string[] multifactorProviders;
        bool     isPasswordChanging;
        var      users = _multifactorService.GetUserIdsWithTwoFactorType(userName, txtNewPassword.Text, out isMultiFactorEnabled, out multifactorProviders, out isPasswordChanging);

        if (isMultiFactorEnabled)
        {
            PXLogin.LogoutUser(loginText, Session.SessionID);
            PXSessionContextFactory.Abandon();
            if (Request.QueryString["gk"] != null)
            {
                Page.Response.Redirect("~");
            }
            else
            {
                Page.Response.Redirect("~", true);
            }
            return;
        }

        PXLogin.InitUserEnvironment(userName, cmbLang.SelectedValue);
        AgreeToEula(loginText);
    }
Esempio n. 16
0
        protected void createICPOAction()
        {
            Base.Save.Press();

            var curCompanyID = PXInstanceHelper.CurrentCompany;
            var curUserName  = PXLogin.ExtractUsername(PXContext.PXIdentity.IdentityName);

            //A.By using LMICCustomer table to identify the destination tenant of PO need to be created
            var curSOOrder      = (SOOrder)Base.Caches[typeof(SOOrder)].Current;
            var curLMICCustomer = PXSelect <LMICCustomer, Where <LMICCustomer.customerID, Equal <Required <LMICCustomer.customerID> > > > .Select(Base, curSOOrder.CustomerID).TopFirst;

            //B.Go to the destination tenant, and ensure vendor is defined in LMICVendor.If not, throw error message “The vendor is not defined in destination tenant”.
            var curCompanyName = PXLogin.ExtractCompany(PXContext.PXIdentity.IdentityName);
            var curLMICVendor  = new LMICVendor();

            try
            {
                using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICCustomer.LoginName}"))
                {
                    curLMICVendor = PXSelect <LMICVendor, Where <LMICVendor.tenantID, Equal <Required <LMICVendor.tenantID> > > > .Select(PXGraph.CreateInstance <POOrderEntry>(), curCompanyID).TopFirst;
                }
            }
            catch (Exception)
            {
                throw new PXException("Please try again.");
            }

            /*Get InventoryCD in each line*/
            var inventoryCDList = new List <string>();

            foreach (SOLine line in Base.Transactions.Cache.Cached)
            {
                inventoryCDList.Add(PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, line.InventoryID).TopFirst?.InventoryCD);
            }

            if (curLMICCustomer != null)
            {
                if (curLMICVendor != null)
                {
                    try
                    {
                        PXLongOperation.StartOperation(Base, () =>
                        {
                            var SOOrderCustomerOrderNbr = string.Empty;


                            //C.Create a purchase order in destination tenant by uing the following mapping.
                            using (PXLoginScope pXLoginScope = new PXLoginScope($"{curUserName}@{curLMICCustomer.LoginName}"))
                            {
                                POOrderEntry pOOrderEntry = PXGraph.CreateInstance <POOrderEntry>();
                                /* PO Header */
                                POOrder pOOrder = new POOrder();
                                pOOrder         = pOOrderEntry.Document.Insert(pOOrder);

                                pOOrder.BranchID = curLMICVendor.BranchID;
                                pOOrder.VendorID = curLMICVendor.VendorID;

                                pOOrderEntry.Document.Cache.RaiseFieldUpdated <POOrder.vendorID>(pOOrder, pOOrder.VendorID);

                                pOOrder.VendorRefNbr = curSOOrder.OrderNbr;
                                pOOrder.OrderDate    = curSOOrder.OrderDate;
                                pOOrder.OrderDesc    = "IC PO | " + curCompanyName + " | " + curSOOrder.OrderNbr;

                                /* PO Line */
                                int i = 0;
                                foreach (SOLine line in Base.Transactions.Cache.Cached)
                                {
                                    POLine pOLine       = new POLine();
                                    var tempInventoryID = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(pOOrderEntry, inventoryCDList[i])?.TopFirst?.InventoryID;
                                    pOLine.InventoryID  =
                                        tempInventoryID == null ?
                                        PXSelect <INItemXRef, Where <INItemXRef.alternateID, Equal <Required <INItemXRef.alternateID> > > > .Select(pOOrderEntry, inventoryCDList[i])?.TopFirst?.InventoryID : tempInventoryID;
                                    pOLine.OrderQty = line.OrderQty;
                                    pOLine          = pOOrderEntry.Transactions.Insert(pOLine);

                                    pOLine.CuryUnitCost = line.CuryUnitPrice;
                                    pOLine = pOOrderEntry.Transactions.Update(pOLine);

                                    i++;
                                }

                                //D.If the PO is saved successfully, please update the following fields
                                // - POOrder, ICSOCreated = true
                                POOrderExt pOOrderExt     = pOOrder.GetExtension <POOrderExt>();
                                pOOrderExt.UsrICSOCreated = true;
                                pOOrderEntry.Document.Update(pOOrder);
                                pOOrderEntry.Actions.PressSave();

                                SOOrderCustomerOrderNbr = pOOrder.OrderNbr;
                            }

                            //D.If the PO is saved successfully, please update the following fields
                            // - SOOrder, ICPOCreated = true; Customer Order Nbr = POOrder.OrderNbr
                            SOOrderExt sOOrderExt       = curSOOrder.GetExtension <SOOrderExt>();
                            sOOrderExt.UsrICPOCreated   = true;
                            curSOOrder.CustomerOrderNbr = SOOrderCustomerOrderNbr;
                            Base.Document.Update(curSOOrder);
                            Base.Save.Press();
                        });
                    }
                    catch (Exception)
                    {
                        throw new PXException("Please try again.");
                    }
                }
                else
                {
                    throw new PXException("The vendor is not defined in destination tenant");
                }
            }
        }
Esempio n. 17
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(edEmail.Text))
        {
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.EmailEmpty);
            return;
        }

        if (Request.QueryString.GetValues("Target") == null || Request.QueryString.GetValues("ReturnUrl") == null)
        {
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.InvalidQueryString);
            return;
        }

        string link = HttpContext.Current.Request.GetWebsiteUrl().TrimEnd('/');

        link += Request.QueryString.GetValues("Target")[0];
        link += "?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString.GetValues("ReturnUrl")[0]);

        string[] companies = PXDatabase.Companies;
        bool     anySuccess = false; string errorMsg = null;

        if (companies.Length > 0)
        {
            if (!PXDatabase.SecureCompanyID)
            {
                companies = new string[] { cmbCompany.SelectedItem.Value }
            }
            ;

            foreach (string companyID in companies)
            {
                try
                {
                    PXDatabase.ResetCredentials();
                    PXLogin.SendUserLogin(edEmail.Text, link, "temp@" + companyID);
                    anySuccess = true;
                }
                catch (Exception ex)
                {
                    errorMsg = ex.Message;
                }
            }
        }
        else
        {
            try
            {
                PXLogin.SendUserLogin(edEmail.Text, link, null);
                anySuccess = true;
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }
        }

        if (anySuccess)
        {
            //lblMsg.ForeColor = System.Drawing.Color.Black;
            this.Master.Message = PX.Data.PXMessages.LocalizeNoPrefix(PX.AscxControlsMessages.LoginScreen.PasswordSent);
            LiteralControl metaRefresh = new LiteralControl("<meta http-equiv=\"Refresh\" content=\"4;URL=" + link + "\" />");
            Page.Header.Controls.Add(metaRefresh);
        }
        else if (!String.IsNullOrEmpty(errorMsg))
        {
            this.Master.Message = errorMsg;
        }
    }
}
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            bool authorized = false,
                                                  allowAnonymous     = false,
                                                  missingCredentials = false;
            var anonActionAttributes     = actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>(true);
            var anonControllerAttributes = actionContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes <AllowAnonymousAttribute>(true);

            if (anonActionAttributes.Count > 0 || anonControllerAttributes.Count > 0)
            {
                allowAnonymous = true;
            }
            var authorizeHeader = actionContext.Request.Headers.Authorization;

            if (authorizeHeader != null && authorizeHeader.Scheme.Equals("basic", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(authorizeHeader.Parameter))
            {
                var encoding    = Encoding.GetEncoding("ISO-8859-1");
                var credintials = encoding.GetString(Convert.FromBase64String(authorizeHeader.Parameter));

                var splitted = credintials.Split(':');
                if (splitted.Length < 2)
                {
                    actionContext.Response = new Util.UnauthorizedMessage();
                }
                else
                {
                    string company  = string.Empty;
                    string username = string.Empty;
                    string password = string.Empty;
                    if (splitted.Length > 2)
                    {
                        company  = splitted[0].ToUpper();
                        username = splitted[1].ToUpper();
                        password = splitted[2];
                    }
                    else if (splitted.Length == 2)
                    {
                        username = splitted[0].ToUpper();
                        password = splitted[1];
                    }
                    if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
                    {
                        var userName = PXLogin.ConcatLogin(username, company);
                        var retVal   = PXLogin.LoginUser(ref userName, password);
                        if (retVal)
                        {
                            authorized = true;
                        }
                    }
                    else
                    {
                        missingCredentials = true;
                    }
                }
            }
            else
            {
                missingCredentials = true;
            }
            if (!allowAnonymous && missingCredentials)
            {
                actionContext.Response = new Util.ErrorMessage {
                    Message = "Credentials are missing (protocol error)."
                }
            }
            ;
            else if (!allowAnonymous && !authorized)
            {
                actionContext.Response = new Util.UnauthorizedMessage();
            }
        }