Esempio n. 1
0
        public long CountOtherUsersBySiteAndDisplayName(Site site, string displayName, User user)
        {
            if (site == null)
            throw new ArgumentNullException("site");

             return Session.GetNamedQuery("CountOtherUsersBySiteAndDisplayName")
                  .SetEntity("site", site)
                  .SetString("name", displayName.Trim())
                  .SetInt32("id", user.UserId)
                  .UniqueResult<long>();
        }
Esempio n. 2
0
        public long CountOtherUsersBySiteAndEmail(Site site, string email, User user)
        {
            if (site == null)
            throw new ArgumentNullException("site");

             long ret = Session.GetNamedQuery("CountOtherUsersBySiteAndEmail")
                    .SetEntity("site", site)
                    .SetString("email", email.Trim())
                    .SetInt32("id", user.UserId)
                   .UniqueResult<long>();
             return ret;
        }
Esempio n. 3
0
        /// <summary>
        /// Get a standard user for a given site
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public static User GetTestUser(Site site)
        {
            User user = new User()
             {
            Email = "*****@*****.**",
            DisplayName = "test",
            Password = "******",
            CreatedDate = DateTime.Now,
            IsActive = true,
            Site = site
             };

             return user;
        }
        /// <summary>
        /// Reset a user password creating a new one.
        /// </summary>
        /// <param name="user"></param>
        /// <returns>The new password</returns>
        public string ResetPassword(User user)
        {
            string password = user.GeneratePassword();

             // Save the user
             userService.SaveUser(user);

             return password;
        }
        /// <summary>
        /// Effettua il login di un dato User
        /// </summary>
        /// <param name="user"></param>
        /// <param name="ipAddress"></param>
        public void LogIn(User user, string ipAddress, bool createPersistentCookie)
        {
            user.IsAuthenticated = true;
             user.LastLogin = DateTime.Now;
             user.LastIp = ipAddress;

             // Save login date and IP
             userService.UpdateUser(user);

             // Create the authentication ticket
             HttpContext.Current.User = new ArashiPrincipal(user);
             FormsAuthentication.SetAuthCookie(user.Name, createPersistentCookie);
        }
Esempio n. 6
0
 public void UpdateUser(User user)
 {
     //using (NHTransactionScope tx = new NHTransactionScope())
      //{
      Repository<User>.Save(user);
      //   tx.VoteCommit();
      //}
 }
Esempio n. 7
0
        public ServiceResult SaveUser(User user)
        {
            //using (NHTransactionScope tx = new NHTransactionScope())
             //{
            ServiceResult result = new ServiceResult()
            {
               State = ServiceResult.ServiceState.Success
            };

            user.Email = user.Email.Trim();
            user.DisplayName = user.DisplayName.Trim();
            Repository<User>.Save(user);
            //tx.VoteCommit();

            return result;
             //}
        }
Esempio n. 8
0
        public string ResetPassword(User user)
        {
            string newPassword = user.GeneratePassword();

             SaveUser(user);
             return newPassword;
        }
Esempio n. 9
0
 public void DeleteUser(User user)
 {
     //using (NHTransactionScope tx = new NHTransactionScope())
      //{
      user.IsLogicallyDeleted = true;
      Repository<User>.Save(user);
      //   tx.VoteCommit();
      //}
 }
Esempio n. 10
0
 /// <summary>
 /// Set the user for the current context.
 /// </summary>
 /// <param name="user"></param>
 public void SetUser(User user)
 {
     currentUser = user;
      HttpContext.Current.User = user;
      Thread.CurrentPrincipal = user;
 }
Esempio n. 11
0
        /// <summary>
        /// Create the Administrator account
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AdminButton_Click(object sender, EventArgs e)
        {
            log.Debug("Install.AdminButton_Click: Start");

             if (!IsValid)
             {
            log.Debug("Install.AdminButton_Click: Page is not valid!");
            return;
             }

             // Only create an admin if there are really NO users.
             if (userService.CountAllUsersForAllSites() > 0)
             {
            string msg = "There is already a user in the database. For security reasons Arashi won't add a new user!";
            ShowError(msg);
            return;
             }

             // Retrieve the previous saved Site
             Arashi.Core.Domain.Site site = siteService.GetSiteById(Convert.ToInt32(SiteIdHidden.Value));

             User newAdmin = new User
             {
            DisplayName = "Admin",
            Email = EmailTextBox.Text,
            FirstName = "Admin",
            IsActive = true,
            TimeZone = 0,
            Site = site,
            AdminTheme = "arashi",
            AdminCulture = Thread.CurrentThread.CurrentCulture.Name,
            CreatedDate = DateTime.UtcNow
             };

             newAdmin.Password = newAdmin.HashPassword(PasswordTextBox.Text);

             try
             {
            Role adminRole = userService.GetRoleByName(site, "Administrators");
            newAdmin.Roles.Add(adminRole);
            userService.SaveUser(newAdmin);

            ShowMessage("User successfully created.");
            log.Debug("Install.AdminButton_Click: Admin user created!");

            AdminPanel.Visible = false;
            pnlFinished.Visible = true;

            RemoveInstallLock();

            //at the moment, this is the last step of the installation, so
            //call the finishing routine here
            FinishInstall();
             }
             catch (Exception ex)
             {
            log.Error(ex.ToString());
            ShowError("An error occurred while creating the administrator: <br/>" + ex.ToString());
             }

             log.Debug("Install.AdminButton_Click: End");
        }