embedd login form into website

Discussion in 'Tips/Tricks/Mods' started by giftsnake, Oct 27, 2009.

  1. LKTechnik

    LKTechnik New Member

    OK... to many pn's an support request

    For place an login form on your Page you must use this code:

    HTML:
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
    
    <form name="ajaxform" id="ajaxform"  method="POST"  >
        <input type="hidden" name="s_mod" value="login">
        <input type="hidden" name="s_pg" value="index">
        <input name="username" id="username" value="" size="30" maxlength="255" type="text">
        <input name="passwort" id="passwort" value="" size="30" maxlength="255" type="password">
        <button type="submit" class="button" value=""  ><span>Anmelden</span></button>
    </form>
    
    <script type="text/javascript">
        //callback handler for form submit
        $("#ajaxform").submit(function()
        {
            var postData = $(this).serializeArray();
            $.ajax({
                url : 'https://isp.tld:8080/content.php',
                type: "POST",
                data : postData,
                xhrFields: {withCredentials: true},
                success:function(){
                    window.location.replace("https://isp.tld:8080/index.php");
                }
            });
            return false;
        });
    </script>
    Replace https://isp.tld:8080 with your ISPConfig URL (2 times)

    For an Auto Login and redirect your user to the ISPConfig Page use this snipped

    HTML:
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
    <script type="text/javascript"> 
    
    function weiterleitung() { 
        $.ajax({ 
        type: "post", 
        url: "https://isp.tld:8080/content.php", 
        data: "s_mod=login&s_pg=index&username=USERNAME&passwort=PASSWORD", 
        xhrFields: {withCredentials: true} 
        }).done(function(){location.href='https://isp.tld:8080/index.php'}); 
    
    } 
    window.setTimeout("weiterleitung()", 100); 
    
    
    </script> 
    Replace https://isp.tld:8080 with your ISPConfig URL (2 times)
    Replace USERNAME and PASSWORD with the Users data


    for both snippes you must change the /usr/local/ispconfig/interface/lib/config.inc.local.php
    and Add the folowing lines
    HTML:
        header('Access-Control-Allow-Origin: http://www.yoururl.tld'); 
        header('Access-Control-Allow-Methods: POST'); 
        header('Access-Control-Allow-Credentials: true');
    replace http://www.yoururl.tld with the url with the orgin of your request


    and it sucks i dont can change my posts
     
    ac15, DDArt and jossmalo like this.
  2. webguyz

    webguyz Active Member HowtoForge Supporter

    LKTechnik,

    Started using your login script in my setup and its working great. The only issue I'm having is that Internet Explorer does not work with the script, but Firefox and Chrome work fine. Any ideas as to why IE doesn't like it? When I run the script it takes me to the login page and has the login/password. I tried version 11 and other versions but no go with IE.

    Thanks!
     
  3. Andrew Roosevelt

    Andrew Roosevelt New Member

    Thanks for this, but can you explain it shortly so I can speak with my developer? (I am no developer)
     
  4. LKTechnik

    LKTechnik New Member

    @webguyz
    on IE6-8 its normaly jquery dose not work in ie6
    URI: http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js
    Meldung: '$' is undefined

    i think this snipped is the best way
    Code:
    <!--[if lte IE 8]>
    <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <![endif]-->
    here is the same problem:
    http://stackoverflow.com/questions/18779637/jquery-2-0-3-not-working-with-ie



    @Andrew Roosevelt
    did you read the full thread?

    if you have no idea what the snipped is do, why you need it?
    if you only have problem to understand how the code work -> you dont need it for this you have your developer...
     
  5. radim_h

    radim_h Member HowtoForge Supporter

    Hello,
    Thank you LKTECHNIK, it works great.
    I have one question, do you know how to logoff before login with the script ?

    I'm using "Auto Login and redirect your user to the ISPConfig Page". User can have more Login buttons with more variables in his account (in WHMCS). If he is allready logged in and click on different username/login button ajax keeps the first login on page..

    So i have to request logoff fist, try somehow if logoff is done and sent new variables then...

    Regards
    RH
     
  6. Franco Quijano

    Franco Quijano New Member

    hello, im trying to get the softaculous auto-install api to work with ispconfig3, the script ask for an url to log in with (they have there an example to do so with cpanel) but there is no way to log in like that with ispconfig3?

    This is the code for calling the login for the autoinstall api (cpanel style):

    PHP:
    @set_time_limit(100);
    $new = new Soft_Install();
    $new->login 'https://user:[email protected]:2083/frontend/x3/softaculous/index.live.php';
    $new->data['softdomain'] = 'domain.com'// OPTIONAL - By Default the primary domain will be used
    $new->data['softdirectory'] = 'folder'// OPTIONAL - By default it will be installed in the /public_html folder
    $new->data['admin_pass'] = 'qwerty';
    $new->data['admin_email'] = '[email protected]';
    $res $new->install(26); // Will install WordPress
    if($res == 'installed'){
        echo 
    'Installed';
    }else{
        echo 
    $res// A serialized array of error will be returned
    }

    I was trying to make the snipped of this thread to work with this code with no luck...

    thanks for your help
     
  7. Franco Quijano

    Franco Quijano New Member

    Done!

    PHP:
    $new = new Soft_Install();
    $new->cookie=$_COOKIE['PHPSESSID'];
    $new->login 'https://yourispconfig3:port/softaculous/index.php';
    Thats the trick to get the cookie to work with softaculous auto install api after login with LKTechnik's code...
     
    webguyz likes this.
  8. Franco Quijano

    Franco Quijano New Member

    Now... how to logout? hahaha
     
  9. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    I didn't read much but as long as $_COOKIE['PHPSESSID']; holds the current php session_id you can
    Code:
    session_destroy();
    session_regenerate_id(true);
    
     
  10. webguyz

    webguyz Active Member HowtoForge Supporter

    LKTechnik,
    Tried to use the code that was working great with 3.0x with 3.1 and just get a screen 'Connecting to Control Panel'
    Using your code for Auto Login and redirect your user to the ISPConfig Page
    Do you know if this code works with 3.1?
    Thanks!
     
  11. webguyz

    webguyz Active Member HowtoForge Supporter

    Ok, figured out the solution thanks to cwispy.
    For the auto login script to work in 3.1 change the 2 lines:
    ------------------------------------------------------------
    url: "https://isp.tld:8080/content.php",
    data: "s_mod=login&s_pg=index&username=USERNAME&passwort=PASSWORD",
    -------------------------------------------------------------
    to:
    --------------------------------------------------------------------
    url: "https://isp.tld:8080/login/index.php",
    data: "s_mod=login&s_pg=index&username=USERNAME&password=PASSWORD",
    ---------------------------------------------------------------
     
    Last edited: Nov 2, 2016

Share This Page