package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
HTML::Mason::Component::FileBased->new(
'code' => sub {
use utf8; local $SGN::View::Mason::Commands::m = $HTML::Mason::Commands::m;
HTML::Mason::Exception::Params->throw
    ( error =>
      "Odd number of parameters passed to component expecting name/value pairs"
    ) if @_ % 2;
my ( $goto_url );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }
#line 5 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
     $goto_url = exists $pos{'goto_url'} ? $_[ $pos{'goto_url'} ] :  '/';
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 8 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"

    my $join_breeding_programs = eval{ $c->get_conf('user_registration_join_breeding_programs') };
#line 1 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
$m->print( '
<!-- Login Dialog -->

' );
#line 7 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
$m->print( '
' );
#line 11 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
$m->print( '
<div class="modal fade" id="site_login_dialog" name="site_login_dialog" tabindex="-1" role="dialog" aria-labelledby="site_login_dialog_title">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align:center">
' );
#line 16 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
  if (!$c->config->{require_login}) {
$m->print( '                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
' );
#line 18 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
  }
$m->print( '                <h3 class="modal-title" id="site_login_dialog_title">Login</h3>
            </div>
            <div class="modal-body">
                <form id="login_form" name="login_form">
                    <div class="container-fluid">

' );
#line 25 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
 if ($c->config->{default_login_janedoe}) {
$m->print( '                        <input class="form-control" style="width:240px" id="username" name="username" placeholder="Username" type="text" value="janedoe"/>
                        <br />
                        <input class="form-control" style="width:240px" id="password" name="password" placeholder="Password" type="password" value="secretpw"/>
' );
#line 29 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
 } else {
$m->print( '                        <div class="input-group">
                            <input class="form-control" id="username" name="username" placeholder="Username" type="text" tabindex="1" />
                            <span class="input-group-btn">
                                <button id="forgot_username_modal_show" class="btn btn-default" type="button" tabindex="4">&nbsp;<span class="glyphicon glyphicon-question-sign"></span>&nbsp;</button>
                            </span>
                        </div>
                        <br />
                        <div class="input-group">
                            <input class="form-control" id="password" name="password" placeholder="Password" type="password" tabindex="2" />
                            <span class="input-group-btn">
                                <button id="reset_password_modal_show" class="btn btn-default" type="button" tabindex="5">&nbsp;<span class="glyphicon glyphicon-question-sign"></span>&nbsp;</button>
                            </span>
                        </div>
' );
#line 43 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
 }
$m->print( '                        <br />

                        <div>
                            <input type="checkbox" id="show_password"> Show Password
                        </div>
                        <br />

                        <input type="hidden" value="' );
#line 51 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
$m->print(  $goto_url  );
#line 51 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
$m->print( '" id="goto_url" name="goto_url" />

                        <div>
                            <button class="btn btn-default" id="new_user_modal_show" style="float:left" tabindex="6">New User</button>
                            <button class="btn btn-primary" id="submit_password" name="submit_password" type="submit" style="float:right" tabindex="3">Login</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
' );
#line 61 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
  if (!$c->config->{require_login}) {
$m->print( '                <button id="close_site_login_dialog_button" type="button" class="btn btn-default" data-dismiss="modal" style="float:left">Close</button>
' );
#line 63 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
  }
$m->print( '            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="site_login_forgot_username_dialog" name="site_login_forgot_username_dialog" tabindex="-1" role="dialog" aria-labelledby="site_login_forgot_username_dialog_title">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align:center">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title" id="site_login_forgot_username_dialog_title">Forgot Username</h3>
            </div>
            <div class="modal-body">
                <div>
                    If you\'ve forgotten your username, enter your email address below. An email will be sent with any account username(s) associated with your email address.
                </div>
                <br />
                <div style="white-space:nowrap">
                    <form id="forgot_username_form" name="forgot_username_form" style="white-space:nowrap">
                        <div style="white-space:nowrap; align:center">
                            <label class="textlabel">Email Address</label>
                            <input class="form-control" style="width:200px; white-space:nowrap; float:center" id="forgot_username_email" name="forgot_username_email" /><br />
                            <button type="submit" class="btn btn-primary" id="submit_forgot_username_email" style="float:center" >Get Username(s)</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button id="close_site_login_forgot_username_dialog_button" type="button" class="btn btn-default" data-dismiss="modal" style="float:left">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="site_login_reset_password_dialog" name="site_login_reset_password_dialog" tabindex="-1" role="dialog" aria-labelledby="site_login_reset_password_dialog_title">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align:center">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title" id="site_login_reset_password_dialog_title">Reset Password</h3>
            </div>
            <div class="modal-body">
                <div>
                    To reset your password, please enter your email address. A link will be sent to that address with a link that will enable you to reset your password.
                </div>
                <br />
                <div style="white-space:nowrap">
                    <form id="password_reset_form" name="password_reset_form" style="white-space:nowrap">
                        <div style="white-space:nowrap; align:center">
                            <label class="textlabel">Email Address</label>
                            <input class="form-control" style="width:200px; white-space:nowrap; float:center" id="password_reset_email" name="password_reset_email" /><br />
                            <button type="submit" class="btn btn-primary" id="submit_password_reset_email" style="float:center" >Get link</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button id="close_site_login_reset_password_dialog_button" type="button" class="btn btn-default" data-dismiss="modal" style="float:left">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="site_login_new_user_dialog" name="site_login_new_user_dialog" tabindex="-1" role="dialog" aria-labelledby="site_login_new_user_dialog_title">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align:center">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title" id="site_login_new_user_dialog_title">Create New User</h3>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-10 col-sm-offset-1">

                        <form id="new_account_form">
                            <div class="container-fluid">
                                <div class="panel panel-danger">
                                    <div class="panel-heading">Notice</div>
                                    <div class="panel-body">
                                        <ul>
                                            <li><b>Before</b> creating a new account, please check if you <b>already have an account</b> using the <a href="/search/direct_search.pl?search=directory">directory search</a>. </li>
                                            <li>A link will be emailed to you. Please click on it to activate the account.</li>
                                            <li><b>All fields are required.</b></li>
                                        </ul>
                                    </div>
                                </div>

                                <div class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">First Name: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="text" name="first_name" value="" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Last Name: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="text" name="last_name" value="" />
                                        </div>
                                    </div>
' );
#line 164 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
 if ( $join_breeding_programs ) { 
$m->print( '                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Breeding Program(s): </label>
                                        <div class="col-sm-9">
                                            <div id="breeding_programs_div"></div>
                                      </div>
                                    </div>
' );
#line 171 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
 } else {  
$m->print( '                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Organization: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="text" name="organization" value="" />
                                        </div>
                                    </div>
' );
#line 178 "/home/production/cxgn/sgn/mason/site/login_dialog.mas"
 }
$m->print( '                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Username: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="text" name="username" value="" />
                                            <p class="help-block">Username must be at least 7 characters long.</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Password: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="password" name="password" value="" />
                                            <p class="help-block">Password must be at least 7 characters long and different from your username.</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Confirm Password: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="password" name="confirm_password" value="" />
                                            <p class="help-block">Password must be at least 7 characters long and different from your username.</p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">Email Address: </label>
                                        <div class="col-sm-9">
                                            <input class="form-control" type="text" name="email_address" value="" />
                                            <p class="help-block">An email will be sent to this address requiring you to confirm its receipt to activate your account.</p>
                                        </div>
                                    </div>

                                    <div align="right">
                                        <button class="btn btn-default btn-lg" type="reset" >Reset</button>
                                        <button class="btn btn-primary btn-lg" type="submit" name="create_account" >Create Account</button>
                                    </div>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button id="close_site_login_new_user_dialog_button" type="button" class="btn btn-default" data-dismiss="modal" style="float:left">Close</button>
            </div>
        </div>
    </div>
</div>

<script>
jQuery(document).ready( function() { 

    jQuery("#site_login_dialog").on(\'shown.bs.modal\', function() {
        jQuery(\'#show_password\').prop(\'checked\', false);
        document.getElementById("password").type = "password";
        jQuery("#username").focus();
    });

    jQuery(\'#forgot_username_modal_show\').click(function() {
        jQuery(\'#site_login_forgot_username_dialog\').modal(\'show\');
    });

    jQuery(\'#forgot_username_form\').submit(function(event) {
        event.preventDefault();
        var form_data = jQuery(\'#forgot_username_form\').serialize();
        jQuery.ajax( {
            url: \'/ajax/user/forgot_username\',
            data: form_data,
            error: function(r) { alert(\'An error occurred! Sorry!\');  },
            success: function(r) {
                if (r.error) { alert(r.error); }
                else { 
                    alert(r.message);
                    jQuery(\'#site_login_forgot_username_dialog\').modal(\'hide\');
                }
            }
        });
    });

    jQuery(\'#reset_password_modal_show\').click(function(){
        event.preventDefault();
        jQuery(\'#site_login_reset_password_dialog\').modal(\'show\');
    });

    jQuery(\'#password_reset_form\').submit( function(event) {
        event.preventDefault();
        var form_data = jQuery(\'#password_reset_form\').serialize();
        jQuery.ajax( {
            url: \'/ajax/user/reset_password\',
            data: form_data,
            error: function(r) { alert(\'An error occurred! Sorry!\');  },
            success: function(r) {
                if (r.error) { alert(r.error); }
                else { 
                    alert(r.message);
                    jQuery(\'#site_login_reset_password_dialog\').modal(\'hide\');
                }
            }
        });
    });

    jQuery(\'#show_password\').change(function() {
        var pwd_status = document.getElementById("password");
        console.log(\'type\', pwd_status.type);
        if (pwd_status.type === "password") {
            pwd_status.type = "text";
        } else {
            pwd_status.type = "password"
        }
    });

    jQuery(\'#new_user_modal_show\').click(function(){
        event.preventDefault();
        jQuery(\'#site_login_new_user_dialog\').modal(\'show\');
    });
    jQuery("#site_login_new_user_dialog").on(\'shown.bs.modal\', function() {
        get_select_box(\'breeding_programs\', \'breeding_programs_div\', { \'name\': \'breeding_programs\', \'id\': \'breeding_programs\', \'default\': -1, \'multiple\': 1 });
    });

    jQuery(\'#new_account_form\').submit(function(event) {
        event.preventDefault();
        var form_data = jQuery(\'#new_account_form\').serialize();
        //alert(JSON.stringify(form_data));
        jQuery.ajax({
            url: \'/ajax/user/new\',
            beforeSend: function(){
                jQuery(\'#working_modal\').modal(\'show\');
            },
            data: form_data,
            success: function(r) {
                jQuery(\'#working_modal\').modal(\'hide\');
                console.log(r);
                if (r.error) { alert(r.error); }
                else {
                    let message = r.message || \'New account added. Check your email for the confirmation link - you must confirm your account before you can login.\';
                    alert(message);
                    jQuery(\'#site_login_new_user_dialog\').modal(\'hide\');
                    jQuery(\'#site_login_dialog\').modal(\'hide\');
                }
            }
        });
    });

    jQuery("#username, #password").keydown(function(event) {
        var key = event.keyCode ? event.keyCode : event.which;
        if ( key === 13 ) {
            jQuery("#login_form").submit();
            event.preventDefault();
        }
    });
    jQuery(\'#login_form\').submit( function(event) { 
        event.preventDefault();
        var form_data = jQuery(\'#login_form\').serialize();
        if (!jQuery(\'#username\').val() || !jQuery(\'#password\').val()) { 
            alert(\'Please enter a username and password\');
            return;
        }
        jQuery.ajax( { 
            url: \'/ajax/user/login\',
            data: form_data,
            error: function(r) { alert(\'An error occurred! Sorry!\');  },
            success: function(r) {
                if (r.error) { 
                    alert(r.error);
                    return;
                }
                if (r.goto_url.match(\'login\')) {
                    location.href=\'/\';
                } else if (r.goto_url && r.goto_url !== "" ) { 
                    location.href=r.goto_url;
                } else {
                    location.href=\'/\';
                }
            }
        });
    });

    // Display New User Dialog if `new_user` query param set
    url = new URL(window.location.href);
    if ( url.searchParams.get(\'new_user\') ) {
        jQuery(\'#site_login_new_user_dialog\').modal(\'show\');
    }
});
</script>


<!-- End login dialog -->
' );
;return;
},
'declared_args' => {
  '$goto_url' => { default => ' \'/\'' }
},
'load_time' => 1763079527,

)
;