コード例 #1
0
        public static async Task <object> GetAccessCustomer(string customerId, IAccountRepository accountRepository, ILoginUserService loginUserService)
        {
            Guid CustomerId;
            Guid guid;
            bool IsEmail = Regex.IsMatch(customerId, @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", RegexOptions.IgnoreCase);
            bool IsPhone = Regex.IsMatch(customerId, @"^[0-9]{10}$", RegexOptions.IgnoreCase);
            bool IsGuid  = Guid.TryParse(customerId, out guid);

            if (IsEmail)
            {
                var isEmailExist = await loginUserService.GetEmailUser(customerId);

                if (isEmailExist != null)
                {
                    CustomerId = Guid.Parse(isEmailExist.Id);
                    return(CustomerId);
                }
                else
                {
                    return("Email Not Found");
                }
            }

            else if (IsPhone)
            {
                var isPhoneExist = await loginUserService.GetMobileUser(customerId);

                if (isPhoneExist != null)
                {
                    CustomerId = Guid.Parse(isPhoneExist.Id);
                    return(CustomerId);
                }
                else
                {
                    return("Mobile Number Is Not Found");
                }
            }
            else if (IsGuid)
            {
                CustomerId = Guid.Parse(customerId);
                return(CustomerId);
            }

            else if (!IsPhone && !IsEmail && !IsGuid)
            {
                var isUserNameExist = await loginUserService.GetNameUser(customerId);

                if (isUserNameExist != null)
                {
                    CustomerId = Guid.Parse(isUserNameExist.Id);
                    return(CustomerId);
                }
                else
                {
                    return("UserName Is Not Found");
                }
            }
            else
            {
                return("UnExpected Error");
            }
        }
コード例 #2
0
        public async Task Execute(Input input)
        {
            if (input == null)
            {
                outputHandler.Error("Input is null.");
                return;
            }
            bool IsEmail = Regex.IsMatch(input.Name.ToString(), @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", RegexOptions.IgnoreCase);
            bool IsPhone = Regex.IsMatch(input.Name.ToString(), @"^[0-9]{10}$", RegexOptions.IgnoreCase);

            if (IsEmail)
            {
                var isEmailExist = await loginUserService.GetEmailUser(input.Name.ToString());

                if (isEmailExist != null)
                {
                    var loginOutput = loginUserService.Execute(isEmailExist, input.Password.ToString());
                    if (loginOutput == null)
                    {
                        outputHandler.Error("An error throw when Login with user password");
                        return;
                    }

                    Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);
                    outputHandler.Handle(output);
                }
                else
                {
                    outputHandler.Error("Email Not Found");
                }
            }

            else if (IsPhone)
            {
                var isPhoneExist = await loginUserService.GetMobileUser(input.Name.ToString());

                if (isPhoneExist != null)
                {
                    var loginOutput = loginUserService.Execute(isPhoneExist, input.Password.ToString());
                    if (loginOutput == null)
                    {
                        outputHandler.Error("An error throw when Login with user password");
                        return;
                    }

                    Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);
                    outputHandler.Handle(output);
                }
                else
                {
                    outputHandler.Error("Mobile Number Is Not Found");
                }
            }

            else if (!IsPhone && !IsEmail)
            {
                var isUserNameExist = await loginUserService.GetNameUser(input.Name.ToString());

                if (isUserNameExist != null)
                {
                    var loginOutput = loginUserService.Execute(isUserNameExist, input.Password.ToString());
                    if (loginOutput == null)
                    {
                        outputHandler.Error("An error throw when Login with user password");
                        return;
                    }

                    Output output = new Output(loginOutput.CustomerId, loginOutput.Name, loginOutput.Token);
                    outputHandler.Handle(output);
                }
                else
                {
                    outputHandler.Error("UserName Is Not Found");
                }
            }
            else
            {
                outputHandler.Error("UnExpected Error");
            }
        }