Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Polyrhythm-Inc/sky-login

Repository files navigation

sky-login

Sky-login is a login module library work as standalone.

Release Notes

current-stable : 0.1.4

System Required Softwares

  • 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/

Installation

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

Usage

initialization

<?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');

Authentication

$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');
 }
});

Explanation of configuration value.

Writte in lib/config/core.php default.

securitySalt

To use in order to complicate the password.

Configure::write('securitySalt', '76hba\^-/:[peyu64@jhk*a1');

enableUserhashId

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);

enableAutoLoginWithDeviceId(Not implemented)

Can auto login, when device_id and platform_id(ios or android) are transmited from client.

Configure::write('enableAutoLoginWithDeviceId', false);

enableEmailAuth

Enable email based authentication

Configure::write('enableEmailAuth', true);

enableNameAuth

Enable name based authentication

Configure::write('enableNameAuth', true);
additianla info

If both of enableEmailAuth and enableNameAuth are 'true', You can login either email or user_name.

enableContainUserRoleData

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);

enableAutoLoginWithCookie(Not implemented)

Can auto login, if cookie values for skylogin are transmited from client and they have verify value.

Configure::write('enableAutoLoginWithCookie', false);

cookieAuthExpires(Not implemented)

Configure::write('cookieAuthExpires', 86400);

cookieName(Not implemented)

Configure::write('cookieName', '__sltk__');

Api reference

\SkyLogin\Platform

auth([function callback])

\SkyLogin\Platform::auth(function(){
 //some logic here...
});

login(array $params)

\SkyLogin\Platform::login(array(
 'email' => 'hogehoge',
 'password' => 'fugafuga'
));

register(array $params, [array $addTransactions])

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'
));

void logout

Destruct all user data on session and cookie.

\SkyLogin\Platform::logout();

bool hasRole(mix $key)

Don't use this method if enableContainUserRoleData is disable.
\SkyLogin\Platform::hasRole('admin'); // Serch based on role name from role.json .
\SkyLogin\Platform::hasRole(1); // Serch based on role id from role.json.

\SkyLogin\model

User

getByUserId(int $userid)
getByUserIdRelationSequenceId(int $sid)
getByNameAndEmailAndPasswd(string $name, string $email, string $password)
getByEmailAndPasswd(string email, string $password)
getByNameAndPasswd(string name, string $password)

--

UserDevice

getByUserId(int $userid)
getByOsTypeIdAndDeviceId(int $osTypeId, string $deviceid)
add(array $params)

--

UserRole

getByUserIdAndRoleId(int $userid, int $roleId)
delteByUserIdAndRoleId(int $osTypeId, string $deviceid)
add(array $params)

--

UserIdRelation

getByHashId(string $hashid)
add(array $params)

--

UserEachPlatformAuthentication

getByPlatformIdAndAuthToken(int $platformid, string $token)
add(array $params)
updateByPlatformIdAndUserId(array $params, int, $platformid, int $userid)

--

Role

getById(int $id)

--

Run Test

$ cd sky-login
$ export PHP_ENV=development && export SKY_LOGIN_DB_CONFIG_FILE_PATH=/path/to/your/test_db_config.php
$ phpunit test/

License

Hogehoge inc.

About

A stand alone login module supported multiple login platforms.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

Languages

AltStyle によって変換されたページ (->オリジナル) /