Example #1
0
        public LoginResult Login(string loginName, string password, bool passwordIsEncrypted)
        {
            UserProfile userProfile =
                UserProfileDao.FindByLoginName(loginName);

            String storedPassword = userProfile.enPassword;

            if (passwordIsEncrypted)
            {
                if (!password.Equals(storedPassword))
                {
                    throw new IncorrectPasswordException(loginName);
                }
            }
            else
            {
                if (!PasswordEncrypter.IsClearPasswordCorrect(password,
                                                              storedPassword))
                {
                    throw new IncorrectPasswordException(loginName);
                }
            }

            return(new LoginResult(userProfile.usrId, userProfile.firstName,
                                   storedPassword, userProfile.language, userProfile.country));
        }
Example #2
0
        public long RegisterUser(string loginName, string clearPassword,
                                 UserProfileDetails userProfileDetails)
        {
            try
            {
                UserProfileDao.FindByLoginName(loginName);

                throw new DuplicateInstanceException(loginName,
                                                     typeof(UserProfile).FullName);
            }
            catch (InstanceNotFoundException)
            {
                String encryptedPassword = PasswordEncrypter.Crypt(clearPassword);

                UserProfile userProfile = new UserProfile();

                userProfile.loginName  = loginName;
                userProfile.enPassword = encryptedPassword;
                userProfile.firstName  = userProfileDetails.FirstName;
                userProfile.lastName   = userProfileDetails.Lastname;
                userProfile.email      = userProfileDetails.Email;
                userProfile.language   = userProfileDetails.Language;
                userProfile.country    = userProfileDetails.Country;

                UserProfileDao.Create(userProfile);

                return(userProfile.usrId);
            }
        }
Example #3
0
        /// <summary>
        /// Checks if the specified loginName corresponds to a valid user.
        /// </summary>
        /// <param name="loginName"> User loginName. </param>
        /// <returns> Boolean to indicate if the loginName exists </returns>
        public bool UserExists(string loginName)
        {
            try
            {
                UserProfile userProfile = UserProfileDao.FindByLoginName(loginName);
            }
            catch (InstanceNotFoundException)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Check if User exists, if not throw exception
        /// </summary>
        /// <param name="loginName"><c>loginName</c> User login name.</param>
        /// <returns>UserProfile.</returns>
        /// <exception cref="UserNotFoundException"/>
        private UserProfile CheckUser(string loginName)
        {
            UserProfile user;

            try
            {
                user = UserProfileDao.FindByLoginName(loginName);
            }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }
            return(user);
        }
Example #5
0
        public LoginResult Login(String loginName, String password,
                                 Boolean passwordIsEncrypted)
        {
            UserProfile userProfile =
                UserProfileDao.FindByLoginName(loginName);

            String storedPassword = userProfile.enPassword;

            if (passwordIsEncrypted)
            {
                if (!password.Equals(storedPassword))
                {
                    throw new IncorrectPasswordException(loginName);
                }
            }
            else
            {
                if (!PasswordEncrypter.IsClearPasswordCorrect(password,
                                                              storedPassword))
                {
                    throw new IncorrectPasswordException(loginName);
                }
            }

            try
            {
                CreditCard card = creditCardDao.FindDefaultUserIdCard(userProfile.usrId);

                return(new LoginResult(userProfile.usrId, userProfile.firstName,
                                       storedPassword, userProfile.language, userProfile.country, userProfile.role, userProfile.address,
                                       card.cardId, card.cardNumber));
            }
            catch (InstanceNotFoundException)
            {
                return(new LoginResult(userProfile.usrId, userProfile.firstName,
                                       storedPassword, userProfile.language, userProfile.country, userProfile.role, userProfile.address));
            }
        }
Example #6
0
        public UserProfile FindUserByLoginName(string login)
        {
            UserProfile u = UserProfileDao.FindByLoginName(login);

            return(u);
        }