예제 #1
0
        public static List <Authouriser> getAllUsersCreditials(IAuthDataMapper authDataMapper = null)
        {
            List <Authouriser> results = new List <Authouriser>();

            if (authDataMapper == null)
            {
                authDataMapper = new AuthDataMapper();
            }

            results = authDataMapper.getAllUsersFromTheDatabase();

            if (results == null)
            {
                throw new ArgumentNullException("The system have no users registered currently, please reister");
            }
            else
            {
                return(results);
            }
        }
예제 #2
0
        public static string resetUserCreditials(string username, string password, IAuthDataMapper authDataMapper = null)
        {
            if (authDataMapper == null)
            {
                authDataMapper = new AuthDataMapper();
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("Username can not be empty");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password can not be empty");
            }

            if (!authDataMapper.usernameExistInTheDatabase(username))
            {
                string message = string.Format("The username {0} is not registered", username);
                throw new ArgumentException(message);
            }

            if (!Validator.emailIsValid(username))
            {
                string message = string.Format("The email address {0} is invalid ", username);
                throw new ArgumentException(message);
            }
            int?results = authDataMapper.resetUserPasswordFromDatabase(username, password);

            if (results > 0)
            {
                string message = string.Format("Successfully updated user {0}", username);
                return(message);
            }
            else
            {
                string message = string.Format("Failed to update user {0}", username);
                return(message);
            }
        }
예제 #3
0
        public static Authouriser getUserCreditials(string username, IAuthDataMapper authDataMapper = null)
        {
            Authouriser results = new Authouriser();

            if (authDataMapper == null)
            {
                authDataMapper = new AuthDataMapper();
            }

            results = authDataMapper.getUserFromTheDatabase(username);

            if (results == null)
            {
                string message = string.Format("The user {0} is not registered, please reister", username);
                throw new ArgumentNullException(message);
            }
            else
            {
                return(results);
            }
        }
예제 #4
0
        public static string craeteCreditials(string username, string password, IAuthDataMapper authDataMapper = null)
        {
            if (authDataMapper == null)
            {
                authDataMapper = new AuthDataMapper();
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("Username can not be empty");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password can not be empty");
            }

            if (authDataMapper.usernameExistInTheDatabase(username))
            {
                string message = string.Format("The username {0} is already registered", username);
                throw new ArgumentException(message);
            }

            if (!Validator.emailIsValid(username))
            {
                string message = string.Format("The email address {0} is invalid ", username);
                throw new ArgumentException(message);
            }
            int?results = authDataMapper.insertUserNewToDatabase(username, password);

            if (results > 0)
            {
                return("Please check your email to complete your registeration");
            }
            else
            {
                return("Outch.. something went wrong, try again later");
            }
        }
예제 #5
0
        // Unsubscribe user
        public static string unsubscribeUser(string username, string password, IAuthDataMapper authDataMapper = null)
        {
            if (authDataMapper == null)
            {
                authDataMapper = new AuthDataMapper();
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("Username can not be empty");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password can not be empty");
            }

            if (!authDataMapper.usernameExistInTheDatabase(username))
            {
                string message = string.Format("The username {0} is not registered", username);
                throw new ArgumentException(message);
            }
            return(authDataMapper.deleteUserFromDatabase(username, password));
        }