/// <summary>
        /// The remove users from roles.
        /// </summary>
        /// <param name="usernames">
        /// The usernames.
        /// </param>
        /// <param name="roleNames">
        /// The role names.
        /// </param>
        /// <exception cref="AppleseedMembershipProviderException">
        /// </exception>
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            var userIds = new Guid[usernames.Length];
            var roleIds = new Guid[roleNames.Length];

            AppleseedUser user = null;

            for (var i = 0; i < usernames.Length; i++)
            {
                user = (AppleseedUser)Membership.GetUser(usernames[i]);

                if (user == null)
                {
                    throw new AppleseedMembershipProviderException(string.Format("User {0} doesn't exist", usernames[i]));
                }

                userIds[i] = user.ProviderUserKey;
            }

            for (var i = 0; i < roleNames.Length; i++)
            {
                var role = this.GetRoleByName(this.ApplicationName, roleNames[i]);
                roleIds[i] = role.Id;
            }

            this.RemoveUsersFromRoles(this.ApplicationName, userIds, roleIds);
        }
Esempio n. 2
0
        public void UpdateExistingUserTest()
        {
            try
            {
                AppleseedUser user = (AppleseedUser)Membership.GetUser("Tito");

                Assert.AreEqual(user.Email, "*****@*****.**");
                Assert.IsTrue(user.IsApproved);

                user.Email         = "*****@*****.**";
                user.IsApproved    = false;
                user.LastLoginDate = new DateTime(1982, 2, 6);

                Membership.UpdateUser(user);

                user = (AppleseedUser)Membership.GetUser("Tito");
                Assert.AreEqual(user.Email, "*****@*****.**");
                Assert.IsFalse(user.IsApproved);
                Assert.AreEqual(new DateTime(1982, 2, 6), user.LastLoginDate);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
                Assert.Fail("Error in UpdateUserTest1", ex);
            }
        }
Esempio n. 3
0
        public void UpdateUserTest2()
        {
            try
            {
                AppleseedUser user = new AppleseedUser(Membership.Provider.Name, "invalidUserName", Guid.NewGuid(), "*****@*****.**", "question", "answer", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.MinValue);

                Membership.UpdateUser(user);

                Assert.Fail("UpdateUser didn't throw an exception even though userName was invalid");
            }
            catch (AppleseedMembershipProviderException)
            {
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
                Assert.Fail("Error in UpdateUserTest1", ex);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// The usersInRole_ItemCommand server event handler on this page
        /// is used to handle the user editing and deleting roles
        /// from the usersInRole asp:datalist control
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListCommandEventArgs"/> instance containing the event data.</param>
        protected void usersInRole_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            UsersDB users = new UsersDB();

            Label         lblUserEmail = (Label)e.Item.FindControl("lblUserEmail");
            string        userName     = Membership.GetUserNameByEmail(lblUserEmail.Text);
            AppleseedUser user         = (AppleseedUser)Membership.GetUser(userName);

            if (e.CommandName == "delete")
            {
                // update database
                users.DeleteUserRole(roleId, user.ProviderUserKey, this.PortalSettings.PortalAlias);

                // Ensure that item is not editable
                usersInRole.EditItemIndex = -1;

                // Repopulate list
                BindData();
            }
        }
Esempio n. 5
0
        public void AddUsersToRolesTest6()
        {
            try
            {
                AppleseedRoleProvider provider = Roles.Provider as AppleseedRoleProvider;

                AppleseedUser user  = (AppleseedUser)Membership.GetUser("*****@*****.**");
                Guid[]        users = new Guid[1];
                users[0] = user.ProviderUserKey;

                AppleseedRole role  = provider.GetRoleByName("Appleseed", "clerks");
                Guid[]        roles = new Guid[1];
                roles[0] = role.Id;

                provider.AddUsersToRoles("Appleseed", users, roles);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Assert.Fail("Error in AddUsersToRolesTest6" + ex.Message, ex);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the Click event of the SendPasswordBtn 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>
        private void SendPasswordBtn_Click(object sender, EventArgs e)
        {
            if (email.Text == string.Empty)
            {
                Message.Text    = "Please enter you email address";
                Message.TextKey = "SIGNIN_ENTER_EMAIL_ADDR";
                return;
            }
            // generate random password
            string randomPassword = RandomPassword.Generate(8, 10);

            CryptoHelper crypthelp = new CryptoHelper();
            UsersDB      usersDB   = new UsersDB();

            //Obtain single row of User information
            AppleseedUser user = usersDB.GetSingleUser(email.Text, this.PortalSettings.PortalAlias);

            if (user != null)
            {
                string Pswrd;
                string AppName   = this.PortalSettings.PortalName;
                bool   encrypted = Config.EncryptPassword;
                string Name      = user.Email;
                if (encrypted)
                {
                    Pswrd = randomPassword;
                    crypthelp.ResetPassword(Name, randomPassword);
                }
                else
                {
                    Pswrd = user.GetPassword();
                }
                crypthelp.ResetPassword(Name, randomPassword);
                string LoginUrl = Path.ApplicationFullPath + "DesktopModules/Admin/Logon.aspx?Usr="******"&Pwd=" +
                                  Pswrd + "&Alias=" + this.PortalSettings.PortalAlias;
                // MailMessage mail = new MailMessage();

                // [email protected]
                // Date 19 March 2003
                // We have to use a correct sender address,
                // because most SMTP servers reject it otherwise
                //jes1111 - mail.From = ConfigurationSettings.AppSettings["EmailFrom"].ToString();
                //mail.From = Config.EmailFrom;
                //mail.To = email.Text;
                //mail.Subject = AppName + " - " + General.GetString( "SIGNIN_SEND_PWD", "Send me password", this );

                StringBuilder sb = new StringBuilder();

                sb.Append(Name);
                sb.Append(",");
                sb.Append("\r\n\r\n");
                sb.Append(General.GetString("SIGNIN_PWD_REQUESTED", "This is the password you requested", this));
                sb.Append(" ");
                sb.Append(Pswrd);
                sb.Append("\r\n\r\n");
                sb.Append(General.GetString("SIGNIN_THANK_YOU", "Thanks for your visit.", this));
                sb.Append(" ");
                sb.Append(AppName);
                sb.Append("\r\n\r\n");
                sb.Append(General.GetString("SIGNIN_YOU_CAN_LOGIN_FROM", "You can login from", this));
                sb.Append(":");
                sb.Append("\r\n");
                sb.Append(Path.ApplicationFullPath);
                sb.Append("\r\n\r\n");
                sb.Append(General.GetString("SIGNIN_USE_DIRECT_URL", "Or using direct url", this));
                sb.Append("\r\n");
                sb.Append(LoginUrl);
                sb.Append("\r\n\r\n");
                sb.Append(
                    General.GetString("SIGNIN_URL_WARNING",
                                      "NOTE: The address above may not show up on your screen as one line. This would prevent you from using the link to access the web page. If this happens, just use the 'cut' and 'paste' options to join the pieces of the URL.",
                                      this));

                //mail.Body = sb.ToString();
                //mail.BodyFormat = MailFormat.Text;

                //SmtpMail.SmtpServer = Config.SmtpServer;
                //SmtpMail.Send( mail );


                string      subject = AppName + " - " + General.GetString("SIGNIN_SEND_PWD", "Send me password", this);
                MailMessage newmail = new MailMessage(Config.EmailFrom.ToString(), email.Text, subject, sb.ToString());
                SmtpClient  client  = new SmtpClient(Config.SmtpServer);
                client.Send(newmail);

                Message.Text =
                    General.GetString("SIGNIN_PWD_WAS_SENT", "Your password was sent to the addess you provided",
                                      this);
                Message.TextKey = "SIGNIN_PWD_WAS_SENT";
            }
            else
            {
                Message.Text =
                    General.GetString("SIGNIN_PWD_MISSING_IN_DB",
                                      "The email you specified does not exists on our database", this);
                Message.TextKey = "SIGNIN_PWD_MISSING_IN_DB";
            }
        }