当前位置: 首页>>代码示例>>C#>>正文


C# UserAccount.Update方法代码示例

本文整理汇总了C#中UserAccount.Update方法的典型用法代码示例。如果您正苦于以下问题:C# UserAccount.Update方法的具体用法?C# UserAccount.Update怎么用?C# UserAccount.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserAccount的用法示例。


在下文中一共展示了UserAccount.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Settings

        public ActionResult Settings(NameValueCollection nvc)
        {
            ViewBag.IsValid = true;

            mu = Membership.GetUser();
            ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey));

            uad = new UserAccountDetail();

            uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

            string enableProfileLogging = Request.Form["enableprofilelogging"];
            string emailmessages = Request.Form["emailmessages"];
            string showonmap = Request.Form["showonmap"];
            string displayAge = Request.Form["displayage"];
            string membersOnlyProfile = Request.Form["membersonlyprofile"];

            if (!string.IsNullOrEmpty(membersOnlyProfile))
                uad.MembersOnlyProfile = true;
            else uad.MembersOnlyProfile = false;

            if (!string.IsNullOrEmpty(enableProfileLogging))
                uad.EnableProfileLogging = true;
            else uad.EnableProfileLogging = false;

            if (!string.IsNullOrEmpty(displayAge))
                uad.DisplayAge = true;
            else uad.DisplayAge = false;

            if (!string.IsNullOrEmpty(emailmessages))
                uad.EmailMessages = true;
            else uad.EmailMessages = false;

            if (!string.IsNullOrEmpty(showonmap))
                uad.ShowOnMap = true;
            else uad.ShowOnMap = false;

            uad.Set();

            string username = Request.Form["username"].Trim();
            bool isNewUserName = false;
            bool isValidName = false;

            try
            {
                isValidName = !System.Text.RegularExpressions.Regex.IsMatch(@"[A-Za-z][A-Za-z0-9_]{3,14}", username);
            }
            catch
            {
                // bad name
                isValidName = false;
            }

            if (mu.UserName != username && isValidName)
            {
                // TODO: PUT IN ALL THE SAME VALIDATION AS REGISTRATION
                isNewUserName = true;
                UserAccount newUsername = new UserAccount(username.Replace(":", string.Empty) /* still annoying errors */);

                if (newUsername.UserAccountID != 0)
                {
                    ViewBag.IsValid = false;
                    ModelState.AddModelError("", BootBaronLib.Resources.Messages.AlreadyInUse + ": " + BootBaronLib.Resources.Messages.UserName);
                    uad = new UserAccountDetail();

                    uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));
                    mu = Membership.GetUser();

                    ViewBag.UserAccountDetail = uad;
                    ViewBag.Membership = mu;
                    return View();
                }
                else
                {
                    if (!Utilities.IsEmail(Request.Form["email"]))
                    {
                        ViewBag.IsValid = false;
                        ModelState.AddModelError("", BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.EMail);
                        return View();
                    }
                    else if (Request.Form["email"].Trim() != ua.EMail)
                    {
                        ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey));
                        ua.EMail = Request.Form["email"];
                        ua.Update();
                    }

                    ua.UserName = username;
                    ua.Update();
                    FormsAuthentication.SetAuthCookie(username, false);
                    ViewBag.IsValid = true;
                }
            }
            else if (!Utilities.IsEmail(Request.Form["email"]))
            {
                ViewBag.IsValid = false;
                ModelState.AddModelError("", BootBaronLib.Resources.Messages.Invalid + ": " + BootBaronLib.Resources.Messages.EMail);
                return View();
            }
            else if (Request.Form["email"].Trim() != ua.EMail)
//.........这里部分代码省略.........
开发者ID:pakoito,项目名称:web,代码行数:101,代码来源:AccountController.cs

示例2: LogOff

        public ActionResult LogOff()
        {
            if (Membership.GetUser() == null)
            {
                FormsAuthentication.SignOut();

                return RedirectToAction("Index", "Home");
            }

            ua = new UserAccount(Membership.GetUser().UserName);
            ua.IsOnLine = false;
            ua.SigningOut = true;
            ua.Update();
            ua.RemoveCache();

            ChatRoomUser cru = new ChatRoomUser();

            cru.GetChatRoomUserByUserAccountID(ua.UserAccountID);
            cru.DeleteChatRoomUser();

            FormsAuthentication.SignOut();

            return RedirectToAction("Index", "Home");
        }
开发者ID:pakoito,项目名称:web,代码行数:24,代码来源:AccountController.cs

示例3: LogOn

        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                bool remember = Convert.ToBoolean(model.RememberMe);

                if (string.IsNullOrWhiteSpace(model.UserName) ||
                    string.IsNullOrWhiteSpace(model.Password))
                {
                    return View(model);
                }

                ua = new UserAccount(model.UserName);

                if (ua.UserAccountID == 0)
                {
                    ua = new UserAccount();
                    ua.GetUserAccountByEmail(model.UserName);

                    if (ua.UserAccountID > 0)
                    {
                        // they were stupid and put their email not username
                        model.UserName = ua.UserName;
                    }
                }

                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.RedirectFromLoginPage(model.UserName, remember);

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        ua = new UserAccount(model.UserName);

                        if (ua.IsLockedOut)
                        {
                            ModelState.AddModelError(string.Empty, BootBaronLib.Resources.Messages.IsLockedOut);
                            return View(model);
                        }

                        ua.LastLoginDate = DateTime.UtcNow;
                        ua.FailedPasswordAttemptCount = 0;
                        ua.IsOnLine = true;
                        ua.SigningOut = false;
                        ua.Update();

                        UserAccountDetail uad = new UserAccountDetail();
                        uad.GetUserAccountDeailForUser(ua.UserAccountID);
                        //uad.DefaultLanguage = Utilities.GetCurrentLanguageCode();
                        //uad.Update();

                        if (!string.IsNullOrWhiteSpace(uad.DefaultLanguage))
                        {
                            HttpCookie hc =
                                new HttpCookie(SiteEnums.CookieName.usersetting.ToString(), uad.DefaultLanguage);

                            NameValueCollection nvc = new NameValueCollection();
                            nvc.Add(SiteEnums.CookieValue.language.ToString(), uad.DefaultLanguage);

                            Utilities.CookieMaker(SiteEnums.CookieName.usersetting, nvc);

                            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(uad.DefaultLanguage);
                            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(uad.DefaultLanguage);
                        }

                        return RedirectToAction("Home", "Account");
                    }
                }
                else
                {
                    // it updates as online, make off
                    ua = new UserAccount(model.UserName);

                    if (ua.UserAccountID > 0)
                    {
                        ua.IsOnLine = false;
                        ua.SigningOut = true;
                        ua.Update();
                    }
                }
            }

            ModelState.AddModelError(string.Empty, BootBaronLib.Resources.Messages.LoginUnsuccessfulPleaseCorrect);

            // If we got this far, something failed, redisplay form
            return View(model);
        }
开发者ID:pakoito,项目名称:web,代码行数:91,代码来源:AccountController.cs

示例4: UpdateRoles

        public ActionResult UpdateRoles(int userAccountID, IEnumerable<string> roleOption)
        {
            var ua = new UserAccount(userAccountID)
            {
                IsApproved = (Request.Form["isApproved"] != null),
                EMail =  Request.Form["email"]

            };
            ua.Update();

            var uad1 = new UserAccountDetail();
            uad1.GetUserAccountDeailForUser(ua.UserAccountID);
            uad1.EmailMessages = (Request.Form["emailMessages"] != null);
            uad1.Update();

            UserAccountRole.DeleteUserRoles(userAccountID);

            if (roleOption != null)
            {
                foreach (Role thenewRole in roleOption.Select(newRole => new Role(newRole)))
                {
                    UserAccountRole.AddUserToRole(userAccountID, thenewRole.RoleID);
                }
            }

            if (ua.UserAccountID > 0)
            {
                ViewBag.SelectedUser = ua;
                var uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(ua.UserAccountID);
                ViewBag.UserAccountDetail = uad;
            }

            LoadAllRoles();

            return View("UserManagement");
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:37,代码来源:SiteAdminController.cs

示例5: ForgotPassword

        public ActionResult ForgotPassword(string email)
        {
            UserAccount ua = new UserAccount();
            ua.GetUserAccountByEmail(email);

            if (ua.UserAccountID == 0)
            {
                ViewBag.Result = Messages.NotFound;
            }
            else
            {
                ua.FailedPasswordAnswerAttemptCount = 0;
                ua.FailedPasswordAttemptCount = 0;
                ua.IsLockedOut = false;
                ua.Update();

                mu = Membership.GetUser(ua.UserName);
                string newPassword = mu.ResetPassword();

                BootBaronLib.Operational.Utilities.SendMail(email, BootBaronLib.Configs.AmazonCloudConfigs.SendFromEmail, Messages.PasswordReset,
                   Messages.UserName + ": " + ua.UserName + Environment.NewLine +
                    Environment.NewLine + Messages.NewPassword + ": " + newPassword +
                    Environment.NewLine +
                Environment.NewLine + Messages.SignIn + ": " + BootBaronLib.Configs.GeneralConfigs.SiteDomain);

                ViewBag.Result = Messages.CheckYourEmailAndSpamFolder;
            }

            return View();
        }
开发者ID:pakoito,项目名称:web,代码行数:30,代码来源:AccountController.cs

示例6: UpdateFailureCount

        /// <summary>
        ///     A helper method that performs the checks and updates associated with password failure tracking.
        /// </summary>
        private void UpdateFailureCount(string username, SiteEnums.MembershipFailureTypes failureType)
        {
            var eu = new UserAccount(username);
            if (eu.UserAccountID == 0) throw new ProviderException(Messages.UnableToUpdateFailureCount);

            int failureCount = 0;

            if (failureType == SiteEnums.MembershipFailureTypes.password)
            {
                failureCount = Convert.ToInt32(eu.FailedPasswordAttemptCount);
            }

            if (failureType == SiteEnums.MembershipFailureTypes.passwordAnswer)
            {
                failureCount = Convert.ToInt32(eu.FailedPasswordAnswerAttemptCount);
            }

            if (failureCount == 0)
            {
                // First password failure or outside of PasswordAttemptWindow.
                // Start a new password failure count from 1 and a new window starting now.
                if (failureType == SiteEnums.MembershipFailureTypes.password)
                {
                    eu.FailedPasswordAttemptCount = 1;
                    //  eu.FailedPasswordAttemptWindowStart = FromDB.GetUTCDate();
                }
                if (failureType == SiteEnums.MembershipFailureTypes.passwordAnswer)
                {
                    eu.FailedPasswordAnswerAttemptCount = 1;
                    //  eu.FailedPasswordAnswerAttemptWindowStart = FromDB.GetUTCDate();
                }

                try
                {
                    eu.Update();
                }
                catch
                {
                    throw new ProviderException(Messages.UnableToUpdateFailureCountAndWindowStart);
                }
            }
            else
            {
                if (failureCount++ >= MaxInvalidPasswordAttempts)
                {
                    // Max password attempts have exceeded the failure threshold. Lock out the user.
                    eu.IsLockedOut = true;
                    //  eu.LastLockoutDate = FromDB.GetUTCDate();

                    try
                    {
                        eu.Update();
                    }
                    catch
                    {
                        throw new ProviderException(Messages.UnableToLockOutUser);
                    }
                }
                else
                {
                    // Max password attempts have not exceeded the failure threshold. Update
                    // the failure counts. Leave the window the same.
                    if (failureType == SiteEnums.MembershipFailureTypes.password)
                    {
                        eu.FailedPasswordAttemptCount = failureCount;
                    }
                    if (failureType == SiteEnums.MembershipFailureTypes.passwordAnswer)
                    {
                        eu.FailedPasswordAnswerAttemptCount = failureCount;
                    }

                    try
                    {
                        eu.Update();
                    }
                    catch
                    {
                        throw new ProviderException(Messages.UnableToUpdateFailureCount);
                    }
                }
            }
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:85,代码来源:MembershipProvider.cs

示例7: ForgotPassword

        public ActionResult ForgotPassword(string email)
        {
            var ua = new UserAccount();
            ua.GetUserAccountByEmail(email);

            if (ua.UserAccountID == 0)
            {
                ViewBag.Result = Messages.NotFound;
            }
            else
            {
                ua.FailedPasswordAnswerAttemptCount = 0;
                ua.FailedPasswordAttemptCount = 0;
                ua.Update();

                _mu = Membership.GetUser(ua.UserName);

                if (_mu != null)
                {
                    string newPassword = _mu.ResetPassword();

                    _mail.SendMail(AmazonCloudConfigs.SendFromEmail, email, Messages.PasswordReset,
                        string.Format("{0}: {1}{2}{2}{3}: {4}{2}{2}{5}: {6}",
                            Messages.UserName, ua.UserName, Environment.NewLine,
                            Messages.NewPassword, newPassword, Messages.SignIn, GeneralConfigs.SiteDomain));
                }

                ViewBag.Result = Messages.CheckYourEmailAndSpamFolder;
            }

            return View();
        }
开发者ID:dasklub,项目名称:kommunity,代码行数:32,代码来源:AccountController.cs

示例8: UpdateUser

        /// <summary>
        ///     Update the underlying end user for this membership user
        /// </summary>
        /// <param name="user"></param>
        public override void UpdateUser(MembershipUser user)
        {
            var eu = new UserAccount(Convert.ToInt32(user.ProviderUserKey));

            if (eu.UserAccountID < 1)
                throw new ProviderException(Messages.UpdateUserFailedNoUniqueUserFound);
            if (eu.UserAccountID == 0)
                return;

            eu.Comment = user.Comment;
            eu.CreateDate = user.CreationDate;
            eu.EMail = user.Email;
            eu.IsApproved = user.IsApproved;
            eu.IsLockedOut = user.IsLockedOut;
            eu.IsOnLine = user.IsOnline;
            eu.LastActivityDate = user.LastActivityDate;
            eu.LastLockoutDate = user.LastLockoutDate;
            eu.LastLoginDate = user.LastLoginDate;
            eu.LastPasswordChangedDate = user.LastPasswordChangedDate;
            eu.PasswordQuestion = user.PasswordQuestion;
            eu.PasswordQuestion = user.ProviderName;
            eu.UserName = user.UserName;

            eu.Update();
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:29,代码来源:MembershipProvider.cs

示例9: ValidateUser

        /// <summary>
        ///     Confirms that this person can log in,
        ///     they are approved and not locked out
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;

            username = username.Trim();
            password = password.Trim();

            if (username == string.Empty || password == string.Empty)
            {
                return false;
            }

            var eu = new UserAccount(username);

            if (eu.UserAccountID == 0) return false;
            if (!eu.IsApproved) return false;
            if (eu.IsLockedOut) return false;

            if (IsValidPasswordComparison(password, eu.Password))
            {
                if (eu.IsLockedOut) return isValid;

                isValid = true;
                eu.IsOnLine = true;
                eu.Update();
            }
            else
            {
                UpdateFailureCount(username, SiteEnums.MembershipFailureTypes.password);
            }

            return isValid;
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:40,代码来源:MembershipProvider.cs

示例10: ResetPassword

        /// <summary>
        ///     Same thing as: GetPassword method here
        /// </summary>
        /// <param name="username"></param>
        /// <param name="answer"></param>
        /// <returns></returns>
        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordRetrieval) throw new ProviderException(Messages.PasswordRetrievalNotEnabled);

            string password = RandomPassword.Generate(8, 10);

            var eu = new UserAccount(username);

            if (eu.UserAccountID < 1)
                throw new ProviderException(Messages.GetPasswordFailedNoUnique);

            if (eu.UserAccountID > 0)
            {
                // this is going to be reset anyway
                //if (eu.IsLockedOut)
                //    throw new MembershipPasswordException("The supplied user is locked out.");
            }
            else throw new MembershipPasswordException(Messages.TheSuppliedUserNameIsNotFound);

            if (RequiresQuestionAndAnswer && !IsValidPasswordAnswerComparison(answer, eu.PasswordAnswer))
            {
                UpdateFailureCount(username, SiteEnums.MembershipFailureTypes.passwordAnswer);
                throw new MembershipPasswordException(Messages.IncorrectPasswordAnswer);
            }
            if (PasswordFormat == MembershipPasswordFormat.Hashed)
            {
                //  reset the password
                eu.IsLockedOut = false;
                eu.FailedPasswordAttemptCount = 0;
                eu.Password = EncodePassword(password);
                eu.Update();
            }

            if (PasswordFormat == MembershipPasswordFormat.Encrypted)
            {
                password = UnEncodePassword(eu.Password);
            }

            return password;
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:46,代码来源:MembershipProvider.cs

示例11: UnlockUser

        /// <summary>
        ///     Clears a lock so that the membership user can be validated.
        /// </summary>
        /// <returns>true if the membership user was successfully unlocked; otherwise, false.</returns>
        /// <param name="userName">The membership user whose lock status you want to clear.</param>
        public override bool UnlockUser(string userName)
        {
            try
            {
                var eu = new UserAccount(userName);

                if (eu.UserAccountID < 1 || eu.UserAccountID == 0) return false;

                eu.IsLockedOut = false;
                eu.FailedPasswordAnswerAttemptCount = 0;
                eu.FailedPasswordAttemptCount = 0;
                eu.Update();
                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:24,代码来源:MembershipProvider.cs

示例12: GetUser

        /// <summary>
        ///     Get the user by name and online status
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            if (string.IsNullOrWhiteSpace(username)) return null;

            var eu = new UserAccount(username);

            if (eu.UserAccountID == 0) return null;

            if (!eu.IsApproved || eu.IsLockedOut) FormsAuthentication.SignOut();

            eu.Update();

            var mu = GetMembershipUserFromUserAccount(eu);

            return mu;
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:22,代码来源:MembershipProvider.cs

示例13: GetPassword

        /// <summary>
        ///     Gets the password for the specified user name from the data source.
        /// </summary>
        /// <returns>The password for the specified user name.</returns>
        /// <param name="username">The user to retrieve the password for.</param>
        /// <param name="answer">The password answer for the user.</param>
        public override string GetPassword(string username, string answer)
        {
            if (!EnablePasswordRetrieval) throw new ProviderException("Password Retrieval Not Enabled.");

            string password = string.Empty;

            var eu = new UserAccount(username);

            if (eu.UserAccountID < 1)
                throw new ProviderException("Get password failed. No unique user found.");

            if (eu.UserAccountID > 0)
            {
                if (eu.IsLockedOut)
                    throw new MembershipPasswordException("The supplied user is locked out.");
            }
            else throw new MembershipPasswordException("The supplied user name is not found.");

            if (RequiresQuestionAndAnswer && !IsValidPasswordAnswerComparison(answer, eu.PasswordAnswer))
            {
                UpdateFailureCount(username, SiteEnums.MembershipFailureTypes.passwordAnswer);
                throw new MembershipPasswordException("Incorrect password answer.");
            }
            if (PasswordFormat == MembershipPasswordFormat.Hashed)
            {
                //  reset the password
                // password = Utilities.RandomPassword.Generate();
                eu.Password = EncodePassword(password);
                eu.Update();
            }

            if (PasswordFormat == MembershipPasswordFormat.Encrypted)
            {
                password = UnEncodePassword(eu.Password);
            }

            return password;
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:44,代码来源:MembershipProvider.cs

示例14: ChangePassword

        /// <summary>
        ///     Change the user's password
        /// </summary>
        /// <param name="username"></param>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public override bool ChangePassword(
            string username,
            string oldPassword,
            string newPassword)
        {
            var args = new ValidatePasswordEventArgs(username, newPassword, true);
            OnValidatingPassword(args);

            if (args.Cancel)
            {
                if (args.FailureInformation != null) throw args.FailureInformation;
                throw new MembershipPasswordException("Change password canceled due to new password validation failure.");
            }

            var eu = new UserAccount(username);

            if (eu.UserAccountID < 1) throw new ProviderException("Change password failed. No unique user found.");

            if (EncodePassword(oldPassword) != eu.Password)
            {
                return false;
            }

            eu.Password = EncodePassword(newPassword);

            try
            {
                return eu.Update();
            }
            catch
            {
                return false;
            }
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:41,代码来源:MembershipProvider.cs

示例15: GetUser

        /// <summary>
        /// Get the user by name and online status
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            if (username == string.Empty) { return null; }

            MembershipUser mu = null;
            UserAccount eu = new UserAccount(username);
            if (eu.UserAccountID != 0)// && eu.IsOnLine == userIsOnline)
            {
                eu.Update(); // updates the last activity date
                // get the values for this end user
                mu = GetMembershipUserFromUserAccount(eu);
            }
            return mu;
        }
开发者ID:pakoito,项目名称:web,代码行数:20,代码来源:MembershipProvider.cs


注:本文中的UserAccount.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。