When an Umbraco user logs in I would also like them to be authenticated as a member
Pseudo code:
//On successful umbraco login (need to hook into this event)
string UmbracoUserName= //Get username of umbraco user, which will be same as member name //create the authentication ticket
System.Web.Security.FormsAuthenticationTicket authTicket = new System.Web.Security.FormsAuthenticationTicket(1, UmbracoUserName, DateTime.Now, DateTime.Now.AddMinutes(60), false);
// encrypt the ticket
string encryptedTicket = System.Web.Security.FormsAuthentication.Encrypt(authTicket);
// create a cookie and add the encrypted ticket to the cookie as data
HttpCookie authCookie = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, encryptedTicket);
// add the cookie to the cookies collection returned to the user's browser
Response.Cookies.Add(authCookie);
I'm integrating an existing .net site into a new custom section, umbraco users need access to the Umbraco content and also certain parts of the new custom section which is set by membership roles.
I'd probably extend the Umbraco Users membership provider so that when a user successfully logs in, you then issue the same command to the Members membership provider aswell.
I'm not sure if it would work, but you could also try using one membership provider for both Users and Members (in the web.config).
2. Create a class which inherits from the previous interface:
namespace yournamespace { /// /// Summary description for FormsAuthentication /// public class FormsAuthenticationService : IFormsAuthenticationService { /// /// /// /// /// public void SignIn(string userName, bool createPersistentCookie) { if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
public class MemberProfile : ProfileBase { public MemberProfile() { // // TODO: Add constructor logic here // }
[SettingsAllowAnonymous(false)] // Back End User of the Member we want to log in public string User { get { var o = base.GetPropertyValue("user"); if (o == DBNull.Value) { return string.Empty; } return (string)o; } set { base.SetPropertyValue("nombre", value); } } } }
4. Run this function to log in the member just before user is authenticated.
This authenticate the member through ASP.NET provider:
public void LoginMember() {
var usr = Member.GetMemberFromLoginName("login");
if (usr != null) { if (System.Web.Security.Membership.ValidateUser(usr.Value, usr.Password)) { BeComputed.IFormsAuthenticationService FormsService = new BeComputed.FormsAuthenticationService(); FormsService.SignIn(usr.LoginName, true); } } }
Remember to inherit your DLL in the member provider section in Web Config.
Sync user and member login
Hi,
When an Umbraco user logs in I would also like them to be authenticated as a member
Pseudo code:
I'm integrating an existing .net site into a new custom section, umbraco users need access to the Umbraco content and also certain parts of the new custom section which is set by membership roles.
Appreciate any help
Thanks
Rich
Hey Rich,
I'd probably extend the Umbraco Users membership provider so that when a user successfully logs in, you then issue the same command to the Members membership provider aswell.
I'm not sure if it would work, but you could also try using one membership provider for both Users and Members (in the web.config).
Matt
Hi Rich,
I did this before through a custom profile
1. Create a new Library Class project with visual studio
Create an interface:
2. Create a class which inherits from the previous interface:
3. Create a new profile, for example:
4. Run this function to log in the member just before user is authenticated.
This authenticate the member through ASP.NET provider:
Remember to inherit your DLL in the member provider section in Web Config.
HTH.
Sincere regards,
Eduardo Macho
is working on a reply...