protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { InfoControl.Web.Security.MembershipManager mManager = new InfoControl.Web.Security.MembershipManager(this); InfoControl.Web.Security.DataEntities.User user = mManager.GetUserByName(CreateUserWizard1.UserName.ToString()); Profile profile = new Profile(); ProfileManager pManager = new ProfileManager(this); profile.Name = (CreateUserWizard1.FindControl("txtName") as TextBox).Text; profile.CPF = (CreateUserWizard1.FindControl("txtCPF") as TextBox).Text; //profile.Address = (CreateUserWizard1.FindControl("txtAddress") as TextBox).Text; profile.Phone = (CreateUserWizard1.FindControl("txtPhone") as TextBox).Text; //profile.Neighborhood = (CreateUserWizard1.FindControl("txtNeighborhood") as TextBox).Text; profile.PostalCode = (CreateUserWizard1.FindControl("txtPostalCode") as TextBox).Text; profile.ModifiedDate = DateTime.Now; //profile.UserId = user.UserId; //profile.StateId = (CreateUserWizard1.FindControl("cboState") as DropDownList).SelectedValue; try { pManager.Insert(profile); } catch (Exception ex) { if (ex != null) { return; } } Context.Items.Add("UserId", user.UserId); Server.Transfer("User.aspx"); }
/// <summary> /// Change the password /// </summary> /// <param name="username"></param> /// <param name="oldPwd"></param> /// <param name="newPwd"></param> /// <returns></returns> public override bool ChangePassword(string username, string oldPwd, string newPwd) { // // Validate user to permits change the password // if (!ValidateUser(username, oldPwd, false)) { return(false); } // // Fires event validating password // ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPwd, true); OnValidatingPassword(args); if (args.Cancel) { if (args.FailureInformation != null) { throw args.FailureInformation; } else { throw new MembershipPasswordException("Change password canceled due to new password validation failure."); } } // // Updates the user password // return(MembershipManager.ChangePassword(username, newPwd)); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="answer"></param> /// <returns></returns> public override string GetPassword(string username, string answer) { if (!EnablePasswordRetrieval) { throw new ProviderException("Password Retrieval Not Enabled."); } if (PasswordFormat == System.Web.Security.MembershipPasswordFormat.Hashed) { return(ResetPassword(username, answer)); } return(MembershipManager.GetPassword(username, answer)); }
/// <summary> /// Change the Q & A /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="newPwdQuestion"></param> /// <param name="newPwdAnswer"></param> /// <returns></returns> public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPwdQuestion, string newPwdAnswer) { if (!ValidateUser(username, password, false)) { return(false); } // // Updates the user password // return(MembershipManager.ChangePasswordQuestionAndAnswer(username, newPwdQuestion, newPwdAnswer)); }
void OnSessionEnd(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; System.Web.SessionState.HttpSessionState session = application.Session; using (MembershipManager membershipManager = new MembershipManager(null)) { AccessControlPrincipal principal = session[session.SessionID] as AccessControlPrincipal; if (principal != null && principal.Identity != null) { membershipManager.Logoff(principal); } } session.RemoveAll(); }
/// <summary>Gets a collection of all the users in the SQL Server membership database.</summary> /// <returns>A <see cref="T:System.Web.Security.MembershipUserCollection"></see> of <see cref="T:System.Web.Security.MembershipUser"></see> objects representing all the users in the database for the configured <see cref="P:System.Web.Security.SqlMembershipProvider.ApplicationName"></see>.</returns> /// <param name="totalRecords">The total number of users.</param> /// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param> /// <param name="pageSize">The size of the page of results to return.</param> /// <exception cref="T:System.ArgumentException">pageIndex is less than zero.- or -pageSize is less than one.- or -pageIndex multiplied by pageSize plus pageSize minus one exceeds <see cref="F:System.Int32.MaxValue"></see>.</exception> public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { // // Calculate the first and last records // int firstUserIndex = pageIndex * pageSize; int lastUserIndex = ((pageIndex * pageSize) + pageSize) - 1; if (pageIndex < 0) { throw new ArgumentException(Properties.Resources.PageIndex_bad, "pageIndex"); } if (pageSize < 1) { throw new ArgumentException(Properties.Resources.PageSize_bad, "pageSize"); } if (lastUserIndex > 0x7fffffff) { throw new ArgumentException(Properties.Resources.PageIndex_PageSize_bad, "pageIndex and pageSize"); } // // Retrieve a users collection // System.Collections.Generic.IList <User> users = MembershipManager.GetAllUsers().ToList(); totalRecords = users.Count; lastUserIndex = Math.Min(totalRecords, lastUserIndex); // // Enumerate the Membership.User and convert to MembershipUserCollection // MembershipUserCollection list = new MembershipUserCollection(); for (int idx = firstUserIndex; idx < lastUserIndex; idx++) { list.Add(new VivinaMembershipUser(users[idx])); } return(list); }
/// <summary>Resets a user's password to a new, automatically generated password.</summary> /// <returns>The new password for the specified user.</returns> /// <param name="username">The user to reset the password for. </param> /// <param name="answer">The password answer for the specified user. </param> public override string ResetPassword(string username, string answer) { ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, answer, true); OnValidatingPassword(args); if (args.Cancel) { if (args.FailureInformation != null) { throw args.FailureInformation; } else { throw new MembershipPasswordException("Reset password canceled due to password validation failure."); } } return(MembershipManager.ResetPassword(username, answer)); }
/// <summary> /// Create a user /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="passwordQuestion"></param> /// <param name="passwordAnswer"></param> /// <param name="isApproved"></param> /// <param name="providerUserKey"></param> /// <param name="status"></param> /// <returns></returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); User user = new User(); user.UserName = username; user.Password = password; user.Email = email; user.PasswordQuestion = passwordQuestion; user.PasswordAnswer = passwordAnswer; return(MembershipManager.Insert(user, out status, _requiresValidEmail)); }
void context_PostAcquireRequestState(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; HttpContext context = application.Context; MembershipManager membershipManager = new MembershipManager(null); AccessControlPrincipal principal = null; DataEntities.User user = null; System.Security.Principal.IIdentity identity = null; if (IsValid) { context.Trace.Warn("Role Module Begin"); #region Cookies if ((!Roles.CookieRequireSSL || context.Request.IsSecureConnection)) { if (Roles.CacheRolesInCookie) { HttpCookie cookie = context.Request.Cookies[Roles.CookieName]; if (cookie != null && cookie.Value != null) { if (!string.IsNullOrEmpty(Roles.CookiePath) && (Roles.CookiePath != "/")) { cookie.Path = Roles.CookiePath; } if (Roles.CookieProtectionValue == CookieProtection.Encryption) { cookie.Value = cookie.Value.Decrypt().Decompress(); } cookie.Domain = Roles.Domain; context.User = HttpUtility.UrlDecode(cookie.Value).Deserialize <AccessControlPrincipal>(); } else { Roles.DeleteCookie(); } } else { Roles.DeleteCookie(); } } else { Roles.DeleteCookie(); } #endregion identity = context.User.Identity; principal = new AccessControlPrincipal(user, identity); if (context.Session != null && context.Session[context.Session.SessionID] != null && identity.IsAuthenticated) { principal = context.Session[context.Session.SessionID] as AccessControlPrincipal; } if (String.IsNullOrEmpty(principal.Name) && !String.IsNullOrEmpty(identity.Name)) { user = membershipManager.GetUserByName(identity.Name); if (user != null) { bool timeoutExpired = DateTime.Now.Subtract(user.LastActivityDate).Minutes > System.Web.Security.Membership.UserIsOnlineTimeWindow; user.LastActivityDate = DateTime.Now; user.IsOnline = !timeoutExpired; membershipManager.DbContext.SubmitChanges(); membershipManager.DataManager.Commit(); } principal = new AccessControlPrincipal(user, identity); } if (context.Application["Session_End"] == null) { context.Application["Session_End"] = new EventHandler(OnSessionEnd); } // // Cache the user in session to dont query database // if (context.Session != null && identity.IsAuthenticated) { context.Session[context.Session.SessionID] = principal; } System.Threading.Thread.CurrentPrincipal = principal; context.User = principal; context.Trace.Warn("Role Module End"); } }
/// <summary> /// Deletes a user /// </summary> /// <param name="username"></param> /// <param name="deleteAllRelatedData"></param> /// <returns></returns> public override bool DeleteUser(string username, bool deleteAllRelatedData) { MembershipManager.Delete(username); return(true); }
/// <summary> /// /// </summary> /// <param name="user"></param> public override void UpdateUser(MembershipUser user) { MembershipManager.UpdateMembershipUser(user); }
/// <summary> /// Verifies that the specified user name and password exist in the data source. /// </summary> /// <param name="username">The name of the user to validate.</param> /// <param name="password">The password for the specified user</param> /// <returns></returns> public virtual bool ValidateUser(string username, string password, bool checkIsOnline) { return(MembershipManager.ValidateUser(username, password, checkIsOnline)); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <returns></returns> public override bool UnlockUser(string username) { return(MembershipManager.UnlockUser(username)); }
/// <summary> /// Get number of the users is online /// </summary> /// <returns></returns> public override int GetNumberOfUsersOnline() { return(MembershipManager.GetAllUsers().Where(usr => usr.IsOnline == true).Count()); }
/// <summary> /// /// </summary> /// <param name="providerUserKey"></param> /// <param name="userIsOnline"></param> /// <returns></returns> public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { User user = MembershipManager.GetUser(Convert.ToInt32(providerUserKey)); return(user == null ? null : new VivinaMembershipUser(user)); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="userIsOnline"></param> /// <returns></returns> public override MembershipUser GetUser(string username, bool userIsOnline) { User user = MembershipManager.GetUserByName(username); return(user == null ? null : new VivinaMembershipUser(user)); }
/// <summary> /// /// </summary> /// <param name="email"></param> /// <returns></returns> public override string GetUserNameByEmail(string email) { return(MembershipManager.GetUserByEmail(email).UserName); }