Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

2. Server tutorial

ruojianll edited this page Sep 4, 2016 · 1 revision

#Create you app

  1. Move into Server dir.
  2. Run composer install to install the dependencies for AliceSPA.
  3. Copy and rename app_empty to the same dir with your app name.
  4. Move into yourAppName/Config dir.
  5. Rename Main.php.example to Main.php.
  6. Configure Main.php, add you roles to Roles.php and add your errors to Errors.php.
  7. Configure php, mysql, http server and run.

#Route, service, middleware and controller AliceSPA in based on slim framework, you can use slim framwork's features to build your app. Server/yourAppName/public/index.php is the entry. First we load the dependency libraries by require $SERVER_PATH . '/vendor/autoload.php'. Next we load config files by require $APP_PATH . '/Config/load.php' and create an intance of \slime\app with settins. Then load AliceSPA's components and register configs. If CORS is setted in config file, we will enable CORS support. Finally $app->run() will match url and handle request.

You can write your own routes, services, middlewares and controllers and load them at correct position in this file. We don't recommand you to modify the structure of index.php generated by AliceSPA.

#Database accessing AliceSPA use Medoo for database accessing. You can get a medoo instance with config in Server/yourAppName/Config/Main.php by a sigleton service provided by AliceSPA.

#AliceSPA You can use slim framework and medoo to do lots of things. AliceSPA provided these features, and more features are in developing.

  • Accout
  • Session stored in database
  • Captcha (image captcha provided by securimage)
  • Accessibility controll: verifying role and captcha automatically.
  • Direct database access (request can modify database table direct without controller under accessibility controll)

##Account

$authServ = \AliceSPA\Service\Authentication::getInstance(); //get accout service instance
$authServ->getUserInfo();//get user info

Login, logout and outhers functions provided by AliceSPA server and client internally. You don't need to develop. See client's tutorial.

##Database

$db = \AliceSPA\Service\Database::getInstance();//get medoo instance

##Session

$sessionServ = \AliceSPA\Service\Session::getInstance();//get session service instance
$sessionServ->getSession();//get session array
$sessionServ->get($key);//get value in session array
$sessionServ->set($Key,$value);//set value in session array

Session will be loaded from database and stored into database, don't care the details.

##Captcha AliseSPA will generate catpcha and verify it automatically. See client's tutorial. Tutorial of developing your captcha services is in developing.

##Accessibility controll ###Role

use \AliceSPA\Helper\Utilities as utils;
utils::secureRoute(
    $app->get(your route info),//a slim framework route
    ['roleName1','roleName2'],//roles for this route or true
    false,false);

User can access api only if the user have logged in and have correct role in the array. If set true, user must have logged in.

Role admin can access all the apis.

Logged in user has role user.

Every one has role visitor.

You can set your roles in Server/yourAppName/Config/Roles.php.

###Captcha

use \AliceSPA\Helper\Utilities as utils;
utils::secureRoute(
    $app->get(your route info),//a slim framework route
    false,
    'image',//type of captcha
    false);

AliceSPA has many types of captcha such as image and SMS.

Every type has many captchas for every visitor, stored in session. User can access api only if any captcha had correct type, id ,code and not expired of this user.

###Direct database access

use \AliceSPA\Helper\Utilities as utils;
utils::secureRoute(
    $app->get(your route info),//a slim framework route
    false,false,
    [//access info
        'tableName1'=>['insert','select'],
        'tableName2'=>['delete','update']
    ]);

User can access database from this api. Table names and its actions specified by access info.

AliceSPA Client provided an interface to support this feature.

Clone this wiki locally