EasyLogin v1.3
User Membership System
Thank you for purchasing my script. If you have any questions that are beyond the scope of this help file, please feel free to email via my user page contact form here. Thanks so much!
This script requires at least PHP 5.3 (with PDO) MySQL, OpenSSL, cURL.
Watch the video & read the information bellow:
-
Extract the files from easylogin/ folder (or just copy the entire folder) to your sever / localhost server.
-
Create a new database from your phpMyAdmin or cPanel, then import easylogin.sql to that database.
-
Edit config.php and set home_url to your website home address (! with a slash / at the end); set script_url to where you have copied the script files (! with a slash / at the end).
-
Set the database connection details with the databse you have created on step #2.
-
(Optional) Go to https://cloud.google.com/console/project create a new Project and enable Google+ API from the APIs tab. Then go to Credentials and create a new Client ID (!! Set your domain url & Authorized redirect URI to a link to connect.php?method=google from the script files; Make sure the url points to that file!), then create te API key. Now copy Client ID, Client secret & API key to config.php.
-
(Optional) Go to https://developers.facebook.com/ and create a new App, then go to the Settings tab and set App Domains to your website domain, Contact Email to your email; Click on the +Add Platform button and select Website then set your Site URL. Now go to the Status & Review tab and make your App public. Now go back to the Settings tab and copy the App ID & App Secret to config.php.
-
(Optional) Go to http://dev.twitter.com/ and create a new App, set your Website url and !! Callback URL to a link to connect.php?method=twitter from the script files. Make sure the url points to that file! (For testing on your localhost use 127.0.0.1 instead of localhost). Now Copy API Key & API Secret to config.php
-
(Optional) You can also set other settings in config.php. More information can be found in the Configuration section bellow.
-
Now you can login using User: admin & Password: admin. (Make sure you change the password)
To integrate this script all you have to do is:
-
First make sure you have included jQuery in your page.
<script src="assets/js/jquery-1.11.0.min.js"></script>
-
Include the load.php file and call load_templates() function;
<?php
// Path to load.php
require_once 'includes/load.php';
$EL = EasyLogin::getInstance();
// Load templates for modals
load_templates();
?>
Now you can use the script functions to do cool things. Here is an example to display Sign in / Sign up buttons as well as the buttons after the user has logged.
<?php if (is_user_logged_in()): ?>
Howdy, <?php echo current_user('username'); ?> |
<a href="#" data-toggle="modal" data-target="#EL_account">My Account</a> |
<?php if (current_user('role') == 'admin'): ?>
<a href="admin/">Admin</a> |
<?php endif; ?>
<a href="#" onclick="EasyLogin.signout();">Sign out</a>
<br><img src="<?php echo current_user('avatar'); ?>" class="user-avatar" width="100" height="100"/>
<?php else: ?>
<a href="#" data-toggle="modal" data-target="#EL_signin">Sign in</a> |
<a href="#" data-toggle="modal" data-target="#EL_signup">Sign up</a>
<?php endif; ?>
As in the example above the butons have some attributes:
Sign in button with data-toggle="modal" data-target="#EL_signin"
<a href="#" data-toggle="modal" data-target="#EL_signin">Sign in</a>
Sign up button with data-toggle="modal" data-target="#EL_signup"
<a href="#" data-toggle="modal" data-target="#EL_signup">Sign up</a>
My Account button with data-toggle="modal" data-target="#EL_account"
<a href="#" data-toggle="modal" data-target="#EL_account">My Account</a>
Sign out button with onclick="EasyLogin.signout();"
<a href="#" onclick="EasyLogin.signout();">Sign out</a>
In this section are described all settings from the config.php file.
Note: To access any config item from config.php use $EL->config_item('item_from_config');
-
home_url - Website home address (eg. http://mywebsite.com/) with a slash / at the end;
-
script_url - A link to the script folder; if your website is http://mywebsite.com/ and you have copied the files to the root then the script_url is the same as your website url. BUT if you have copied the files to a folder, like easylogin/ then the script_url is http://mywebsite/easylogin/ (don't forget the slash at the end);
-
db - Database connection details:
-
name - database name
-
user - database user
-
pass - database password
-
host - database host (usualy is localhost)
-
email - Email information
-
from_name - The name that will apear in the emails that are sent to users. Default: empty;
-
from_name - The email that will apear in the emails that are sent to users. Default: empty;
-
phpmailer - (true/false) - Enables/disables the PHPMailer class for sending emails. Default: true;
-
api_keys - Array with all the api keys that are used (ReCaptcha, Google+, Facebook, Twitter...)
-
login_redirect - Redirect URL after the user has logged in. Default empty;
-
require_username - (true/false) - Enables/disables the username input. Default: true;
-
require_name - (true/false) - Enables/disables the name input. Default: true;
-
require_captcha - (true/false) - Enables/disables captcha. It's highly recommended to be enabled (true). Default: true;
-
email_activation - (true/false) - Enables/disables email activation. It's recommended to be enabled (true). Default: true;
-
default_role - The default role to be assigned to the new users. Default: 'user';
-
upload_dir - Path to the folder where the avatars are uploaded (with a slash / at the end). Default: 'uploads/';
-
default_avatar - Default Gravatar type (mm/ identicon/ monsterid/ wavatar) or image url. Default: 'mm';
-
encryption_algorithm - The encryption algorithm used to encrypt the passswords. If changed the passwords will not be longed compatible, a reset password will be required. Recommended to be changed only the first time. The algorithm can be: 'md5' , 'sha256' , 'haval160,4' , 'bcrypt' or any other one from here. Default: md5;
-
auth_salt - A random string to secure the passwords better. If changed the passwords will not be longed compatible, a reset password will be required. Default: empty;
-
session_name - Name of the session where are stored the data for the logged user. Default: 'easylogin';
-
custom_fields - Array of custom fields. Please reffer to the Custom Fields section for more details;
-
email_templates - Array with templates for the emails;
The custom fields can be text. textarea, checkbox, select;
To add custom fields edit config.php and add the type of custom field you want.
Example:
//Custom fields
'custom_fields' => array(
array(
'type' => 'textarea', // Custom field type
'name' => 'about', // Custom field name
'label' => 'About' // Custom field label
),
),
To validate the custom fields edit includes/functions.php and add a validation callback function
function validate_custom_field_about($val) {
// Validation logic
return true / false;
}
The function name is validate_custom_field_about where about is the name of the field defined in the custom_fields array. The function must return true or false.
To get the value of a custom field use: get_usermeta($user_id, $meta_key). For more functions go to the Functions section bellow.
In this section are described the major functions that you can use. Plase note there are 2 types, functions (like is_user_logged_in()) and methods (like $EL->is_logged());
To use any of the functtions/methods you must include load.php;
Functions:
-
is_user_logged_in() - Checks if the user is logged or not. Returns bool value (true/false);
-
current_user($var) - Returns id / name / username / role / avatar of the current user (eg: current_user('username') will return the username of the logged user). If the user is not logged the function will return false;
-
get_current_user_id() - Returns the id of the current user or false if the user is not logged;
-
get_user_avatar($user_id) - Returns the avatar by user_id.
-
get_userdata($user_id) - Returns the raw data of the user_id (all data from users&usermeta table) or false if the user is not found;
-
get_usermeta($user_id, $meta_key) - Returns the user meta by user_id & meta_key or false if not found;
-
add_usermeta($user_id, $meta_key, $meta_value) - Add user meta;
-
update_usermeta($user_id, $meta_key, $meta_value) - Update user meta;
-
delete_usermeta($user_id, $meta_key) - Delete user meta;
-
signout() - Sign out the current user;
-
get_users() - Returns an array with all the users form database;
-
load_templates() - Loads the html templates required for modals;
Methods (most of the methods are used in the functions above):
Use a method like this:
<?php
$EL = EasyLogin::getInstance(); // Get the instance
$home_url = $EL->config_item('home_url'); // Access the config_item method
?>
To see all the available methods edit EasyLogin.class.php.
HTML
All of the HTML you may want to edit is located in templates.php. Make sure you don't break something.
CSS
The main css is easylogin.css and for the avatar uploader css imgPicker.css
JavaScript
This script requires jQuery.
The main JavaScript files are easylogin.min.js (main file), bootstrap.min.js (for modals), imgPicker.min.js (for avatar uploader). If you want the edit them, edit the uncompressed versions.
PHP
The PHP files are located in the includes/ folder (except config.php)
-
config.php - Configuration file;
-
load.php - Loads all the required files for the script;
-
EasyLogin.class.php - Main class with all of the methods;
-
Database.class.php - PDO Database class;
-
functions.php - Functions;
-
ajax.php - Here are sent all of the ajax requests;
-
imgPicker/ - The script files for avatar uploader (Full script here);
-
oauth/ - Libraries for Google+/Facebook/Twitter authentication;
-
recaptchalib.php - Google ReCaptcha library;
I've used the following libraries:
Once again, thank you so much for purchasing this script. As I said at the beginning, I'd be glad to help you if you have any questions relating to this script. Also if you have any suggestions for new features that you want please let me know.
Cretu Eusebiu,
HazzardWeb