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.