Esempio n. 1
0
        // Checks User Credentials
        public static ResponseType IsValidUser(UserBase user)
        {
            //Check that we have an account
            if (user == null || String.IsNullOrWhiteSpace(user.UserName))
            {
                return(ResponseType.AccountInvalid);
            }

            // Check that passwords match
            if (String.IsNullOrWhiteSpace(user.Password))
            {
                return(ResponseType.PasswordEmpty);
            }

            // Check that the account exists
            if (!IsValidUserName(user.UserName))
            {
                return(ResponseType.AccountInvalid);
            }

            // We found the account
            var value = QsDataRepository.GetAllUsers().First(x => x.UserName == user.UserName);

            if (value != null)
            {
                return(CheckPass(user.Password, value) ? ResponseType.AccountSuccess : ResponseType.AccountInvalid);
            }
            return(ResponseType.AccountInvalid);
        }
Esempio n. 2
0
 // Is valid user account, by ID
 public static User IsValidUserId(string userId)
 {
     try
     {
         return(QsDataRepository.GetAllUsers().First(x => x.UserId.Equals(new Guid(userId))));
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 3
0
 //Is valid user account, userName to get pasword
 public static string IsValidUserPassword(string userName)
 {
     try
     {
         var result = QsDataRepository.GetAllUsers().First(x => x.UserName.Equals(userName));
         return(result.Password);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 4
0
 // Is valid user account, by Name
 public static bool IsValidUserName(string userName)
 {
     try
     {
         var result = QsDataRepository.GetAllUsers().First(x => x.UserName.Equals(userName));
         return(result != null);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
        // Creates token
        public static object GetUserToken(UserBase user, string ipAddress)
        {
            // Check that the account exists
            if (!IsValidUserName(user.UserName))
            {
                return(ResponseType.AccountInvalid);
            }

            // We found the account
            var value = QsDataRepository.GetAllUsers().First(x => x.UserName.Equals(user.UserName));

            if (value != null)
            {
                return(new { Token = new Token(value.UserId.ToString(), ipAddress).Encrypt() });
            }
            return(ResponseType.AccountInvalid);
        }
        public HttpResponseMessage GetAllUsers()
        {
            IList <User> result = QsDataRepository.GetAllUsers();

            return(Request.CreateResponse(result.Any() ? HttpStatusCode.OK : HttpStatusCode.NotFound, result));
        }