Ablecommerce API to validate Members on the fly

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Fri Oct 10, 2008 5:56 am

Locate the following lines of code in SaveUser() method in EditUser.aspx page.

Code: Select all

_User.Save();
//UPDATE PASSWORD
and make them look like as below

Code: Select all

_User.Settings.SetValueByKey("FmaMemberId",memberID.Text);
_User.Save();
//UPDATE PASSWORD
Last edited by mazhar on Mon Oct 20, 2008 10:48 am, edited 2 times in total.

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Fri Oct 10, 2008 7:44 am

Mazhar:

Thank you soooo much for your patience!

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Fri Oct 10, 2008 7:54 am

You are welcome 8)

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Fri Oct 10, 2008 8:08 am

I am adding the memberID.text to the MyCredentialsPage.ascx and I am trying to edit the code in the MyCredentialsPage.ascx.cs.

I notice that in the MyCredentialsPage.ascx.cs there is no protected void InitializeForm() in which to place the

Code: Select all

protected void InitializeForm()
        
    {
        //CALLS IN MEMBERID FIELD
        string FmaMemberId = _User.Settings.GetValueByKey("FmaMemberId");
        memberID.Text = FmaMemberId;
I tried putting it in the page load event to no avail. I also tried adding the call to the InitializeForm() and that wasn't correct either.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Fri Oct 10, 2008 8:21 am

Locate the following code in the Page_Load method

Code: Select all

if (!isAnonymous)
            {
                UserName.Text = userName;
                NewAccountText.Visible = false;
                UpdateAccountText.Visible = true;
            }
and make it look like

Code: Select all

if (!isAnonymous)
            {
                UserName.Text = userName;
                NewAccountText.Visible = false;
                UpdateAccountText.Visible = true;
                string FmaMemberId = user.Settings.GetValueByKey("FmaMemberId");
                memberID.Text = FmaMemberId;
            }
Also when checking the crediantials make sure that current user have some memberid other wise the textbox will be empty.

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Fri Oct 10, 2008 8:36 am

Perfect!

I am also adding the update for memberID on the MyCredentialsPage.ascx.cs. However, I am getting this error:
[[ConLib:MyCredentialsPage]] e:\hshome\fmastore\fmastore.org\ConLib\MyCredentialsPage.ascx.cs(122): error CS0103: The name '_User' does not exist in the current context
My code is:

Code: Select all

   _User.Settings.SetValueByKey("FmaMemberId", memberID.Text);
                _User.Save();
                //UPDATE THE USERNAME

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Fri Oct 10, 2008 8:43 am

_User object doesn't exist in this control. Here it is called the user so you should have the code as

Code: Select all

user.Settings.SetValueByKey("FmaMemberId", memberID.Text);
                user.Save();

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Fri Oct 10, 2008 8:58 am

Strange, it doesn't throw an error. But it isn't saving right either. If I go out of the page and come back in after save, the information did not save...

Code: Select all

//UPDATE MEMBERID
                user.Settings.SetValueByKey("FmaMemberId", memberID.Text);
                user.Save();
                //UPDATE THE USERNAME

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Fri Oct 10, 2008 9:32 am

Well it will not work in SaveButton_Click() method because when some user only want to update his/her member id in that case validation will not allow the operation. A quick work around to this problem is to have an other button for the member id field so that user can update it separately. For this first modify the ascx file and change your text box code to exactly look like as below

Code: Select all

<asp:TextBox ID="memberId" runat="server" ValidationGroup="MemberId"></asp:TextBox>
<asp:Button ID="UpdateMemberId" runat="server" Text="Update Member Id" ValidationGroup="MemberId" OnClick="UpdateMemberId_Click" />

and then add the following method to your controls cs file

Code: Select all

protected void UpdateMemberId_Click(object sender, EventArgs e)
    {
        User user = Token.Instance.User;
        bool isAnonymous = user.UserName.StartsWith("zz_anonymous_");
        if (!isAnonymous)
        {            
            user.Settings.SetValueByKey("FmaMemberId", memberId.Text);
            user.Save();
        }
    }
This change will make available another button on the page which will only change the member id field.
Last edited by mazhar on Mon Oct 20, 2008 10:48 am, edited 1 time in total.

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Fri Oct 10, 2008 10:35 am

Ah ok. I will do that. Thank you!

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Fri Oct 10, 2008 1:18 pm

I keep getting this error:
[[ConLib:MyCredentialsPage]] e:\hshome\fmastore\fmastore.org\ConLib\MyCredentialsPage.ascx.cs(32): error CS0103: The name 'memberID' does not exist in the current context
Ah, I figured it out before I posted this text, Forgot that most programming languages are case sensitive, unlike ColdFusion which I have been using for a year. The code had memberId, not memberID..

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Sat Oct 11, 2008 4:13 am

Just change memberID to memberId. Its because we have changed the textbox name from memberID to memberId, so all old references on the page should be updated.

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Mon Oct 13, 2008 8:51 am

I am trying now to add the code to the LoginDialog.ascx.cs to validate if a memberID is valid by using this code:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.fmanet.org/JobBoard/Job-Board-Login.cfm?ID=" + FmaMemberId);
using (Stream stream = request.GetResponse().GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string response = reader.ReadToEnd();
return response;// This string contains the HTML or text returned by your URL
}
}

But I cannot call in the FmaMemberId correctly.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Mon Oct 13, 2008 9:30 am

If user is logged then you can get his/her member id by using the Token as discussed before.

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Mon Oct 13, 2008 9:47 am

This is not quiet right. Somehow I need to see the fmamemberID, and the response returned from the Job-Board-Login.cfm page and then add it to the member group 'validmember'

//LOGIN SUCCEEDED, MIGRATE USER IF NEEDED
int newUserId = loginUser.UserId;
int oldUserId = Token.Instance.UserId;
if ((oldUserId != newUserId) && (newUserId != 0))
{
User.Migrate(Token.Instance.User, UserDataSource.Load(newUserId));
Token.Instance.UserId = newUserId;
UserSetting userSetting = new UserSetting();
userSetting.FieldName = "FmaMemberId";
userSetting.FieldValue = "FmaMemberId";
newUser.Settings.Add(userSetting);
newUser.Save();

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.fmanet.org/JobBoard/Job-Board-Login.cfm?ID=" + FmaMemberId);
using (Stream stream = request.GetResponse().GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string response = reader.ReadToEnd();
return response;// This string contains the HTML or text returned by your URL
}
}

}

UserGroup ugly = new UserGroup(userID, Validmember)
if (validMember)
{
ugly.Save();
}
else
{
ugly.Delete();
}

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Mon Oct 20, 2008 9:49 am

Finally got the finished code working.

For anyone who is trying to do this, on the login page the below code was added to validate a memberID and then add the user to a discount group.

//HANDLE LOGIN PROCESSING
if (trRememberMe.Visible && RememberUserName.Checked)
{
HttpCookie cookie = new HttpCookie("UserName", UserName.Text);
cookie.Expires = DateTime.MaxValue;
Response.Cookies.Add(cookie);
}
else
{
Response.Cookies.Add(new HttpCookie("UserName", ""));
}
// BEGIN MEMBER VALIDATION CODE
string FmaMemberId = loginUser.Settings.GetValueByKey("FmaMemberId");
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.fmanet.org/JobBoard/Job-Board-Login.cfm?ID=" + FmaMemberId);
using (System.IO.Stream stream = request.GetResponse().GetResponseStream())
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
{
string response = reader.ReadToEnd();
if (response.Trim().Equals("YES"))
{
UserGroup validMember = new UserGroup(Token.Instance.UserId, 10);
validMember.Save();
}
else
{
UserGroup validMember = new UserGroup(Token.Instance.UserId, 10);
validMember.Delete();
}
}
}
// END
Last edited by FmaAlbee on Mon Oct 20, 2008 12:42 pm, edited 1 time in total.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Mon Oct 20, 2008 10:12 am

That's great :) Thanks for sharing the information.

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Ablecommerce API to validate Members on the fly

Post by nickc » Mon Oct 20, 2008 10:46 am

My 2¢:
Noticed that your UserGroup id was hard coded - if you moved that to an appSetting string of comma separated values, your app would be more easily managed, with more granualar control over discounts; something like ...

<appSettings>
<add key="MemberDiscount:MemberGroupIds" value="10,31,198" />
</appSettings>

and then...

foreach (groupId in ConfigurationManager.AppSettings["MemberDiscount:MemberGroupIds"].Split(new char[] {','}))
{
UserGroup validMember = new UserGroup(Token.Instance.UserId, Convert.ToInt32(groupId));
validMember.Save();
}

Thanks for the contribution.

FmaAlbee
Lieutenant (LT)
Lieutenant (LT)
Posts: 51
Joined: Fri Sep 12, 2008 2:12 pm

Re: Ablecommerce API to validate Members on the fly

Post by FmaAlbee » Mon Oct 20, 2008 12:37 pm

Thanks nickc,

I will implement and test your suggestion. :)

User avatar
mfreeze
Commodore (COMO)
Commodore (COMO)
Posts: 421
Joined: Mon Jan 24, 2005 2:07 pm
Location: Washington, NJ
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mfreeze » Mon Jan 25, 2010 4:19 pm

Did you ever figure out how to update the user setting in the edituser.aspx.cs file? I am struggling with this also.
Mary E Freeze

Freeze Frame Graphics
Web Hosting and Design, ASP and CFMX Development

http://www.ffgraphics.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Ablecommerce API to validate Members on the fly

Post by mazhar » Tue Jan 26, 2010 7:23 am

Mary have a look at following thread it may be helpful
viewtopic.php?f=45&t=7228

Post Reply