Hello,
We would like to create custom user registration page (with the ability to select a specific user role, acknowledge terms etc) and custom login page (with the ability to redirect user to specific pages based on their role, acknowledge terms)
We have attempted a first crack using DotNetNuke API. Are we going in the right direction? How to compile and deploy this code? Should this be a custom module? Can this be hosted as a separate application? Where/How to manage the DB connection string
Can someone please advice/guide on how to proceed? Are there any documentation/samples/videos available?
-----------------------------------------------------------------------------------------------
using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Roles;
protected void btnSubmit_Click(object sender, EventArgs e)
{
UserInfo newUser = new UserInfo();
newUser.Username = "testadd";
newUser.PortalID = 0;
newUser.DisplayName = "ADD DEMO";
newUser.Email = "userdemo@add.com";
newUser.FirstName = "ADD";
newUser.LastName = "DEMO";
UserCreateStatus rc = UserController.CreateUser(ref newUser);
if (rc == UserCreateStatus.Success)
{
// Manual add role to user
addRoleToUser(newUser, "DNNTest", DateTime.MaxValue);
}
}
public bool addRoleToUser(UserInfo user, string roleName, DateTime expiry)
{
bool rc = false;
var roleCtl = new RoleController();
RoleInfo newRole = roleCtl.GetRoleByName(user.PortalID, roleName);
if (newRole != null & user != null)
{
rc = user.IsInRole(roleName);
roleCtl.AddUserRole(user.PortalID, user.UserID, newRole.RoleID, DateTime.MinValue, expiry);
// Refresh user and check if role was added
user = UserController.GetUserById(user.PortalID, user.UserID);
rc = user.IsInRole(roleName);
}
return rc;
}