Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'include.php';
- $error = '';
- if ( isset( $_POST['login'] ) )
- {
- if ( !$_POST['username'] or !$_POST['password'] )
- {
- $error = "Please enter your username and password.";
- }
- else
- {
- $idType = 'username';
- $id = $_POST['username'];
- $_member = NULL;
- if ( $_member = $db->query( "SELECT * FROM members WHERE username='". $db->escape_string( $_POST['username'] ) ."'" )->fetch_array() )
- {
- $idType = 'id';
- $id = $_member['connect_id'];
- }
- $login = file_get_contents( $masterUrl . '?' . http_build_query( array( 'act' => 'login', 'idType' => $idType, 'id' => $id, 'password' => md5( $_POST['password'] ) ) ) );
- if ( $login = @json_decode( $login, TRUE ) )
- {
- switch ( $login['connect_status'] )
- {
- case 'SUCCESS':
- // Load local member
- $member = $db->query( "SELECT * FROM members WHERE connect_id=". intval( $login['connect_id'] ) )->fetch_array();
- // If we can't load based of the connect ID, but we already loaded off the username, update the connect ID
- if ( isset( $_member['id'] ) and !isset( $member['id'] ) )
- {
- $member = $_member;
- $db->query( "UPDATE members SET connect_id=". intval( $login['connect_id'] ) ." WHERE id={$_member['id']};" );
- }
- // If we don't have a member, create one
- if ( !isset( $member['id'] ) )
- {
- $db->query( "INSERT INTO members ( username, email, password, connect_id ) VALUES ( '". $db->escape_string( $login['connect_username'] ) ."', '". $db->escape_string( $login['connect_email'] ) ."', '". md5( $_POST['password'] ) ."', ". intval( $login['connect_id'] ) ." )" );
- }
- // Or update our existing one
- else
- {
- $db->query( "UPDATE members SET username='". $db->escape_string( $login['connect_username'] ) ."', email='". $db->escape_string( $login['connect_email'] ) ."', password='".md5( $_POST['password'] )."' WHERE id={$member['id']};" );
- }
- // Log the user in ....
- setcookie( 'ipsce_user', $login['connect_username'], time()+60*60*24*30 );
- setcookie( 'ipsce_pass', md5( $_POST['password'] ), time()+60*60*24*30 );
- // And redirect
- $redirect = base64_encode( str_replace( 'login.php', 'index.php', $_SERVER['HTTP_ORIGIN'] . $_SERVER['PHP_SELF'] ) );
- header( 'Location: ' . $masterUrl . '?' . http_build_query( array( 'act' => 'login', 'idType' => $idType, 'id' => $id, 'password' => md5( $_POST['password'] ), 'key' => md5( $masterKey . $id ), 'redirect' => $redirect, 'redirectHash' => md5( $masterKey . $redirect ), 'noparams' => '1' ) ) );
- exit;
- case 'WRONG_AUTH':
- $error = "Password incorrect.";
- break;
- case 'NO_USER':
- $error = "Could not locate a user with that username.";
- break;
- case 'ACCOUNT_LOCKED':
- $minutes = ceil( $login['connect_unlock'] / 60 );
- $error = "Your account is locked. Please try again in {$minutes} minutes.";
- break;
- case 'VALIDATING':
- $error = "You must validate your account before you can log in. <a href='{$login['connect_revalidate_url']}' target='_blank'>Resend Validation Email</a>";
- break;
- case 'MISSING_DATA':
- default:
- $error = "We could not log you in. Please try again later.";
- break;
- }
- }
- else
- {
- $error = "We could not log you in. Please try again later.";
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>IPS Connect - Slave Example</title>
- <meta charset='utf-8' />
- <link rel='stylesheet' href='resources/ipb_styles.css' media='all' />
- </head>
- <body id='ipboard_body'>
- <div id='header_bar' class='clearfix'>
- <div class='main_width'>
- <ul id='admin_bar' class='ipsList_inline left'>
- <li><a href='index.php'>Home</a></li>
- </ul>
- </div>
- </div>
- <div id='content'>
- <?php if ( isset( $_GET['register'] ) ): ?>
- <div class='message'>
- Account created successfully. You can now log in.
- </div>
- <br />
- <?php endif; ?>
- <form action='login.php' method='post'>
- <input type='hidden' name='login' value='1' />
- <div class='ipsBox_container ipsPad'>
- <ul class='ipsForm ipsForm_vertical'>
- <li class='ipsField'>
- <label class='ipsField_title'>Username <span class='ipsForm_required'>*</span></label>
- <div class='ipsField_content'>
- <input class='input_text' name='username' value='<?= ( isset( $_POST['username'] ) ? $_POST['username'] : '' ) ?>' />
- </div>
- </li>
- <li class='ipsField'>
- <label class='ipsField_title'>Password <span class='ipsForm_required'>*</span></label>
- <div class='ipsField_content'>
- <input class='input_text' name='password' type='password' value='<?= ( isset( $_POST['password'] ) ? $_POST['password'] : '' ) ?>' />
- <?php if ( $error ): ?>
- <br />
- <span class='error'><?= $error ?></span>
- <?php endif; ?>
- </div>
- </li>
- </ul>
- </div>
- <fieldset class='submit'>
- <input type='submit' class='input_submit' value='Submit' />
- </fieldset>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement