public static BaseResponse CreateLogin(CreateLoginRequest ahRequest) { return GetResponse(Methods.CREATELOGIN, ahRequest); }
public BaseResponse CreateLogin(string memberId, string userName, string initialPassword, string postalCode) { methodName = "CreateLogin"; List<Message> errors = new List<Message>(); string errortext = string.Empty; try { #region validate input // All params are required if ((memberId.Trim() == "") || (userName.Trim() == "") || (initialPassword.Trim() == "") || (postalCode.Trim() == "")) { errors.Add(new Message("ImproperValidationCriteriaException")); } using (HarperLINQ.AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString)) { string exception = string.Empty; bool exists = false; int existing = (from a in context.tbl_Customers join b in context.SFG_CustomerNumbers on a.cusID equals b.cusID where a.cusUserName == userName.Trim() && b.SFGCustNum != memberId.Trim() select a).Count(); if (existing > 0) { exists = true; exception = "User name is in use."; } existing = 0; existing = (from a in context.tbl_Customers join b in context.SFG_CustomerNumbers on a.cusID equals b.cusID where a.cusDisplayName == userName.Trim() && b.SFGCustNum != memberId.Trim() select a).Count(); if (existing > 0) { exists = true; exception += " Screen name is in use."; } existing = 0; existing = (from a in context.tbl_Customers join b in context.SFG_CustomerNumbers on a.cusID equals b.cusID where a.cusEmail == userName.Trim() && b.SFGCustNum != memberId.Trim() select a).Count(); if (existing > 0) { exists = true; exception += "Email address is in use."; } if (exists) { throw new Exception(exception); } } #endregion CreateLoginRequest request = new CreateLoginRequest(memberId.Trim(), userName.Trim(), initialPassword.Trim(), postalCode.Trim(), false); baseResponse = UserMaintenance.CreateLogin(request); if (baseResponse != null && baseResponse.TypedResponse != null && baseResponse.TypedResponse.GetType().Name == "CreateLoginResponse" && (baseResponse.TypedResponse as CreateLoginResponse).Success) { HarperACL.Authenticator auth = new Authenticator(userName.Trim(), Cryptography.Hash(initialPassword.Trim(),true), true, true, false, memberId.Trim()); if (!auth.CreateUsername(userName.Trim(), initialPassword.Trim(), memberId.Trim())) { throw new Exception("User created at SFG, could not create user at AH"); } } } catch (Exception ex) { errortext = string.Format("Error creating login. Memberid: {0} Username: {1} Password: {2} PostalCode: {3} \r\nException message: {4}\r\nException stacktrace: {5}", new object[] { memberId, userName, initialPassword, postalCode, ex.Message, ex.StackTrace }); errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateLoginException", errortext, "", "", null)); } foreach (Message error in errors) { if (baseResponse == null) { baseResponse = new BaseResponse(); } baseResponse.Messages.Add(error); StringBuilder error_text = new StringBuilder(); error_text.AppendLine("CREATELOGIN ERROR LOGGED"); error_text.AppendLine(string.Format("MEMBERID {0}", memberId)); baseResponse.Messages.Add(error); error_text.AppendLine(string.Format("ERROR: {0}", new object[] { error.AhMessage})); EventLogger.LogError("MembershipLogic.CreateLogin", error_text.ToString(), true); } return baseResponse; }