<%@ Page Title="Title" Language="C#" MasterPageFile="~/Site.Master" %>
<%@ Import Namespace="eDocument.Server.Administrator.User" %>
<script runat="server">

    private void btnResetPassword_OnClick(object sender, EventArgs e)
    {

        //var username = txtUsername.Text.Trim();
        var mail = txtMail.Text.Trim().ToLower();

        if(string.IsNullOrWhiteSpace(mail))
        {
            lblMessage.Text = "Oppgi e-post.";
            return;
        }


        var sendt = LogIn.SendPasswordMail(mail);

        if(sendt)
        {
            lblMessage.Text = string.Empty;
            lblMessageOk.Text = "En e-post med instruksjoner om hvordan du nullstiller passordet ditt er sendt til '" + mail + "'.";
        }
        else
        {
            lblMessageOk.Text = string.Empty;
            lblMessage.Text = "Fant ikke bruker med oppgitt e-postadresse";
        }
    }


</script>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
    <div class="row">
        <div class="col-12 col-lg-6 offset-lg-3">
            <h1 class="skjema-admin__page-title skjema-admin__text-center d-block">
                Nullstill passord
            </h1>
                
            <div class="skjema-admin__mb-20">
                <label class="skjema-admin__page__label">
                    Brukernavn (e-postadresse)
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="txtMail" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
                </label>

                <asp:TextBox 
                    ID="txtMail" 
                    CssClass="skjema-admin__form__input"
                    runat="server" 
                    MaxLength="300">
                </asp:TextBox>
                
                <asp:RegularExpressionValidator runat="server" ControlToValidate="txtMail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic" ErrorMessage="Ugyldig e-postadresse" ForeColor="Red" />
                <asp:Label runat="server" ID="lblEmail" ForeColor="Red"></asp:Label>
            </div>

            <br />
            
            
            <asp:Button 
                ID="btnResetPassword" 
                CssClass="skjema-admin__button skjema-admin__button--primary mb-5"
                runat="server" 
                Text="Nullstill passord" 
                OnClick="btnResetPassword_OnClick">
            </asp:Button>
            
            <br/>
            <asp:Label runat="server" id="lblMessage" ForeColor="Red"></asp:Label><br/>
            <asp:Label runat="server" id="lblMessageOk" ForeColor="Green"></asp:Label>
        </div>
    </div>
</asp:Content>
