API
Version 7.x > API > User Enabled after Custom Registration View modes: 
User avatar
Member
Member
gmac - 7/24/2013 10:26:53 AM
   
User Enabled after Custom Registration
I am registering a user manually, without the registration or custom registration webpart from kentico. These two things are not an option for this project. I want to enable the user after They are registered and created in the database. Registration is successful. I am using ui.Enabled = true. but it is not enabling the user when I redirect to the next page.
	ui.SetValue("FirstName", txtGivenName.Text);
ui.SetValue("LastName", txtFamilyName.Text);
ui.SetValue("FullName", txtGivenName.Text + " " + txtFamilyName.Text);
ui.SetValue("UserName", txtUsername.Text);
ui.SetValue("Email", txtEmail.Text);
ui.SetValue("Phone", txtPhone.Text);
ui.SetValue("DOB", _dob);
ui.SetValue("Citizenship", _citizenship);
ui.SetValue("Gender", _gender);


UserInfoProvider.SetUserInfo(ui);

UserInfoProvider.SetPassword(ui, txtPassword.Text);

UserSiteInfoProvider.AddUserToSite(ui.UserID, CMSContext.CurrentSite.SiteID);

ui.Enabled = true;

User avatar
Certified Developer 8
Certified Developer 8
Petr Dvorak - 7/24/2013 1:15:50 PM
   
RE:User Enabled after Custom Registration
Try calling ui.Update() to persist the modification:
ui.Enabled = true;
ui.Update();

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 7/24/2013 4:34:44 PM
   
RE:User Enabled after Custom Registration
Yes,

You should definitely use the Update method at the end to confirm changes.
ui.Update();

Could you please confirm if it fixes your issue?

Best Regards,
Martin Danko

User avatar
Member
Member
gmac - 7/25/2013 7:59:30 AM
   
RE:User Enabled after Custom Registration
This did not work.

User avatar
Member
Member
gmac - 7/25/2013 10:03:29 AM
   
RE:User Enabled after Custom Registration
It seems that the public anonymous user is still enabled

User avatar
Member
Member
kentico_sandroj - 7/30/2013 3:14:04 PM
   
RE:User Enabled after Custom Registration
Hello,

This is what you mentioned in the original post:

"I want to enable the user after They are registered"

Your latest post:

"This did not work. It seems that the public anonymous user is still enabled"

Could you please clarify what you are trying to accomplish? How can a public anonymous user be registered or enabled? Are you checking the database after running this code?


User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/30/2013 8:37:28 PM
   
RE:User Enabled after Custom Registration
When you say enabled do you mean the current users "Enabled" property is not set? OR the user you just created is not logged in or authenticated? If you are saying the new user is not authenticated, add this simple code to authenticate them
if (ui.Enabled)
{
CMSContext.AuthenticateUser(ui.UserName, true);
// might redirect to a new page after this as well
}
You might also want to add them to roles. I'd suggest looking in the code behind of the /CMSWebparts/Membership/Registration/RegistrationForm.asxc.cs file. About line 958 starts talking about setting role values and shortly after that it talks about authenticating the user you just created/registered. This code should help you accomplish what you are attempting.

User avatar
Member
Member
gmac - 7/30/2013 8:42:36 PM
   
RE:User Enabled after Custom Registration
I ended up using the SetCurrentUser method and redirecting to the next page in our workflow and that solved the problem

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/31/2013 6:59:22 AM
   
RE:User Enabled after Custom Registration
Still curious about the enabled vs. authenticated? What you described sounded like authentication.

User avatar
Member
Member
drewr-bpstudios - 9/26/2013 11:51:23 AM
   
RE:User Enabled after Custom Registration
Not sure if this is a still an issue but heres my take:

The api call to set the user as enabled is being made after you set the user object. You need to grab a reference to that user again and then save the info. Otherwise, you are saving the user above and then just pulling up a property and assigning it but not saving it. Another option is to just set ui.Enabled above the UserInfoProvider.SetUserInfo(ui) method.