GetUser() public static method

public static GetUser ( ) : System.Web.Security.MembershipUser
return System.Web.Security.MembershipUser
Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UsernamePlaceHolder.Visible    = !Request.IsAuthenticated;
            OldPasswordPlaceHolder.Visible = Session[OldPasswordSessionKey] == null;

            if (IsPostBack)
            {
                MembershipUser user = Request.IsAuthenticated
               ? UserManager.GetUser()
               : UserManager.GetUser(Request["userName"]);
                string newPass = Request["firstNewPass"];

                if (user == null || newPass != Request["secondNewPass"] || Server.HtmlEncode(newPass) != newPass)
                {
                    ReportError();
                }
                else
                {
                    try
                    {
                        /*bool changePasswordSuccess =*/
                        user.ChangePassword(
                            (Session[OldPasswordSessionKey] ?? Request["oldPass"]).ToString(), newPass);
                        Session.Remove(OldPasswordSessionKey);
                        FormsAuthentication.SignOut();
                        Response.Redirect(FormsAuthentication.LoginUrl);
                    }
                    catch (Exception)
                    {
                        ReportError();
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// The update app user.
        /// </summary>
        /// <param name="appUser">
        /// The app user.
        /// </param>
        /// <param name="additionaUserInfo">
        /// The reg user.
        /// </param>
        public void UpdateAppUser(IAppUser appUser, IRegistringUser additionaUserInfo)
        {
            //var curUser = GetUser(appUser.Id);
            var curMemUser = MsMembership.GetUser(additionaUserInfo.UserName);
            var curAppUser = GetById(appUser.Id);

            curAppUser.Contact.FirstName = appUser.Contact.FirstName;
            curAppUser.Contact.LastName  = appUser.Contact.LastName;
            curAppUser.SiteId            = appUser.SiteId;
            curAppUser.IsActive          = appUser.IsActive;
            curAppUser.Title             = appUser.Title;
            curAppUser.UpdatedBy         = Thread.CurrentPrincipal.Identity.Name;
            curAppUser.UpdatedOn         = DateTime.UtcNow;
            curAppUser.SortOrder         = appUser.SortOrder;
            curAppUser.Status            = appUser.Status;
            curAppUser.RoleId            = appUser.RoleId;

            if (curMemUser != null)
            {
                curMemUser.Email = additionaUserInfo.Email;
            }

            //curUser.UserName = additionaUserInfo.UserName;
            MsMembership.UpdateUser(curMemUser);

            SetUserRole(additionaUserInfo, curAppUser.User, curAppUser);
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                return;
            }

            switch (task.Value)
            {
            case "Next":
                MembershipUser membershipUser = UserManager.GetUser(Request["userName"]);
                if (membershipUser != null)
                {
                    QuestionPlaceHolder.Visible = true;
                    questionLabel.InnerText     = membershipUser.PasswordQuestion;
                    if (Request["answer"] != null)
                    {
                        try
                        {
                            string newPass = membershipUser.ResetPassword(Request["answer"]);
                            Session[Change.OldPasswordSessionKey] = newPass;
                            FormsAuthentication.SetAuthCookie(membershipUser.UserName, false);
                            Response.Redirect("/Account/Change.aspx");

                            //UsernamePlaceHolder.Visible = false;
                            //QuestionPlaceHolder.Visible = false;
                            //NewPasswordPlaceHolder.Visible = true;
                            //newPassword.InnerText = newPass;
                            //task.Value = "Log In";
                        }
                        catch (MembershipPasswordException)
                        {
                            ReportError("Wrong answer");
                        }
                    }
                }
                else
                {
                    ReportError("Unknown username");
                }
                break;

            case "Restart":
                Response.Redirect(Request.Path);
                break;

            case "Log In":
                Response.Redirect(FormsAuthentication.LoginUrl);
                break;

            default:
                Response.Redirect(FormsAuthentication.LoginUrl);
                break;
            }
        }
Beispiel #4
0
        protected void User_Login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var            Logins = sender as System.Web.UI.WebControls.Login;
            MembershipUser User   = Members.GetUser(Logins.UserName);

            if (Members.ValidateUser(User_Login.UserName, User_Login.Password) == true)
            {
                String Role = "";

                if (HttpContext.Current.User.IsInRole("Administrator"))
                {
                    Role = "Administrator";
                }
                if (HttpContext.Current.User.IsInRole("Manager"))
                {
                    Role = "Manager";
                }
                if (HttpContext.Current.User.IsInRole("Users"))
                {
                    Role = "Users";
                }

                var        ticket = new FormsAuthenticationTicket(1, User_Login.UserName, DateTime.Now, DateTime.Now.AddMinutes(2880), User_Login.RememberMeSet, Role, FormsAuthentication.FormsCookiePath);
                String     hash   = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                if (ticket.IsPersistent)
                {
                    cookie.Expires = ticket.Expiration;
                }

                DateTime Last_Login = User.LastLoginDate;

                Response.Cookies.Add(cookie);
                Session["Status"]    = true;
                Session["LastLogin"] = Last_Login;
                Response.Redirect(FormsAuthentication.GetRedirectUrl(User_Login.UserName, User_Login.RememberMeSet));
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid login details.');", true);
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                return;
            }

            if (Request["unlock"] != null)
            {
                var membershipUser = UserManager.GetUser(Request["unlock"]);
                if (membershipUser != null)
                {
                    membershipUser.UnlockUser();
                }
            }
            else if (Request["delete"] != null)
            {
                var currentUser = UserManager.GetUser();
                if (currentUser != null && Request["delete"] != currentUser.UserName)
                {
                    UserManager.DeleteUser(Request["delete"]);
                }
            }
        }