当前位置: 首页>>代码示例>>C#>>正文


C# Authenticator.CreateUsername方法代码示例

本文整理汇总了C#中Authenticator.CreateUsername方法的典型用法代码示例。如果您正苦于以下问题:C# Authenticator.CreateUsername方法的具体用法?C# Authenticator.CreateUsername怎么用?C# Authenticator.CreateUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Authenticator的用法示例。


在下文中一共展示了Authenticator.CreateUsername方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateLogin

        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;
        }
开发者ID:0huah0,项目名称:csharp-samples,代码行数:100,代码来源:MembershipLogic.cs


注:本文中的Authenticator.CreateUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。