Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsOther Extension...Other Extension...Create User functionCreate User function
Previous
 
Next
New Post
9/28/2012 10:14 AM
 

Hi everyone,

I'm trying to do a webservice who register user. But that's not my problem.

My problem is when i use the CreateUser function in UserController class, it returns always invalidPassword.

I show you my code :

 

string password = "aSe45tG";  UserInfo ui = new UserInfo();  ui.Email = "test45@test.com";  ui.DisplayName = "machintruc";  ui.Username = "machin2";  UserMembership um = new UserMembership(ui);  um.Password = password;  um.PasswordConfirm = password;  UserCreateStatus CreateStatus = new UserCreateStatus();  CreateStatus = UserController.CreateUser(ref ui);  lblStatus.Text = CreateStatus.ToString();

When i'm using this function to test CreateUser, it always return me invalidPassword. By the way, i tried with interface register, with the same password, always good.

do you know what is the problem?

Thx in advance

Cédric

 
New Post
9/29/2012 9:07 PM
 

I would have to look at the core code in User.ascx.cs and the UserModuleBase, UserInfo and UserMembership classes to be certain of all the steps necessary to create a new user but think that the problem lies in your instantiation of the UserMembership object um:

UserMembership um = new UserMembership(ui);

which never gets properly associated with the Membership property of the UserInfo object ui.

The UserInfo.Membership property is automatically initialized upon first reference so you should use something like the following

string password = "aSe45tG";
UserInfo ui = new UserInfo();
ui.Email = test45@test.com;
ui.DisplayName = "machintruc";
ui.Username = "machin2";
ui.Membership.Password = password;
ui.Membership.PasswordConfirm = password; // not sure if this even needs to be set
UserCreateStatus CreateStatus =  UserController.CreateUser(ref ui);

Also, you should be setting the user's PortalID and initializing the user's ProfileProperty collection with at least the preferred locale, preferred time zone and default country before calling CreateUser method.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
10/1/2012 6:01 AM
 

Thanks for your reply, William.

So I modified my code and now I have an error on the function CreateUser but user is created.

I post an screenshot showing my error :

 

Thanks for your help :)

 
New Post
10/4/2012 10:21 AM
 
Anyone can help me? :)

I don't know why this error come with the user's creation
 
New Post
10/5/2012 10:33 PM
 

I'm not sure I dare :) to reply to this thread because when I started to last Monday and opened VS 2012 to a DNN 6.2.3 source install to look at the UserModuleBase.cs class my development computer suffered a major crash which trashed its BIOS settings and consequently its boot sector on a RAID 1 array. Finally back up after 3 days of reinstalling everything.

Anyway . . . I think the null reference error is due to the ProfileProperties collection of the UserInfo object not being properly initialized with default data and in particular either the PreferredTimeZone or PreferredLocale properties before calling CreateUser. In the DNN framework source code's DotNetNuke.Entities.Modules.UserModuleBase class you will find the following:

private UserInfo InitialiseUser()
        {
            var newUser = new UserInfo();
            if (IsHostMenu && !IsRegister)
            {
                newUser.IsSuperUser = true;
            }
            else
            {
                newUser.PortalID = PortalId;
            }

            //Initialise the ProfileProperties Collection
            string lc = new Localization().CurrentUICulture;

            newUser.Profile.InitialiseProfile(PortalId);
            newUser.Profile.PreferredTimeZone = PortalSettings.TimeZone;

            newUser.Profile.PreferredLocale = lc;

            //Set default countr
            string country = Null.NullString;
            country = LookupCountry();
            if (!String.IsNullOrEmpty(country))
            {
                newUser.Profile.Country = country;
            }
            //Set AffiliateId
            int AffiliateId = Null.NullInteger;
            if (Request.Cookies["AffiliateId"] != null)
            {
                AffiliateId = int.Parse(Request.Cookies["AffiliateId"].Value);
            }
            newUser.AffiliateID = AffiliateId;
            return newUser;
        }
I would follow this pattern in your own code or have your module control's code inherit from DotNetNuke.Entities.Modules.UserModuleBase or DotNetNuke.Entities.Modules.UserUserControlBase rather than the typical PortalModuleBase. That way you will have a pre-initialized User object with which to work.

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsOther Extension...Other Extension...Create User functionCreate User function


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out