示例#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);
        }
    }
示例#2
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);
        }
    }
示例#3
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);
	}
示例#4
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);
    }