Ejemplo n.º 1
0
 public IActionResult Post([FromBody] User user)
 {
     if (ModelState.IsValid)
     {
         if (!UserDataBase.AddUser(user))
         {
             return(BadRequest());
         }
         return(Created(Url.Action("Post", user.Email), user));
     }
     return(BadRequest());
 }
Ejemplo n.º 2
0
        public void AddUser(User user)
        {
            CheckRequired(user);

            if (IsExist(user))
            {
                throw new UserExistsException("Данный пользователь уже зарегестриован.");
            }

            try
            {
                _userDataBase.AddUser(user);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Произошла ошибка. {ex.Message}");
            }
        }
        public void LogIn()
        {
            var flag     = false;
            var login    = string.Empty;
            var password = string.Empty;

            do
            {
                flag = true;
                Console.WriteLine("Login: "******"exit"))
                {
                    flag = false;
                    continue;
                }

                Console.WriteLine("Password: "******"exit"))
                {
                    flag = false;
                    continue;
                }


                if (login.Contains("@"))
                {
                    var newUser = new User()
                    {
                        Email = login, Password = password
                    };
                    if (!_authenticatorByEmail.AuthenticateUser(newUser))
                    {
                        Console.WriteLine("Name: ");
                        var name = Console.ReadLine();
                        if (string.Equals(name, "exit"))
                        {
                            flag = false;
                            continue;
                        }
                        newUser.Name = name;
                        _userDataBase.AddUser(newUser);
                    }
                }
                else
                {
                    var newUser = new User()
                    {
                        Name = login, Password = password
                    };
                    if (!_authenticatorByName.AuthenticateUser(newUser))
                    {
                        Console.WriteLine("Email: ");
                        var email = Console.ReadLine();
                        if (string.Equals(email, "exit") || !email.Contains("@"))
                        {
                            flag = false;
                            continue;
                        }
                        newUser.Email = email;
                        _userDataBase.AddUser(newUser);
                    }
                }
            }while (flag);
        }