Пример #1
0
    private void checkEmailExistsGetOrCreatePortalUser(IConciergeAPIService serviceProxy)
    {
        //The API GetOrCreatePortalUser will attempt to match the supplied credentials to a portal user, individual, or organization.
        //If a portal user is found it will be returned.  If not and an individual / organization uses the email address it will create and return a new Portal User
        ConciergeResult <msPortalUser> result = serviceProxy.SearchAndGetOrCreatePortalUser(tbEmail.Text);

        //The portal user in the result will be null if the e-mail didn't match anywhere
        if (result.ResultValue == null)
        {
            return;
        }

        var portalUser = result.ResultValue.ConvertTo <msPortalUser>();

        if (MultiStepWizards.CreateAccount.InitiatedByLeader)
        {
            MultiStepWizards.CreateAccount.InitiatedByLeader = false;
            GoTo(string.Format("~/membership/Join.aspx?entityID={0}", portalUser.Owner));
        }
        else
        {
            GoTo(
                string.Format(
                    "~/profile/EmailLoginInformation.aspx?contextID={0}",
                    portalUser.ID));
        }
    }
Пример #2
0
    private static List <NameValuePair> getAllMemberSuiteConfigurationSettings(string ns)
    {
        using (IConciergeAPIService proxy = ConciergeAPIProxyGenerator.GenerateProxy())
        {
            ConciergeResult <List <NameValuePair> > result = proxy.GetAllConfigurationSettings(ns);
            if (!result.Success)
            {
                return(null);
            }

            return(result.ResultValue);
        }
    }
Пример #3
0
    protected string GetPriorityPaymentsConfig(string entityId)
    {
        if (string.IsNullOrWhiteSpace(entityId))
        {
            return(null);
        }

        using (var api = GetServiceAPIProxy())
        {
            ConciergeResult <PaymentProcessorSettings> priorityData = api.GetPaymentProcessorSettings(null, entityId);
            var serializer = new JavaScriptSerializer();
            return(serializer.Serialize(priorityData.ResultValue));
        }
    }
Пример #4
0
    protected void tryGetOrCreatePortalUser(IConciergeAPIService serviceProxy)
    {
        //The API GetOrCreatePortalUser will attempt to match the supplied credentials to a portal user, individual, or organization.
        //If a portal user is found it will be returned.  If not and an individual / organization uses the email address it will create and return a new Portal User
        ConciergeResult <msPortalUser> result = serviceProxy.SearchAndGetOrCreatePortalUser(tbLoginID.Text);

        //The portal user in the result will be null if the e-mail didn't match anywhere
        if (result.ResultValue == null)
        {
            return;
        }

        portalUser = result.ResultValue.ConvertTo <msPortalUser>();

        //Send the forgotten password email
        var sendEmailResult = serviceProxy.SendForgottenPortalPasswordEmail(portalUser.Name, null);
    }
Пример #5
0
    public static string LogException(Exception ex, Uri u)
    {
        //if there's no http context do not log
        //If we don't know what association this is we can't log either because a auditlog requires a wall to save
        if (HttpContext.Current == null ||   CurrentAssociation == null)
            return null;

        try
        {
            NameValueCollection queryStringVariables = new NameValueCollection();
            if (u != null)
                queryStringVariables = HttpUtility.ParseQueryString(u.Query);
            string contextId = queryStringVariables["contextID"];

            MemberSuiteObject contextObject = null;

            using (IConciergeAPIService proxy = ConciergeAPIProxyGenerator.GenerateProxy())
            {
                //Get the current user details from the Concierge API
                LoginResult loginResult = proxy.WhoAmI().ResultValue;
                msUser currentUser = loginResult.PortalUser == null ? loginResult.User.ConvertTo<msUser>() : loginResult.PortalUser.ConvertTo<msUser>();

                //If there's a specified context then get the details on the context object
                if (!string.IsNullOrWhiteSpace(contextId))
                {
                    ConciergeResult<MemberSuiteObject> getResult = proxy.Get(contextId);
                    if (getResult.Success)
                        contextObject = getResult.ResultValue;
                }

                msAuditLog auditLog = constructAuditLog(currentUser, ex, contextId, contextObject);
                ConciergeResult<MemberSuiteObject> saveResult = proxy.RecordErrorAuditLog(auditLog);
                
                if (saveResult.Success)
                    return saveResult.ResultValue.SafeGetValue<string>("ID");
            }
        }
        catch(Exception e)
        {
            Console.WriteLine("Unable to log exception.");
            Console.WriteLine(e.ToString());
            Console.WriteLine(ex.ToString());
        }

        return null;
    }
Пример #6
0
    /// <summary>
    /// Retrieves the portal information based on a number of factors
    /// </summary>
    /// <returns></returns>
    private static PortalInformation retrievePortalInformation()
    {
        var context = HttpContext.Current;

        if (context == null)
        {
            return(null);
        }

        // first, we need to see if we can locate the association ID
        // if we have that, then we are good - we can get portal information based on that

        // but if we DON'T, we have to try to use the host name
        string associationID = tryToRetrieveAssociationID();


        ConciergeResult <PortalInformation> pi = null;

        using (var api = ConciergeAPIProxyGenerator.GenerateProxy())
        {
            // If there is no specific association id for this portal intance then it is running in multi-tenant mode.  If so, we need to get the association id
            // by passsing the host name into the Concierge API
            if (associationID != null)
            {
                pi = api.RetrievePortalInformationByID();
            }
            else
            {
                var urlString = string.Format("{0}://{1}", context.Request.Url.Scheme,
                                              context.Request.Url.Authority);
                pi = api.RetrievePortalInformationByUrl(urlString);
            }
        }
        // ok - we give up - return a 404 indicating that this portal url is not known
        if (pi == null || !pi.Success || pi.ResultValue == null)
        {
            throw new ApplicationException(
                      "Unable to determine association for this portal. Use the configuration file, a query string, or a valid host name.");
        }

        SessionManager.Set("PortalInformation", pi);  // remember it

        return(pi.ResultValue);
    }
    protected void btnChangeDepartment_Click(object sender, EventArgs e)
    {
        if (!IsValid)
        {
            return;
        }

        IConciergeAPIService proxy = ConciergeAPIProxyGenerator.GenerateProxy();

        // let's get the user from the session
        var loginResult = proxy.WhoAmI();

        if (!loginResult.Success) // something went wrong
        {
            Response.Write("There was a problem: " + loginResult.Errors[0].Message);
            return;
        }


        msUser user = new msUser(loginResult.ResultValue.User);


        // now, change the department
        user.Department = tbUserDepartment.Text;

        // now, we have to save it
        // again, the false keeps an exception from being thrown

        ConciergeResult <MemberSuiteObject> result = proxy.Save(user);

        if (!result.Success)
        {
            Response.Write("Error occured: " + result.Errors[0].Message);
            return;
        }

        user = new msUser(result.ResultValue);
        // store the user in the session - it's serializable

        lblUserDepartment.Text = user.Department;
        tbUserDepartment.Text  = "";

        Response.Write("Department Successfully updated.");
    }
Пример #8
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        lblError.Visible = false;

        //Verify the user's rights to login.  In this sample, this is done using the MemberSuite API
        //If MemberSuite is not the authority storing your credentials, you can verify this using any method you choose
        //For instance, your own database, ASP.NET Membership, digital certificates, or any other method.
        //The actual single sign on only requires the username and expects you have already verified the user's rights to log in.
        if (!VerifyPortalUsersRights())
        {
            lblError.Visible = true;
            return;
        }

        //Get the supplied portal username
        string portalUserName = tbUserName.Text;

        //Generate a Digital Signature of the portal username using the Signing Certificate
        byte[] signature = GenerateDigitalSignature(portalUserName);

        using (IConciergeAPIService proxy = ConciergeAPIProxyGenerator.GenerateProxy())
        {
            //Request a portal security token specifying the portal username, ID of the signing certificate, and digital signature
            ConciergeResult <byte[]> portalLoginTokenResult = proxy.CreatePortalSecurityToken(portalUserName,
                                                                                              SigningCertificateId,
                                                                                              signature);

            //If the Concierge API indicated a fault, write a friendly error message
            if (!portalLoginTokenResult.Success)
            {
                lblError.Text    = string.IsNullOrWhiteSpace(portalLoginTokenResult.FirstErrorMessage) ? "API operation failed" : portalLoginTokenResult.FirstErrorMessage;
                lblError.Visible = true;
                return;
            }

            //Set the portal security token in the web user's session so it can be used by the RedirectToPortal page
            PortalLoginToken = portalLoginTokenResult.ResultValue;
        }

        //Send the web user to the page that will construct a form and POST the portal security token to the portal's Login.aspx page
        Response.Redirect("~/RedirectToPortal.aspx");
    }
    private static void cacheAllConfigurationSettings(string ns)
    {
        if (string.IsNullOrWhiteSpace(ns))
        {
            return;
        }

        lock (threadLock)
        {
            using (IConciergeAPIService proxy = ConciergeAPIProxyGenerator.GenerateProxy())
            {
                ConciergeResult <List <NameValuePair> > result = proxy.GetAllConfigurationSettings(ns);

                if (!result.Success)
                {
                    return;
                }

                CachedConfigurationSettings[ns.ToLower()] = result.ResultValue;
            }
        }
    }
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            if (CurrentUserName == null)
            {
                throw new ProviderException("Cannot change password - not logged in");
            }

            if (username != CurrentUserName)
            {
                throw new ProviderException("Cannot change user name for a different logged in user");
            }

            ValidatePasswordEventArgs args =
                new ValidatePasswordEventArgs(username, newPassword, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                if (args.FailureInformation != null)
                {
                    throw args.FailureInformation;
                }
                else
                {
                    throw new MembershipPasswordException("Change password canceled due to new password validation failure.");
                }
            }


            using (var api = ConciergeAPIProxyGenerator.GenerateProxy(false))
            {
                ConciergeResult changePasswordResult = api.ChangePassword(oldPassword, newPassword);
                return(changePasswordResult.Success);
            }
        }
Пример #11
0
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);

        byte[] portalLoginToken = null;

        string targetURL = Request["TargetUrl"];

        if (string.IsNullOrEmpty(targetURL))
        {
            // If no target URL provided, just go back to the home page
            GoHome();
        }

        if (CurrentUser == null)
        {
            // No Logged-in User, just redirect to target URL
            Response.Redirect(targetURL);
        }

        // Generate an SSO Token based on logged-in User
        using (IConciergeAPIService proxy = ConciergeAPIProxyGenerator.GenerateProxy())
        {
            // Request a portal security token specifying the portal username, ID of the signing certificate, and digital signature
            ConciergeResult <byte[]> portalLoginTokenResult = proxy.CreatePortalSecurityToken(
                CurrentUser.Name,
                ConfigurationManager.AppSettings["SigningCertificateId"],
                Sign(Encoding.ASCII.GetBytes(CurrentUser.Name)));

            //If the Concierge API indicated a fault, write a friendly error message
            if (!portalLoginTokenResult.Success)
            {
                GoToErrorPage(string.IsNullOrWhiteSpace(portalLoginTokenResult.FirstErrorMessage) ? "API operation failed" : portalLoginTokenResult.FirstErrorMessage);
                return;
            }

            //Set the portal security token in the web user's session so it can be used by the RedirectToPortal page
            portalLoginToken = portalLoginTokenResult.ResultValue;
        }

        // If there's no portal security token in the web user's session send them back to the main page
        if (Request.UrlReferrer == null || portalLoginToken == null)
        {
            GoToErrorPage("Unable to jump to target page.");
            return;
        }

        // Define the form variables to POST to the portal Login.aspx

        // This will let the new site know exactly where you are coming from
        litReturnUrl.Text = Request.UrlReferrer.ToString();

        // This token allows the Single Sign On
        litToken.Text = Convert.ToBase64String(portalLoginToken);

        // This OPTIONAL value tells the page where to redirect the user after login.
        litNextUrl.Text = Request["NextUrl"];

        // This is the page that will perform the login
        litAction.Text = targetURL;

        // This page should never be cached
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
    }
        public override void Run()
        {
            /* The purpose of this sample is to show you how to use the API to execute a portal login
             * on behalf of an individual, and once that portal login is completed, how to query on a member's status.
             * We reuse some of what's in DeterminingMembershipStatus here.
             */

            // First, we need to prepare the proxy with the proper security settings.
            // This allows the proxy to generate the appropriate security header. For more information
            // on how to get these settings, see http://api.docs.membersuite.com in the Getting Started section
            if (!ConciergeAPIProxyGenerator.IsSecretAccessKeySet)
            {
                ConciergeAPIProxyGenerator.SetAccessKeyId(ConfigurationManager.AppSettings["AccessKeyID"]);
                ConciergeAPIProxyGenerator.SetSecretAccessKey(ConfigurationManager.AppSettings["SecretAccessKey"]);
                ConciergeAPIProxyGenerator.AssociationId = ConfigurationManager.AppSettings["AssociationID"];
            }

            // ok, let's generate our API proxy
            using (var api = ConciergeAPIProxyGenerator.GenerateProxy())
            {
                Console.WriteLine(
                    "Please enter login credentials. If you don't have specific credentials, try 'test' for both the user and password to get Terry Smith.");
                Console.WriteLine();
                Console.WriteLine("Please enter the username and hit ENTER.");
                string username = Console.ReadLine();

                Console.WriteLine("Please enter the password and hit ENTER.");
                string password = Console.ReadLine();

                ConciergeResult <LoginResult> portalLoginResult = api.LoginToPortal(username, password);

                if (!portalLoginResult.Success)
                {
                    Console.WriteLine("Portal login failed with this error: " + portalLoginResult.FirstErrorMessage);
                    return;
                }

                Console.WriteLine("Portal login successful - accessing member information...");

                // this is the "entity" that you've logged in as.
                // remember an entity is either an organization OR an individual - it's a base class.
                MemberSuiteObject entity = portalLoginResult.ResultValue.PortalEntity;

                // now, let's get that entity's ID
                string entityID = entity.SafeGetValue <string>("ID");

                // there's a lot of confusion between the different types of users, so let's list them
                Console.WriteLine();
                Console.WriteLine("Users");
                Console.WriteLine("-----------------------------");
                Console.WriteLine();
                Console.WriteLine("API User: {0} - this is the security context that your application is using.",
                                  portalLoginResult.ResultValue.User["Name"]);
                Console.WriteLine(
                    "Portal User: {0} - this is the security context that you are logging your member in as. It's linked to the actual member record via the Owner property.",
                    portalLoginResult.ResultValue.PortalUser["Name"]);
                Console.WriteLine(
                    "Individual/Organization: {0} - this is the entity record that the portal user is tied to. ",
                    portalLoginResult.ResultValue.PortalEntity["Name"]);
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("The owner of the login has an ID of '{0}' - accessing...",
                                  entityID);

                // ok, let's get the membership status
                string msql = string.Format(
                    "select TOP 1 FirstName, LocalID, LastName, Membership.Type.Name, Membership.PrimaryChapter.Name, Membership.ExpirationDate, Membership.ReceivesMemberBenefits from Individual where ID = '{0}' order by LastName",
                    entityID);

                var result = api.ExecuteMSQL(msql, 0, null);

                if (!result.Success)
                {
                    Console.WriteLine("Search failed: {0}", result.FirstErrorMessage);
                    return;
                }

                DataRow resultRow = result.ResultValue.SearchResult.Table.Rows[0];
                // we know there's only one row, since the ID is unqiue
                Console.WriteLine("ID: " + resultRow["LocalID"]);
                Console.WriteLine("First Name: " + resultRow["FirstName"]);
                Console.WriteLine("Last Name: " + resultRow[msIndividual.FIELDS.LastName]);
                // <--- this is how you would use constants, which is the better way to go
                Console.WriteLine("Member? " + resultRow["Membership.ReceivesMemberBenefits"]);
                Console.WriteLine("Member Type: " + resultRow["Membership.Type.Name"]);
                Console.WriteLine("Chapter: " + resultRow["Membership.PrimaryChapter.Name"]);
                Console.WriteLine("Expiration Date: " + resultRow["Membership.ExpirationDate"]);
                Console.WriteLine("Search successful: {0} results returned.",
                                  result.ResultValue.SearchResult.TotalRowCount);
            }
        }