예제 #1
0
 public function put($id)
 {
     $this->app->applyHook('user.put', $id);
     $request = (array) json_decode($this->app->request()->getBody());
     $auth = new \services\Authentication($request['email']);
     if (!$auth->email_available()) {
         $user = $auth->getUser();
         foreach ($request as $key => $value) {
             if ($key == "password" && $value != $user->password) {
                 $user->password = $auth->hash_password($value);
             } else {
                 $user->{$key} = $value;
             }
         }
         $user->save();
         $this->render(200, array('success' => $user->as_array()));
     }
     $this->render(200, array('error' => 'User does not exsist'));
 }
예제 #2
0
파일: Admin.php 프로젝트: netdust/ntdst-cms
        $auth->logout();
        $app->redirect($app->request->getRootUri());
    });
    $app->post('/recover', function () use($app) {
        $param = (array) json_decode($app->request()->getBody());
        $auth = new \services\Authentication($param['email']);
        try {
            $auth->fogottenPassword();
            $app->render(200, array('user' => ''));
        } catch (\services\AuthenticationException $e) {
            $app->render(200, array('error' => 1, 'message' => $e->getMessage()));
        }
    });
    $app->post('/signup', function () use($app) {
        $param = (array) json_decode($app->request()->getBody());
        $auth = new \services\Authentication($param['email'], $param['password']);
        if (!$auth->createUser($param['first_name'], $param['last_name'], $param['company'], $param['phone'], $param['group'])) {
            $app->render(401, array('error' => $auth->getError()));
        }
        $app->render(200, array('success' => 'user signed up'));
    });
    $app->post('/remove', function () {
        echo 'welcome to this api';
    });
});
$app->group('/cms', function () use($app) {
    $app->get('(/)(:slug+)', function ($p = array()) use($app) {
        $settings = array_merge(array("api" => $app->request->getRootUri() . '/api/' . VERSION . '/', "root" => $app->request->getRootUri() . '/cms', "home" => 'pages'), (array) $app->config('theme'));
        $modules = array(array("id" => 1, "name" => "Pages", "icon" => "file-o", "path" => "page"), array("id" => 2, "name" => "Collections", "icon" => "picture-o", "path" => "collection"), array("id" => 3, "name" => "Assets", "icon" => "image", "path" => "asset"), array("id" => 4, "name" => "Users", "icon" => "users", "path" => "user"), array("id" => 5, "name" => "Settings", "icon" => "cog", "path" => "setting", "data" => (array) $app->config('theme')), array("id" => 6, "name" => "Help", "icon" => "question", "path" => "help"));
        $args = (object) array('settings' => $settings, 'modules' => $modules);
        $app->applyHook('admin.before.render', $args);
예제 #3
0
파일: Api.php 프로젝트: netdust/ntdst-cms
 // Common to all sub routes
 $controllerFactory = function (\Slim\Route $route) use($app) {
     $type = $route->getParams();
     $type = array_shift($type);
     $controller = 'api\\Controller\\' . ucfirst($type) . 'Controller';
     if (class_exists($controller)) {
         $app->controller = new $controller();
     } else {
         throw new Exception("Invalid data type given, " . $controller);
     }
 };
 $authenticateForRole = function ($role = 'editor') use($app) {
     return function () use($role, $app) {
         $iscms = (bool) preg_match('|/cms/.*$|', $_SERVER['REQUEST_URI']);
         $isapi = (bool) preg_match('|/api/v.*$|', $_SERVER['REQUEST_URI']);
         $auth = new \services\Authentication();
         if (!$auth->authenticate() || !$app->controller->allowed($auth->user, $role)) {
             throw new Exception("user is not allowed");
         }
     };
 };
 // GET page/1/meta/8
 $app->get('/:model(/:id(/:function(/:fid)?)?)?', $controllerFactory, function ($model, $id = false, $function = false, $fid = false) use($app) {
     $param = $app->request()->get();
     if (!$function) {
         $app->controller->get($id, $model, $param);
     } else {
         if (is_callable(array($app->controller, $function))) {
             call_user_func_array(array($app->controller, $function), array($id, $fid, $param));
         } else {
             throw new Exception("Method does not exist, " . $app->controller);