Ejemplo n.º 1
0
        public static Tuple <Singular.Web.MessageType, String> ChangePassword(ChangeDetails details)
        {
            // Check for any business rule failures
            if (!details.CheckAllRules())
            {
                return(Tuple.Create(Singular.Web.MessageType.Validation, "Validation failed"));
            }

            // Check if the password meets complexity requirements
            Singular.Misc.Password.PasswordChecker passwordChecker = new Singular.Misc.Password.PasswordChecker(8, true, true, true, false, 1);
            if (!passwordChecker.CheckPassword(details.NewPassword))
            {
                return(Tuple.Create(Singular.Web.MessageType.Warning, passwordChecker.ErrorMessage));
            }

            // Attempt to change the user's password
            int CheckOP = 0;

            if (details.OldPassword != "")
            {
                CheckOP = 1;
            }
            try
            {
                DataRow result = CommandProc.GetDataRow(
                    "CmdProcs.cmdChangePassword",
                    new string[] { "@UserID", "@OldPassword", "@NewPassword", "@CheckOldPassword" },
                    new object[] {
                    Singular.Settings.CurrentUserID,
                    MEWebSecurity.CurrentIdentity().FirstTimeLogin == false || MEWebSecurity.CurrentIdentity().ResetState == ResetState.MustResetPassword? MEWebSecurity.GetPasswordHash(details.OldPassword) : details.OldPassword,
                    MEWebSecurity.GetPasswordHash(details.NewPassword),
                    CheckOP
                });

                if (bool.Parse(result.ItemArray[0].ToString()) == true)
                {
                    if (MELib.Security.MEWebSecurity.CurrentIdentity().Roles.Contains("Users.ForgotPassword"))
                    {
                        MELib.Security.MEWebSecurity.CurrentIdentity().Roles.Remove("Users.ForgotPassword");
                    }

                    MEWebSecurity.CurrentIdentity().MarkNonFirstTimeLogin();
                    MEWebSecurity.CurrentIdentity().ChangedPassword();
                    return(Tuple.Create(Singular.Web.MessageType.Success, "Change Password Success."));
                }
                else
                {
                    return(Tuple.Create(Singular.Web.MessageType.Error, "Change Password Failed - Incorrect Temporary Password"));
                }
            }
            catch (Exception)
            {
                return(Tuple.Create(Singular.Web.MessageType.Error, "Change Password Failed - Please contact System Administrator"));

                throw;
            }
        }
Ejemplo n.º 2
0
        public Result Login(LoginDetails loginDetails)
        {
            Result ret = new Result();

            try
            {
                MEIdentity.Login(loginDetails);
                ret.Success = true;
                if (MEWebSecurity.CurrentIdentity().FirstTimeLogin)
                {
                    ret.Data = "ChangePassword.aspx";
                }
            }
            catch
            {
                ret.ErrorText = "";
                ret.Success   = false;
            }

            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Setup the login status control
        /// </summary>
        protected override void Setup()
        {
            base.Setup();

            HTMLDiv <object> container = Helpers.Div();

            container.Style.Display = Display.inlineblock;
            container.Style.MarginLeft("20px");

            string loginUrl   = VirtualPathUtility.ToAbsolute(FormsAuthentication.LoginUrl);
            string defaultUrl = VirtualPathUtility.ToAbsolute(FormsAuthentication.DefaultUrl);

            // Logged in
            if (Singular.Security.Security.HasAuthenticatedUser)
            {
                MEIdentity identity = MEWebSecurity.CurrentIdentity();

                var loginStatus = container.Helpers.DivC("login-status");
                {
                    loginStatus.Attributes["data-ContextMenu"] = "cmSecurity";

                    // User label
                    var userLabel = loginStatus.Helpers.HTMLTag("span", "Hello " + identity.FirstName);
                    {
                        userLabel.Style.Display = Display.inlineblock;
                    }

                    // Icon
                    loginStatus.Helpers.Image().Glyph = Singular.Web.FontAwesomeIcon.user;

                    // Context menu
                    var contextMenu = loginStatus.Helpers.DivC("context-menu-ls");
                    {
                        contextMenu.Attributes["id"] = "cmSecurity";
                        contextMenu.Style.TextAlign  = Singular.Web.TextAlign.right;

                        var contextMenuMain = contextMenu.Helpers.DivC("CM-Main");
                        {
                            var contextMenuMainHeader = contextMenuMain.Helpers.Div();
                            {
                                contextMenuMainHeader.AddClass("CM-Header");
                                contextMenuMainHeader.Helpers.Div().Helpers.HTML(identity.UserNameReadable);
                                contextMenuMainHeader.Helpers.Div().Helpers.HTML(identity.EmailAddress);
                            }

                            var contextMenuBody = contextMenuMain.Helpers.Div();
                            {
                                contextMenuBody.AddClass("Selectable");

                                // Uncomment if you have an edit profile page
                                var contextMenuEditProfile = contextMenuBody.Helpers.Div();
                                {
                                    contextMenuEditProfile.Helpers.LinkFor(null, null, VirtualPathUtility.ToAbsolute("~/Users/UserProfile.aspx?UserID=" + HttpUtility.UrlEncode(Singular.Encryption.EncryptString(identity.UserID.ToString()))), "Edit Profile");
                                }

                                // Change password
                                var contextMenuChangePassword = contextMenuBody.Helpers.Div();
                                {
                                    contextMenuChangePassword.Helpers.LinkFor(null, null, VirtualPathUtility.ToAbsolute("~/Account/ChangePassword.aspx"), "Change Password");
                                }

                                // Logout
                                var contextMenuLogout = contextMenuBody.Helpers.Div();
                                {
                                    contextMenuLogout.Helpers.LinkFor(null, null, defaultUrl + "?SCmd=Logout", "Logout");
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Logged out
                var loggedOutDiv = container.Helpers.Div();
                {
                    loggedOutDiv.Style.FontSize = "14px";
                    loggedOutDiv.Helpers.LinkFor(null, null, loginUrl, "Login").Style["text-decoration"] = "none";
                    loggedOutDiv.Helpers.Image().Glyph = FontAwesomeIcon.user;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Setup the login status control
        /// </summary>
        protected override void Setup()
        {
            base.Setup();

            HTMLTag <object> listItem = Helpers.HTMLTag("li");

            listItem.AddClass("dropdown");

            string loginUrl   = VirtualPathUtility.ToAbsolute(FormsAuthentication.LoginUrl);
            string defaultUrl = VirtualPathUtility.ToAbsolute(FormsAuthentication.DefaultUrl);

            // Logged in
            if (Singular.Security.Security.HasAuthenticatedUser)
            {
                MEIdentity identity = MEWebSecurity.CurrentIdentity();

                var aTagUserName = listItem.Helpers.HTMLTag("a");
                aTagUserName.AddClass("dropdown-toggle count-info");
                aTagUserName.Attributes["data-toggle"] = "dropdown";
                {
                    aTagUserName.Helpers.HTML(MELib.CommonData.Lists.ROUserList.GetItem(identity.UserID).FullName);
                    var iTagUserName = aTagUserName.Helpers.HTMLTag("i");
                    iTagUserName.AddClass("fa fa-angle-down fa-lg");
                }

                var ulTagDropDown = listItem.Helpers.HTMLTag("ul");
                ulTagDropDown.AddClass("dropdown-menu animated fadeInRight");
                {
                    var liTagEditProfile = ulTagDropDown.Helpers.HTMLTag("li");
                    {
                        var aTagEditProfile = liTagEditProfile.Helpers.HTMLTag("a");
                        aTagEditProfile.Attributes["href"] = VirtualPathUtility.ToAbsolute("~/Users/UserProfile.aspx?UserID=" + HttpUtility.UrlEncode(Singular.Encryption.EncryptString(identity.UserID.ToString())));
                        {
                            var iTagEditProfile = aTagEditProfile.Helpers.HTMLTag("i");
                            iTagEditProfile.AddClass("fa fa-user pad_5_right");
                        }
                        aTagEditProfile.Helpers.HTML("Edit Profile");
                    }

                    var liDivider = ulTagDropDown.Helpers.HTMLTag("li");
                    liDivider.AddClass("divider");

                    var liTagChangePassword = ulTagDropDown.Helpers.HTMLTag("li");
                    {
                        var aTagChangePassword = liTagChangePassword.Helpers.HTMLTag("a");
                        aTagChangePassword.Attributes["href"] = VirtualPathUtility.ToAbsolute("~/Account/ChangePassword.aspx");
                        {
                            var iTagChangePassword = aTagChangePassword.Helpers.HTMLTag("i");
                            iTagChangePassword.AddClass("fa fa-lock pad_5_right");
                        }
                        aTagChangePassword.Helpers.HTML("Change Password");
                    }

                    var liDivider1 = ulTagDropDown.Helpers.HTMLTag("li");
                    liDivider1.AddClass("divider");

                    var liTagLogout = ulTagDropDown.Helpers.HTMLTag("li");
                    {
                        var aTagLogout = liTagLogout.Helpers.HTMLTag("a");
                        aTagLogout.Attributes["href"] = defaultUrl + "?SCmd=Logout";
                        {
                            var iTagLogout = aTagLogout.Helpers.HTMLTag("i");
                            iTagLogout.AddClass("fa fa-sign-out pad_5_right");
                        }
                        aTagLogout.Helpers.HTML("Log Out");
                    }
                }
            }
            else
            {
                // Logged out
                var aLogin = listItem.Helpers.HTMLTag("a");
                {
                    var iTagUserName = aLogin.Helpers.HTMLTag("i");
                    iTagUserName.AddClass("fa fa-sign-in fa-lg");
                    aLogin.Attributes["href"] = loginUrl;
                    aLogin.Helpers.HTML("Log In");
                }
            }
        }