Hi, i'm trying to implement my own custom membership provider. The problem i have is that my table i am storing my membership information has some additional fields such as the members address.
I found a tutorial on the internet which has the following
I understand you use the create user wizard control which calls the CreateUser method but how can i get it to include the address details. Would i need to do this manually by setting up my own formview and calling my own method within the class? If this is the case then do i need to do the same for the GetUser and GetAllUsers Methods?
The next thing i can't quite get my head around is that when you create a user or get a user you call MembershipUser method by passing in some values. What does this method do and why does it need to be called when it only accepts a fixed limited number of values?
Appreciate if someone could clear this up for me.
Thanks
I found a tutorial on the internet which has the following
Code:
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
MembershipUser user = new MembershipUser(Name, username, providerUserKey, email, passwordQuestion, null, isApproved, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
string sql = "INSERT INTO USERS(USERNAME,PASSWORD,EMAIL,ISACTIVE) VALUES(@UID,@PWD,@EMAIL,@ISACTIVE)";
db.AddParameter("@UID", username);
db.AddParameter("@PWD", password);
db.AddParameter("@EMAIL", email);
db.AddParameter("@ISACTIVE", (isApproved == true ? "Y" : "N"));
int i = db.ExecuteNonQuery(sql);
if (i > 0)
{
status = MembershipCreateStatus.Success;
return user;
}
else
{
status = MembershipCreateStatus.ProviderError;
return null;
}
}
public override void UpdateUser(MembershipUser user)
{
string sql = "UPDATE USERS SET EMAIL=@EMAIL,ISACTIVE=@ISACTIVE WHERE USERNAME=@UID";
db.AddParameter("@EMAIL", user.Email);
db.AddParameter("@ISACTIVE", (user.IsApproved ? "Y" : "N"));
db.AddParameter("@UID", user.UserName);
int i = db.ExecuteNonQuery(sql);
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
MembershipUser user = null;
string sql = "SELECT * FROM USERS WHERE USERNAME=@UID AND ISACTIVE='Y'";
db.AddParameter("@UID", username);
SqlDataReader reader = (SqlDataReader)db.ExecuteReader(sql);
while (reader.Read())
{
user = new MembershipUser(Name, reader.GetString(reader.GetOrdinal("username")), null, reader.GetString(reader.GetOrdinal("email")), null, null, (reader.GetString(reader.GetOrdinal("isactive")) == "Y" ? true : false), false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
}
reader.Close();
return user;
}
I understand you use the create user wizard control which calls the CreateUser method but how can i get it to include the address details. Would i need to do this manually by setting up my own formview and calling my own method within the class? If this is the case then do i need to do the same for the GetUser and GetAllUsers Methods?
The next thing i can't quite get my head around is that when you create a user or get a user you call MembershipUser method by passing in some values. What does this method do and why does it need to be called when it only accepts a fixed limited number of values?
Appreciate if someone could clear this up for me.
Thanks