/// <summary>
        ///
        /// </summary>
        /// <param name="firname"></param>
        /// <param name="surname"></param>
        /// <param name="email"></param>
        /// <param name="dateOfBirth"></param>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public bool AddUser(string firname, string surname, string email, DateTime dateOfBirth, int clientId)
        {
            if (!UserProvidedDataIsValid(firname, surname, email, dateOfBirth))
            {
                return(false);
            }

            var client = _clientRepository.GetById(clientId);

            var user = new User
            {
                Client       = client,
                DateOfBirth  = dateOfBirth,
                EmailAddress = email,
                Firstname    = firname,
                Surname      = surname
            };

            ApplyCreditLimits(client, user);

            if (_userValidator.HasCreditLimitAndLimitIsLessThan500(user))
            {
                return(false);
            }

            _userDataAccess.AddUser(user);

            return(true);
        }
Example #2
0
 public User Register(User user)
 {
     try
     {
         user.Password = _hashGenerator.GenerateHash(user.Password);
         return(_userDataAccess.AddUser(user.NoRoles().NoDateTimeAdd()));
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Encountered an exception while executing UserBusiness.Register");
         return(null);
     }
 }
Example #3
0
 public void AddUser(User user, List <RoleType> roles, Byte[] ImageBytes)
 {
     if (ImageBytes != null)
     {
         user.PicturePath = BytesImage(ImageBytes);
     }
     else
     {
         user.PicturePath = String.Empty;
     }
     user.IsActive = true;
     user.Roles    = roles.Select(r => roleDataAccess.GetRoleByType(r)).ToList();
     userDataAccess.AddUser(user);
 }
        public Session PostNewUser(int id, int userId, string username, string password, DateTime createdDate, DateTime lastActiveAt)
        {
            using (var conn = _dbConnection.GetConnection())
            {
                if (username == "")
                {
                    throw new Exception("empty username");
                }
                if (password == "")
                {
                    throw new Exception("empty password");
                }

                _userDataAccess.AddUser(conn, id, username, password);

                return(_sessionDataAccess.CreateSession(conn, id, userId, lastActiveAt));
            }
        }
Example #5
0
        public User Create(User user, string password)
        {
            if (user == null || string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }

            if (_userDataAccess.UserExists(user.Email))
            {
                throw new Exception($"Username {user.Email} is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _userDataAccess.AddUser(user);
            _userDataAccess.Commit();

            return(user);
        }
Example #6
0
        public IActionResult Register([FromBody] AuthUserModel authUser)
        {
            User user = new User();

            user.Name = authUser.Name;
            if (authUser.Name.Length < 6)
            {
                return(BadRequest("Name too short"));
            }
            if (authUser.Password.Length < 6)
            {
                return(BadRequest("Password too short"));
            }
            try
            {
                userDataAccess.AddUser(user, authUser.Password);
                return(Ok(new { message = "User created" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public bool AddUser(string firname, string surname, string email, DateTime dateOfBirth, int clientId)
        {
            if (string.IsNullOrEmpty(firname) || string.IsNullOrEmpty(surname))
            {
                return(false);
            }

            if (!email.Contains("@") && !email.Contains("."))
            {
                return(false);
            }

            var now = _dateTimeProvider.DateTime;
            int age = now.Year - dateOfBirth.Year;

            if (now.Month < dateOfBirth.Month || (now.Month == dateOfBirth.Month && now.Day < dateOfBirth.Day))
            {
                age--;
            }

            if (age < 21)
            {
                return(false);
            }

            var client = _clientRepository.GetById(clientId);

            var user = new User
            {
                Client       = client,
                DateOfBirth  = dateOfBirth,
                EmailAddress = email,
                Firstname    = firname,
                Surname      = surname
            };

            if (client.Name == "VeryImportantClient")
            {
                // Skip credit check
                user.HasCreditLimit = false;
            }
            else if (client.Name == "ImportantClient")
            {
                // Do credit check and double credit limit
                user.HasCreditLimit = true;
                var creditLimit = _userCreditService.GetCreditLimit(user.Firstname, user.Surname, user.DateOfBirth);
                creditLimit      = creditLimit * 2;
                user.CreditLimit = creditLimit;
            }
            else
            {
                // Do credit check
                user.HasCreditLimit = true;
                var creditLimit = _userCreditService.GetCreditLimit(user.Firstname, user.Surname, user.DateOfBirth);
                user.CreditLimit = creditLimit;
            }

            if (user.HasCreditLimit && user.CreditLimit < 500)
            {
                return(false);
            }

            _userDataAccess.AddUser(user);

            return(true);
        }