using System;
using System.Configuration.Provider;
namespace PetShop.Membership {
class OracleMembershipProvider : MembershipProvider
{
string password, string email, string passwordQuestion,
string passwordAnswer, bool isApproved, object userId,
out MembershipCreateStatus status) {
// create connection
OracleConnection connection =
new OracleConnection(OracleHelper.ConnectionStringMembership);
connection.Open();
OracleTransaction transaction =
connection.BeginTransaction(IsolationLevel.ReadCommitted);
try {
DateTime dt = DateTime.Now;
bool isUserNew = true;
// Step 1: Check if the user exists in the Users
// table: Create if not
int uid = GetUserID(transaction, applicationId, username,
true,
false, dt, out isUserNew);
if (uid == 0) { // User not created successfully!
status = MembershipCreateStatus.ProviderError;
return null;
}
// Step 2: Check if the user exists in the Membership
table: Error
// if yes
if (IsUserInMembership(transaction, uid)) {
status = MembershipCreateStatus.DuplicateUserName;
return null;
}
// Step 3: Check if Email is duplicate
if (IsEmailInMembership(transaction, email, applicationId))
{
status = MembershipCreateStatus.DuplicateEmail;
return null;
}
// Step 4: Create user in Membership table
int pFormat = (int)passwordFormat;
if (!InsertUser(transaction, uid, email, pass, pFormat,
salt, "",
"", isApproved, dt)) {
status = MembershipCreateStatus.ProviderError;
return null;
}
// Step 5: Update activity date if user is not new
if(!isUserNew) {
if(!UpdateLastActivityDate(transaction, uid, dt)) {
status = MembershipCreateStatus.ProviderError;
return null;
}
}
status = MembershipCreateStatus.Success;
return new MembershipUser(this.Name, username, uid,
email,
passwordQuestion, null, isApproved,
false, dt, dt, dt, dt, DateTime.MinValue);
}
catch(Exception) {
if(status == MembershipCreateStatus.Success)
status = MembershipCreateStatus.ProviderError;
throw;
}
finally {
if(status == MembershipCreateStatus.Success)
transaction.Commit();
else
transaction.Rollback();
connection.Close();
connection.Dispose();
}
} |