/// <exception cref="DuplicateInstanceException"/>
        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 =
                    UserProfile.CreateUserProfile(0, loginName, encryptedPassword,
                        userProfileDetails.FirstName, userProfileDetails.Lastname,
                        userProfileDetails.Email);

                UserProfileDao.Create(userProfile);

                return userProfile.usrId;

            }

        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            UserProfileDetails target = (UserProfileDetails)obj;

            return((this.FirstName == target.FirstName) &&
                   (this.Lastname == target.Lastname) &&
                   (this.Email == target.Email) &&
                   (this.Language == target.Language) &&
                   (this.Country == target.Country));
        }
        /// <exception cref="InstanceNotFoundException"/>
        public UserProfileDetails FindUserProfileDetails(long userProfileId)
        {
            UserProfile userProfile = UserProfileDao.Find(userProfileId);

            UserProfileDetails userProfileDetails =
                new UserProfileDetails(userProfile.firstName,
                    userProfile.lastName, userProfile.email);

            return userProfileDetails;
        }
Ejemplo n.º 5
0
        public UserProfileDetails FindUserProfileDetails(long userProfileId)
        {
            UserProfile userProfile = UserProfileDao.Find(userProfileId);

            UserProfileDetails userProfileDetails =
                new UserProfileDetails(userProfile.firstName,
                                       userProfile.lastName, userProfile.email,
                                       userProfile.language, userProfile.country);

            return(userProfileDetails);
        }
Ejemplo n.º 6
0
        public void UpdateUserProfileDetails(long userProfileId,
                                             UserProfileDetails userProfileDetails)
        {
            UserProfile userProfile =
                UserProfileDao.Find(userProfileId);

            userProfile.firstName = userProfileDetails.FirstName;
            userProfile.lastName  = userProfileDetails.Lastname;
            userProfile.email     = userProfileDetails.Email;
            userProfile.language  = userProfileDetails.Language;
            userProfile.country   = userProfileDetails.Country;
            UserProfileDao.Update(userProfile);
        }
        /// <summary>
        /// Loads the languages in the comboBox in the *selectedLanguage*. 
        /// Also, the selectedLanguage will appear selected in the 
        /// ComboBox
        /// </summary>
       /* private void UpdateComboLanguage(String selectedLanguage)
        {
            this.comboLanguage.DataSource = Languages.GetLanguages(selectedLanguage);
            this.comboLanguage.DataTextField = "text";
            this.comboLanguage.DataValueField = "value";
            this.comboLanguage.DataBind();
            this.comboLanguage.SelectedValue = selectedLanguage;
        }*/

        /// <summary>
        /// Loads the countries in the comboBox in the *selectedLanguage*. 
        /// Also, the *selectedCountry* will appear selected in the 
        /// ComboBox
        /// </summary>
       /* private void UpdateComboCountry(String selectedLanguage, String selectedCountry)
        {
            this.comboCountry.DataSource = Countries.GetCountries(selectedLanguage);
            this.comboCountry.DataTextField = "text";
            this.comboCountry.DataValueField = "value";
            this.comboCountry.DataBind();
            this.comboCountry.SelectedValue = selectedCountry;
        }*/

        /// <summary>
        /// Handles the Click event of the btnUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance 
        /// containing the event data.</param>
        protected void BtnUpdateClick(object sender, EventArgs e)
        {

            if (Page.IsValid)
            {
                UserProfileDetails userProfileDetails =
                    new UserProfileDetails(txtFirstName.Text, txtSurname.Text,
                        txtEmail.Text);

                SessionManager.UpdateUserProfileDetails(Context,
                    userProfileDetails);

                Response.Redirect(
                    Response.ApplyAppPathModifier("~/Pages/MainPage.aspx"));

            }
        }
        /// <summary>
        /// Updates the user profile details.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="userProfileDetails">The user profile details.</param>
        public static void UpdateUserProfileDetails(HttpContext context,
            UserProfileDetails userProfileDetails)
        {
            /* Update user's profile details. */

            UserSession userSession=  
                (UserSession)context.Session[USER_SESSION_ATTRIBUTE];           

            userService.UpdateUserProfileDetails(userSession.UserProfileId,
                userProfileDetails);

            /* Update user's session objects. */

            String language = GetLanguageFromBrowserPreferences();
            String country = GetCountryFromBrowserPreferences();

            Locale locale = new Locale(language, country);

            userSession.FirstName = userProfileDetails.FirstName;

            UpdateSessionForAuthenticatedUser(context, userSession, locale);

        }
        /// <summary>
        /// Registers the user.
        /// </summary>
        /// <param name="context">Http Context includes request, response, etc.</param>
        /// <param name="loginName">Username</param>
        /// <param name="clearPassword">Password in clear text</param>
        /// <param name="userProfileDetails">The user profile details.</param>
        /// <exception cref="DuplicateInstanceException"/>
        public static void RegisterUser(HttpContext context, 
            String loginName, String clearPassword,
            UserProfileDetails userProfileDetails)
        {
            
            /* Register user. */
            long usrId = userService.RegisterUser(loginName, clearPassword,
                userProfileDetails);

            /* Insert necessary objects in the session. */
            UserSession userSession = new UserSession();
            userSession.UserProfileId = usrId;
            userSession.FirstName = userProfileDetails.FirstName;

            String language = GetLanguageFromBrowserPreferences();
            String country = GetCountryFromBrowserPreferences();

           Locale locale = new Locale(language,country);

            UpdateSessionForAuthenticatedUser(context, userSession, locale);

            FormsAuthentication.SetAuthCookie(loginName, false);
        }
 /// <exception cref="DuplicateInstanceException"/>
 private long createUserProfile(string loginName)
 {
     UserProfileDetails userProfileDetails = new UserProfileDetails(firstName, lastName, email);
     return userService.RegisterUser(loginName, clearPass, userProfileDetails);
 }
 /// <exception cref="InstanceNotFoundException"/>
 public void UpdateUserProfileDetails(long userProfileId,
     UserProfileDetails userProfileDetails)
 {
     UserProfile userProfile =
         UserProfileDao.Find(userProfileId);
     userProfile.firstName = userProfileDetails.FirstName;
     userProfile.lastName = userProfileDetails.Lastname;
     userProfile.email = userProfileDetails.Email;
     UserProfileDao.Update(userProfile);
 }
        public void UpdateUserProfileDetailsTest()
        {
            // Register user and update profile details
            long userId = userService.RegisterUser(loginName, clearPassword,
                new UserProfileDetails(firstName, lastName, email));

            UserProfileDetails expected =
                    new UserProfileDetails(firstName + "X", lastName + "X",
                        email + "X");

            userService.UpdateUserProfileDetails(userId, expected);

            UserProfileDetails obtained =
                userService.FindUserProfileDetails(userId);

            // Check changes
            Assert.AreEqual(expected, obtained);
        }
        public void FindUserProfileDetailsTest()
        {
            UserProfileDetails expected =
                new UserProfileDetails(firstName, lastName, email);

            long userId =
                userService.RegisterUser(loginName, clearPassword, expected);

            UserProfileDetails obtained =
                   userService.FindUserProfileDetails(userId);

            // Check data
            Assert.AreEqual(expected, obtained);
        }
        //protected void Page_Load(object sender, EventArgs e)
        //{

        //    lblLoginError.Visible = false;

        //    if (!IsPostBack)
        //    {

        //        /* Get current language and country from browser */
        //        String defaultLanguage =
        //            GetLanguageFromBrowserPreferences();
        //        String defaultCountry =
        //            GetCountryFromBrowserPreferences();

        //        /* Combo box initialization */
        //        UpdateComboLanguage(defaultLanguage);
        //        UpdateComboCountry(defaultLanguage, defaultCountry);

        //    }
        //}

        //private String GetLanguageFromBrowserPreferences()
        //{
        //    String language;
        //    CultureInfo cultureInfo =
        //        CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
        //    language = cultureInfo.TwoLetterISOLanguageName;
        //    LogManager.RecordMessage("Preferred language of user" +
        //                             " (based on browser preferences): " + language);
        //    return language;
        //}

        //private String GetCountryFromBrowserPreferences()
        //{
        //    String country;
        //    CultureInfo cultureInfo =
        //        CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

        //    if (cultureInfo.IsNeutralCulture)
        //    {
        //        country = "";
        //    }
        //    else
        //    {
        //        // cultureInfoName is something like en-US
        //        String cultureInfoName = cultureInfo.Name;
        //        // Gets the last two caracters of cultureInfoname
        //        country = cultureInfoName.Substring(cultureInfoName.Length - 2);

        //        LogManager.RecordMessage("Preferred region/country of user " +
        //                                 "(based on browser preferences): " + country);
        //    }

        //    return country;
        //}

        /// <summary>
        /// Loads the languages in the comboBox in the *selectedLanguage*. 
        /// Also, the selectedLanguage will appear selected in the 
        /// ComboBox
        /// </summary>
        //private void UpdateComboLanguage(String selectedLanguage)
        //{
        //    this.comboLanguage.DataSource = Languages.GetLanguages(selectedLanguage);
        //    this.comboLanguage.DataTextField = "text";
        //    this.comboLanguage.DataValueField = "value";
        //    this.comboLanguage.DataBind();
        //    this.comboLanguage.SelectedValue = selectedLanguage;
        //}

        /// <summary>
        /// Loads the countries in the comboBox in the *selectedLanguage*. 
        /// Also, the *selectedCountry* will appear selected in the 
        /// ComboBox
        /// </summary>
        //private void UpdateComboCountry(String selectedLanguage, String selectedCountry)
        //{
        //    this.comboCountry.DataSource = Countries.GetCountries(selectedLanguage);
        //    this.comboCountry.DataTextField = "text";
        //    this.comboCountry.DataValueField = "value";
        //    this.comboCountry.DataBind();
        //    this.comboCountry.SelectedValue = selectedCountry;
        //}

        /// <summary>
        /// Handles the Click event of the btnRegister control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance 
        /// containing the event data.</param>
        protected void BtnRegisterClick(object sender, EventArgs e)
        {

            if (Page.IsValid)
            {
                try
                {
                    UserProfileDetails userProfileDetailsVO =
                        new UserProfileDetails(txtFirstName.Text, txtSurname.Text,
                            txtEmail.Text);

                    SessionManager.RegisterUser(Context, txtLogin.Text,
                        txtPassword.Text, userProfileDetailsVO);

                    Response.Redirect(Response.
                        ApplyAppPathModifier("~/Pages/MainPage.aspx"));

                }
                catch (DuplicateInstanceException)
                {
                    lblLoginError.Visible = true;
                }

            }

        }