<%@ Page Title="" Language="C#" MasterPageFile="~/eosWinkartWeb/eosWinkartWeb.Master" AutoEventWireup="true" CodeBehind="changePass.aspx.cs" Inherits="WebKart.eosWinkartWeb.changePass" ValidateRequest="false"%>

<%@ Import Namespace="System.Security.Policy" %>
<%@ Import Namespace="Eos.WebKart.Domain" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var userName = "<%= Personels.PersonnelNo == "eosWebKartAdmin" ? "Admin" :Personels.PersonnelNo %>";

        $(document).ready(function () {
<%--            var isOnLocal = $("#systemSecurityUrl").val();
            if (isOnLocal.toLowerCase() == "true") {
                $("#systemSecurityUrl").val('<%= HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)+ResolveUrl("~/")%>');
            }
            else if (isOnLocal.toLowerCase() == "false") {
                $("#systemSecurityUrl").val(window.location.origin + "/");
            }--%>
            $("input[type='password']").keydown(function (e) {

                if (e.keyCode === 13 || e.which === 13) {
                    e.preventDefault();
                    $("#btnChangePass").click();
                }
            });
        });


        function btnChangePass_click(e) {
            var lblError = $("#lblError");
            lblError.text("");

            var oldPass = $("#txtOldPass").val();
            var newPass = $("#txtNewPass").val();
            var repNewPass = $("#txtRepNewPass").val();

            if (newPass == "" || oldPass == "" || repNewPass == "") {
                lblError.text("وارد کردن کلیه اطلاعات کلمه عبور الزامی است.");
                return;
            }
            if (newPass == oldPass) {
                lblError.text("رمز عبور جدید و قدیم نباید با هم برابر باشند");
                return;
            }


            if (newPass != repNewPass) {
                lblError.text("رمز عبور جدید و تکرار آن با هم برابر نیستند.");
                return;
            }

            var s = new SecurityManager();
            var validationResult = s.validate(userName, newPass);
            if (validationResult != true) {
                lblError.text(validationResult);
                return;
            }

            //var encryptLoginPass = SecurityManager.EncryptLoginPass(userName, oldPass);
            //var encryptNewPass = SecurityManager.EncryptNewPass(newPass);

            var loginresult = SecurityManager.EncryptLoginPass(userName, oldPass);
            var encryptedresult = SecurityManager.EncryptNewPass(newPass);
            if (!loginresult.success) {
                alert(loginresult.message);
                return;
            }

            if (!encryptedresult.success) {
                alert(encryptedresult.message);
                return;
            }
            $("#encryptedNewPass").val(encryptedresult.result);
            $("#encryptedOldPass").val(loginresult.result);
            $("#aspnetForm").submit();
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%--<table width="100%">
        <tr>
            <td colspan="2" class="CenterTD">
                <asp:Label ID="lblError" runat="server" SkinID="LblError" ClientIDMode="Static"></asp:Label>
            </td>

        </tr>
        <tr>
            <td class="RightTD">
                <asp:TextBox ID="txtOldPass" runat="server" SkinID="txtNumber" TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                    ErrorMessage="*" Font-Names="tahoma" Font-Size="10"
                    ControlToValidate="txtOldPass"></asp:RequiredFieldValidator>
            </td>
            <td class="LeftTD" style="width: 200px">رمز ورود قدیم:</td>
        </tr>
        <tr>
            <td class="RightTD">
                <asp:TextBox ID="txtNewPass" runat="server" SkinID="txtNumber" TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                    ErrorMessage="*" Font-Names="tahoma" Font-Size="10"
                    ControlToValidate="txtNewPass"></asp:RequiredFieldValidator>
            </td>
            <td class="LeftTD">رمز ورود جدید:</td>
        </tr>
        <tr>
            <td class="RightTD">
                <asp:TextBox ID="txtRepNewPass" runat="server" SkinID="txtNumber" TextMode="Password"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                    ErrorMessage="*" Font-Names="tahoma" Font-Size="10"
                    ControlToValidate="txtRepNewPass"></asp:RequiredFieldValidator>
                <asp:CompareValidator ID="CompareValidator1" runat="server"
                    ErrorMessage="رمز های جدید وارد کرده یکسان نیستند" Font-Names="Tahoma"
                    Font-Size="10" ControlToCompare="txtNewPass" ControlToValidate="txtRepNewPass"
                    ForeColor="White"></asp:CompareValidator>
            </td>
            <td class="LeftTD">تکرار رمز ورود جدید:</td>
        </tr>
        <tr>
            <td colspan="2"></td>
        </tr>
        <tr>
            <td class="RightTD">
                <asp:Button ID="btnChangePass" runat="server" Text="تغییر رمز ورود"
                    SkinID="btnOrange" OnClick="btnChangePass_Click" />
            </td>
            <td class="LeftTD">
                <asp:Button ID="btnCancle" runat="server" Text="انصراف" SkinID="btnOrange"
                    OnClick="btnCancle_Click" CausesValidation="False" />
            </td>
        </tr>
    </table>--%>


    <table width="100%">
        <tr>
            <td colspan="2" class="CenterTD">
                <asp:Label ID="lblError" runat="server" SkinID="LblError" ClientIDMode="Static"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="RightTD">
                <input id="txtOldPass" type="password" value="" />
            </td>
            <td class="LeftTD" style="width: 200px">رمز ورود قدیم:</td>
        </tr>
        <tr>
            <td class="RightTD">
                <input id="txtNewPass" type="password" value="" />
            </td>
            <td class="LeftTD">رمز ورود جدید:</td>
        </tr>
        <tr>
            <td class="RightTD">
                <input id="txtRepNewPass" type="password" value="" />
            </td>
            <td class="LeftTD">تکرار رمز ورود جدید:</td>
        </tr>
        <tr>
            <td colspan="2"></td>
        </tr>
        <tr>
            <td class="RightTD">
                <asp:Button ID="btnCancle" runat="server" Text="انصراف" SkinID="btnOrange"
                            OnClick="btnCancle_Click" CausesValidation="False" />
                <input id="encryptedNewPass" name="encryptedNewPass" type="hidden" />
                <input id="encryptedOldPass" name="encryptedOldPass" type="hidden" />
                <%--<input id="systemSecurityUrl" name="systemSecurityUrl" type="hidden" value="<%= ConfigurationManager.AppSettings["IsOnLocal"] %>" />--%>
                <asp:Button ID="btnChangePass" ClientIDMode="Static" runat="server" Text="تغییر رمز ورود"
                            SkinID="btnOrange" OnClientClick="btnChangePass_click();return false;" UseSubmitBehavior="False" OnClick="btnChangePass_Click1" />
            </td>
            <td class="LeftTD"></td>
        </tr>
    </table>
</asp:Content>


