Ejemplo n.º 1
0
        public void TestMethod_SignUpWithEmail_SuccessRegistration()
        {
            //Arrange
            var dbContext = InMemoryDatabaseFactory.Create();
            AccountRegistrationService registrationService = new AccountRegistrationService(dbContext);
            EmailLoginInfo             emailLoginInfo      = new EmailLoginInfo
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            string name = "Muhammad";

            //Act
            registrationService.RegisterAccountAsync(name, emailLoginInfo).Wait();

            //Assert
            var account = dbContext.Accounts
                          .Include(account1 => account1.EmailLoginInfo)
                          .Include(account1 => account1.OrderStatusGroups)
                          .First();

            Assert.AreEqual(name, account.Name);
            Assert.AreEqual(emailLoginInfo.Email, account.EmailLoginInfo.Email);
            Assert.AreEqual(emailLoginInfo.Password, account.EmailLoginInfo.Password);
            Assert.IsTrue(account.OrderStatusGroups.Count > 0);
        }
        public async Task TestMethod_SignUpWithEmail_SuccessRegistration()
        {
            //Arrange
            AccountRegistrationService registrationService = new AccountRegistrationService(dbContext);
            EmailLoginInfo             emailLoginInfo      = new EmailLoginInfo
            {
                Email    = "kashdvbkjsahdvb",
                Password = "******"
            };
            string name = "Muhammad";

            //Act
            await registrationService.RegisterAccountAsync(name, emailLoginInfo);

            //Assert
            var emailLoginDb = await dbContext.EmailLoginInfo
                               .Include(info => info.Account)
                               .ThenInclude(account1 => account1.OrderStatusGroups)
                               .Where(loginInfo => loginInfo.Email == emailLoginInfo.Email)
                               .SingleAsync();

            var accountDb = emailLoginDb.Account;

            Assert.AreEqual(name, accountDb.Name);
            Assert.AreEqual(emailLoginInfo.Email, accountDb.EmailLoginInfo.Email);
            Assert.AreEqual(emailLoginInfo.Password, accountDb.EmailLoginInfo.Password);
            Assert.IsTrue(accountDb.OrderStatusGroups.Count > 0);
        }
        private async Task <Account> RegisterAccountAsync(string name, EmailLoginInfo emailLoginInfo, TelegramLoginInfo telegramLoginInfo)
        {
            //TODO добавить сервисы для проверки входных данных
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(nameof(name));
            }

            if (!LoginInfoCheckService.HasOneLoginInfo(emailLoginInfo, telegramLoginInfo))
            {
                throw new Exception("empty login info");
            }

            var account = new Account
            {
                Name              = name,
                RegistrationDate  = DateTime.UtcNow,
                Money             = 49.99M,
                EmailLoginInfo    = emailLoginInfo,
                TelegramLoginInfo = telegramLoginInfo,
                OrderStatusGroups =
                {
                    new OrderStatusGroup
                    {
                        Name          = "Стандартный набор статусов",
                        OrderStatuses = new[]
                        {
                            new OrderStatus {
                                Name = "Просмотрено", Message = ""
                            },
                            new OrderStatus {
                                Name = "⏳В обработке", Message = "⏳Ваш заказ находится в обработке."
                            },
                            new OrderStatus {
                                Name = "🚚В пути", Message = "🚚Ваш заказ в пути."
                            },
                            new OrderStatus {
                                Name = "✅Принят", Message = "✅Ваш заказ был принят."
                            },
                            new OrderStatus {
                                Name = "❌Отменён", Message = "❌Ваш заказ был отменён."
                            }
                        }
                    }
                }
            };

            await dbContext.Accounts.AddAsync(account);

            await dbContext.SaveChangesAsync();

            return(account);
        }
        public static bool HasOneLoginInfo([CanBeNull] EmailLoginInfo emailLoginInfo,
                                           [CanBeNull] TelegramLoginInfo telegramLoginInfo)
        {
            if (telegramLoginInfo != null)
            {
                return(true);
            }

            if (emailLoginInfo != null)
            {
                CheckEmailLoginInfo(emailLoginInfo);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Login([FromBody] EmailLoginInfo emailLoginInfo)
        {
            try
            {
                var user = await authenticationManager.Authenticate(emailLoginInfo);

                var sid = await userCookieManager.SetLoginCookie(Response, user);

                logger.LogInformation($"Успешный вход по логин-паролю {emailLoginInfo.Email}. sessionId {sid}");
                return(Json(user));
            }
            catch (AuthenticationFailedException)
            {
                return(Unauthorized());
            }
        }
        private static void CheckEmailLoginInfo([NotNull] EmailLoginInfo emailLoginInfo)
        {
            if (emailLoginInfo == null)
            {
                throw new ArgumentNullException(nameof(emailLoginInfo));
            }

            if (emailLoginInfo.Email == null)
            {
                throw new NullReferenceException(nameof(emailLoginInfo.Email));
            }

            if (emailLoginInfo.Password == null)
            {
                throw new NullReferenceException(nameof(emailLoginInfo.Password));
            }

            if (!PasswordIsOk(emailLoginInfo.Password))
            {
                throw new Exception("Bad password");
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> EmailCheckSuccess(Guid guid, [FromQuery(Name = "email")] string email)
        {
            var tmpAccount = context.TemporaryAccountWithUsernameAndPassword.
                             FirstOrDefault(tmp => tmp.Email == email);

            if (tmpAccount != null)
            {
                Guid guidFromDb = tmpAccount.Guid;
                if (guidFromDb == guid)
                {
                    var emailPasswordLoginInfo = new EmailLoginInfo
                    {
                        Email    = tmpAccount.Email,
                        Password = tmpAccount.Password
                    };

                    await registrationService.RegisterAccountAsync(tmpAccount.Name, emailPasswordLoginInfo);

                    context.TemporaryAccountWithUsernameAndPassword.Remove(tmpAccount);
                    await context.SaveChangesAsync();


                    string message = "Поздравляем, ваш email подтверждён";
                    return(RedirectToAction("Success", "StaticMessage", new { message }));
                }
                else
                {
                    string message = "В системе нет запроса на регистрацию акканута с таким идентификатором";
                    return(RedirectToAction("Failure", "StaticMessage", new { message }));
                }
            }
            else
            {
                string message = "В системе нет запроса на регистрацию такого акканута";
                return(RedirectToAction("Failure", "StaticMessage", new { message }));
            }
        }
 public async Task <Account> RegisterAccountAsync(string name, EmailLoginInfo emailLoginInfo)
 {
     return(await RegisterAccountAsync(name, emailLoginInfo, null));
 }