Sky-login is a login module library work as standalone.
current-stable : 0.1.4
- php (must 5.3.0 or later)
- PDO Mysql
- mysql (recommend 5.5 or later)
*If you want to run tests, You have to install phpunit. https://github.com/sebastianbergmann/phpunit/
Avalable as composer package.
First, Adds bellow codes in composer.json
{
"repositories": [
{
"type": "package",
"package": {
"name": "polyrhythm-inc/sky-login",
"version": "current-stable",
"source": {
"url": "https://github.com/polyrhythm-inc/sky-login.git",
"type": "git",
"reference": "current-stable"
},
"require": {
"php-activerecord/php-activerecord": "1.1.2"
},
"autoload": {
"classmap": [
"lib/configure",
"lib/exception",
"lib/http",
"lib/model",
"lib/platform",
"lib/storage",
"lib/util"
],
"files": [
"./SkyLogin.php"
]
}
}
}
],
"require": {
"polyrhythm-inc/sky-login": "current-stable"
}
}composer install and ls migrate.
!! Before enter commands written in bellow, You need to create database for Sky-login module.
$ composer install
$ cd sky-login
$ bin/sl migrate -c username:password@localhost[:port]/dbname<?php require 'SkyLogin.php'; \SkyLogin\Datastore::add('default', array( 'host' => 'localhost', 'port' => null, 'user' => 'user', 'passwd' => 'pass', 'db' => 'skylogin', ) ); \SkyLogin\Configure::write('securitySalt', 'o1ty8ha@-m^'); //If you want to use the role on sky-login, you need to set the path to your role configuration json file. \SkyLogin\model\Role::setJsonPath('/path/to/your/role.json'); //initialize SkyLogin Module \SkyLogin\Platform::initialize('SessionLogin');
$req = new \SkyLogin\http\Request(); if($req->isPost() && !is_null($req->post('user_name')) && !is_null($req->post('email')) && !is_null($req->post('password')) ) { //handle request $userName = $req->post('user_name'); $email = $req->post('email'); $password = sha1( $req->post('password') . SkyLogin::get('securitySalt') ); $role = $req->post('role'); //user registration $status = \SkyLogin\Platform::register( array( 'user_name' => $userName, 'email' => $email, 'password' => $password, 'role' => $role, 'hash_id' => sha1($userName . microtime() . mt_rand(0,1000)) ), array( //Can add function to transaction block in this method. function($me){ \SkyLogin\model\UserRole::add(array('user_id' => $me['id'], 'role_id' => 1)); }, function($me){ \SkyLogin\model\UserDevice::add(..... } ) ); //login \SkyLogin\Platform::login( array( 'login' => $userName , 'password' => $password )); } \SkyLogin\Platform::auth(function($me){ $isAuthorized = \SkyLogin\Platform::isAuthorized(); if($isAuthorized){ header('Location: /sky-login/sample/login.php'); } });
Writte in lib/config/core.php default.
To use in order to complicate the password.
Configure::write('securitySalt', '76hba\^-/:[peyu64@jhk*a1');
Enable this option, if you want to use user_id which is not a auto increment value.
System will generate randome hashid and add it to user_id_relations table which relates users.user_id_relation_sequence_id.
Configure::write('enableUserhashId', true);
Can auto login, when device_id and platform_id(ios or android) are transmited from client.
Configure::write('enableAutoLoginWithDeviceId', false);
Enable email based authentication
Configure::write('enableEmailAuth', true);
Enable name based authentication
Configure::write('enableNameAuth', true);
If both of enableEmailAuth and enableNameAuth are 'true', You can login either email or user_name.
If this configuration value is true, System attach user role data to $me(getable Platform::auth() callback arg) and return value of Platform::currentUser()
Configure::write('enableContainUserRoleData', true);
Can auto login, if cookie values for skylogin are transmited from client and they have verify value.
Configure::write('enableAutoLoginWithCookie', false);
Configure::write('cookieAuthExpires', 86400);
Configure::write('cookieName', '__sltk__');
\SkyLogin\Platform::auth(function(){
//some logic here...
});
\SkyLogin\Platform::login(array( 'email' => 'hogehoge', 'password' => 'fugafuga' ));
Do registration based on $params.
If you want to add some logic in transaction block, you need to give function list to second arg.
\SkyLogin\Platform::login(array( 'email' => 'hogehoge', 'password' => 'fugafuga' ));
Destruct all user data on session and cookie.
\SkyLogin\Platform::logout();
\SkyLogin\Platform::hasRole('admin'); // Serch based on role name from role.json .
\SkyLogin\Platform::hasRole(1); // Serch based on role id from role.json.
--
--
--
--
--
--
$ cd sky-login $ export PHP_ENV=development && export SKY_LOGIN_DB_CONFIG_FILE_PATH=/path/to/your/test_db_config.php $ phpunit test/
Hogehoge inc.