public class MyMembership : System.Web.Security.MembershipProvider
{
private string pApplicationName = "";
public override string ApplicationName
{
get { return pApplicationName; }
set { pApplicationName = value; }
}
private int pMaxInvalidPasswordAttempts = 0;
public override int MaxInvalidPasswordAttempts
{
get { return pMaxInvalidPasswordAttempts; }
}
private int pMinRequiredNonAlphanumericCharacters = 0;
public override int MinRequiredNonAlphanumericCharacters
{
get { return pMinRequiredNonAlphanumericCharacters; }
}
private int pMinRequiredPasswordLength = 0;
public override int MinRequiredPasswordLength
{
get { return pMinRequiredPasswordLength; }
}
private int pPasswordAttemptWindow = 0;
public override int PasswordAttemptWindow
{
get { return pPasswordAttemptWindow; }
}
private MembershipPasswordFormat pPasswordFormat = MembershipPasswordFormat.Clear;
public override System.Web.Security.MembershipPasswordFormat PasswordFormat
{
get { return pPasswordFormat; }
}
private string pPasswordStrengthRegularExpression = "";
public override string PasswordStrengthRegularExpression
{
get { return pPasswordStrengthRegularExpression; }
}
private bool pRequiresQuestionAndAnswer = false;
public override bool RequiresQuestionAndAnswer
{
get { return pRequiresQuestionAndAnswer; }
}
private bool pRequiresUniqueEmail = false;
public override bool RequiresUniqueEmail
{
get { return pRequiresUniqueEmail; }
}
private bool pEnablePasswordReset = false;
public override bool EnablePasswordReset
{
get { return pEnablePasswordReset; }
}
private bool pEnablePasswordRetrieval = false;
public override bool EnablePasswordRetrieval
{
get { return pEnablePasswordRetrieval; }
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new NotImplementedException();
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new NotImplementedException();
}
public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status)
{
throw new NotImplementedException();
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new NotImplementedException();
}
public override System.Web.Security.MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
// Valido que el email introducido contenga la @
if (!emailToMatch.Contains("@"))
{
totalRecords = 0;
return null;
}
// Mediante el uso de un servicio WCF obtengo los usuarios que coincidan con el email especificado.
using (var service = new WCFUser.ServiceUserClient())
{
var users = service.FindByEmail(emailToMatch);
MembershipUserCollection mUsers = new MembershipUserCollection();
foreach (WCFUser.User user in users)
{
MembershipUser mUser = new MembershipUser("MySecurityMembershipProvider",
user.Name,
user.Username,
user.Email,
"",
"",
true,
false,
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime());
mUsers.Add(mUser);
}
totalRecords = mUsers.Count;
return mUsers;
}
}
public override System.Web.Security.MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
// Mediante el uso de un servicio WCF obtengo los usuarios que coincidan con el username especificado.
using (var service = new WCFUser.ServiceUserClient())
{
var users = service.FindByName(usernameToMatch);
MembershipUserCollection mUsers = new MembershipUserCollection();
foreach (WCFUser.User user in users)
{
MembershipUser mUser = new MembershipUser("MySecurityMembershipProvider",
user.Name,
user.Username,
user.Email,
"",
"",
true,
false,
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime());
mUsers.Add(mUser);
}
totalRecords = mUsers.Count;
return mUsers;
}
}
public override System.Web.Security.MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
throw new NotImplementedException();
}
public override int GetNumberOfUsersOnline()
{
throw new NotImplementedException();
}
public override string GetPassword(string username, string answer)
{
throw new NotImplementedException();
}
public override System.Web.Security.MembershipUser GetUser(string username, bool userIsOnline)
{
// Mediante el uso de un servicio WCF obtengo el usuario.
using (var service = new WCFUser.ServiceUserClient())
{
WCFUser.User user = service.GetUser(username);
MembershipUser mUser = new MembershipUser("MySecurityMembershipProvider",
user.Name,
user.Username,
user.Email,
"",
"",
true,
false,
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime());
return mUser;
}
}
public override System.Web.Security.MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
// Mediante el uso de un servicio WCF obtengo el usuario.
using (var service = new WCFUser.ServiceUserClient())
{
WCFUser.User user = service.GetUser(providerUserKey.ToString());
MembershipUser mUser = new MembershipUser("MySecurityMembershipProvider",
user.Name,
user.Username,
user.Email,
"",
"",
true,
false,
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime(),
DateTime.Now.ToLocalTime());
return mUser;
}
}
public override string GetUserNameByEmail(string email)
{
// Mediante el uso de un servicio WCF obtengo el usuario.
using (var service = new WCFUser.ServiceUserClient())
{
return service.GetUsernameByEmail(email);
}
}
public override string ResetPassword(string username, string answer)
{
throw new NotImplementedException();
}
public override bool UnlockUser(string userName)
{
throw new NotImplementedException();
}
public override void UpdateUser(System.Web.Security.MembershipUser user)
{
throw new NotImplementedException();
}
public override bool ValidateUser(string username, string password)
{
// Mediante el uso de un servicio WCF realizo la validación del usuario
using (var service = new WCFUser.ServiceUserClient())
{
return service.Validate(username, password);
}
}
}