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 ExtensionsModulesModulesThe proper way to create DNN user from codeThe proper way to create DNN user from code
Previous
 
Next
New Post
11/22/2010 11:35 PM
 
What is the proper way to create DNN user from code? I use this code, but it won't show on the user list. I don't know why. Is there any something missing?

UserInfo ui = new DotNetNuke.Entities.Users.UserInfo();
ui.Username = "username";
 
ui.FirstName = "first name";
ui.LastName = "last name";
ui.IsSuperUser = false;
ui.Email = "email@domain.com";
ui.PortalID = PortalSettings.PortalId;
ui.DisplayName = "display name";
 
ui.Profile.FirstName = ui.FirstName;
ui.Profile.LastName = ui.LastName;
ui.Profile.Country = "EN";
ui.Profile.PreferredLocale = PortalSettings.DefaultLanguage;
ui.Profile.TimeZone = PortalSettings.TimeZoneOffset;
 
ui.Membership.Password = "p@ssw0rd";
ui.Membership.UpdatePassword = false;
ui.Membership.IsOnLine = false;
ui.Membership.CreatedDate = DateTime.Now;
ui.Membership.Approved = true;
 
UserCreateStatus createStatus = UserController.CreateUser(ref ui);
DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs args;
 
if (createStatus == UserCreateStatus.Success)
{
    args = new UserUserControlBase.UserCreatedEventArgs(ui);
    args.Notify = true;
 
    string body = "Dear " + ui.DisplayName + "<br /><br />We are pleased to announce that you are registered in our website. If you need any assist, don't hesitate to contact us at webmaster@domain.com <br /><br />Thank you.<br /><br />--- Webmaster ---";
 
    string strMessage = DotNetNuke.Services.Mail.Mail.SendMail(
        "webmaster@domain.com",
        ui.Email,
        "", "",
        DotNetNuke.Services.Mail.MailPriority.Normal,
        "New User Registration",
        DotNetNuke.Services.Mail.MailFormat.Html,
        System.Text.Encoding.UTF8,
        body,
        "",
        Host.SMTPServer, Host.SMTPAuthentication, Host.SMTPUsername, Host.SMTPPassword, Host.EnableSMTPSSL);
 
}
else
{
    args = new UserUserControlBase.UserCreatedEventArgs(null);
}
 
args.CreateStatus = createStatus;
 
UserUserControlBase ub = new UserUserControlBase();
ub.OnUserCreated(args);
ub.OnUserCreateCompleted(args);


Thank you for any help.

regards,
yadi
 
New Post
11/23/2010 12:22 AM
 
This forum thread has a good code sample you can borrow from:

http://www.dotnetnuke.com/Community/F...

Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
11/23/2010 2:02 AM
 
Thank you will. Your link is really useful.

I have also something weird with this code:

UserInfo ui = UserController.GetUserByName(PortalId, txtUserName.Text);
 
if (ui == null) // meaning that no user found
{
    Response.Write("Not found");
}
else // user found
{
    Response.Write("found");
}

But the answer is always "found". Meaning that, whatever username I typed the GetUserName method always return NOT NULL. But actually in the database itself there is only one user (the superuser account only).

Thank you for any clue for this.
 
New Post
11/23/2010 2:35 AM
 
uuuh, something weird. If I add new user from code from what Will suggest, it adds in the database. But not show in the Users page. :( Restarting application from the Host won't effect. :(

how could it be?
 
New Post
11/23/2010 2:44 AM
 
Agung

Can you run SQL query like this:

SELECT *
FROM {databaseOwner}{objectQualifier}Users
WHERE username LIKE '%required_name%';

Sure replace required_name with value you are looking for. Then you know user is in DB or not.

Also to answer your previous questions would be good to know what version of DNN do you use?

Sergey
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesThe proper way to create DNN user from codeThe proper way to create DNN user from code


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