Skip to content

Commit 845d621

Browse files
committed
first commit
0 parents  commit 845d621

File tree

482 files changed

+82116
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

482 files changed

+82116
-0
lines changed

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/public/tmp
2+
/public/compressed
3+
/storage/*
4+
/vendor

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"# CodeHive-F3"
2+
"# CodeHive-F3"

app/App.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Prefab;
6+
7+
class App extends Prefab {
8+
public $app;
9+
public $authenticatedUser = false;
10+
11+
public function __construct() {
12+
$this->app = f3();
13+
$this->authenticatedUser = $this->authenticated();
14+
}
15+
16+
public function authenticated() {
17+
return $this->authenticatedUser = $this->app->get('SESSION.USER')?:false;
18+
}
19+
}

app/Controllers/AuthController.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
class AuthController extends Controller {
6+
public function getRegister() {}
7+
8+
public function postRegister() {}
9+
10+
public function getLogin() {
11+
template('auth\login')
12+
}
13+
14+
public function postLogin() {}
15+
16+
public function getLogout() {}
17+
18+
public function getReset() {}
19+
20+
public function postEmailPassword() {}
21+
22+
public function getPasswordResetToken() {}
23+
24+
public function postReset() {}
25+
}

app/Controllers/Controller.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
abstract class Controller {
6+
protected $app;
7+
8+
public function __construct() {
9+
$this->app = f3();
10+
}
11+
}

app/Controllers/DesktopController.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
use FAL\LocalFS;
6+
use App\Models\Desktop;
7+
8+
class DesktopController extends Controller {
9+
protected $model;
10+
protected $fs;
11+
12+
public function __construct() {
13+
parent::__construct();
14+
$this->model = new Desktop();
15+
$this->fs = new LocalFS($this->model->getPath());
16+
}
17+
18+
public function getIndex() {
19+
template('desktop', ['desktopItems' => array_merge($this->fs->listDir(), $this->fs->listDir('/../default/'))]);
20+
}
21+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
class DirectoryController extends Controller {}

app/Controllers/EditorController.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
use FAL\LocalFS;
6+
use App\Models\FS;
7+
8+
class EditorController extends Controller {
9+
protected $model;
10+
protected $fs;
11+
12+
public function __construct() {
13+
parent::__construct();
14+
$this->model = new FS();
15+
$this->fs = new LocalFS($this->model->getPath());
16+
}
17+
18+
public function getIndex() {
19+
template('editor', ['fileTree' => array_merge($this->fs->listDir(null, null, true), $this->fs->listDir('/../default/', null, true)), 'projects' => true]);
20+
}
21+
}

app/Controllers/FilesController.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
class FilesController extends Controller {}

app/Controllers/IndexController.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
class IndexController extends Controller {
5+
public function getIndex() {
6+
template('index');
7+
}
8+
9+
public function getApiIndex() {
10+
echo json_encode(['success' => true]);
11+
}
12+
}

app/Models/FS.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use DB\SQL\Schema;
6+
7+
class FS extends Model {
8+
protected $id = null, $path = null, $user = null, $table = 'desktop', $fields = array();
9+
10+
public function __construct() {
11+
$this->user = user();
12+
$this->fields = array_merge(array('session_id' => array('belongs-to-one' => ($user?'App\Models\User':'App\Models\Session'))), $this->fields);
13+
parent::__construct();
14+
15+
$this->id = $this->user?:(new Session())->load(array('ip = ? AND agent = ?', $this->app->IP, $this->app->AGENT))->last()->_id;
16+
$this->path = root_path('/storage/root/'.$this->id);
17+
if($this->load(array('session_id = ?', $this->id))->dry()) {
18+
$this->newSession($this->id);
19+
}else{
20+
flash('Session restored!');
21+
}
22+
}
23+
24+
public function getID() {
25+
return $this->id;
26+
}
27+
28+
public function getPath() {
29+
return $this->path;
30+
}
31+
32+
private function newSession($id) {
33+
if(!is_dir($this->path)){mkdir($this->path);}
34+
$this->reset();
35+
$this->copyfrom(array('session_id' => $id), array_keys($this->fieldConf));
36+
$this->save();
37+
}
38+
}

app/Models/Model.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use DB\SQL\Schema;
6+
use DB\Cortex;
7+
8+
abstract class Model extends Cortex {
9+
protected $app;
10+
protected $db = 'DB';
11+
protected $fieldConf = array(
12+
'created_at' => array(
13+
'type' => Schema::DT_TIMESTAMP,
14+
'default' => Schema::DF_CURRENT_TIMESTAMP
15+
),
16+
'updated_at' => array(
17+
'type' => Schema::DT_TIMESTAMP,
18+
'default' => '0-0-0 0:0:0'
19+
),
20+
'deleted_at' => array(
21+
'type' => Schema::DT_TIMESTAMP,
22+
'default' => '0-0-0 0:0:0'
23+
)
24+
);
25+
26+
public function __construct() {
27+
if(property_exists($this, 'fields')) {
28+
$this->fieldConf = array_merge($this->fields, $this->fieldConf);
29+
}
30+
31+
parent::__construct();
32+
$this->app = f3();
33+
}
34+
}

app/Models/Profile.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use DB\SQL\Schema;
6+
7+
class Profile extends Model {
8+
protected $table = 'profile',
9+
$fields = array(
10+
'uid' => array(
11+
'belongs-to-one' => 'App\Models\User'
12+
),
13+
'username' => array(
14+
'type' => Schema::DT_VARCHAR128,
15+
'default' => null
16+
),
17+
'privacy' => array(
18+
'type' => Schema::DT_INT4,
19+
'default' => 0
20+
)
21+
);
22+
}

app/Models/Session.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use DB\SQL\Schema;
6+
7+
class Session extends \DB\Cortex {
8+
protected $db = 'DB', $table = 'sessions';
9+
protected $fieldConf = array(
10+
'session_id' => array(
11+
'type' => Schema::DT_VARCHAR512
12+
),
13+
'data' => array(
14+
'type' => Schema::DT_TEXT
15+
),
16+
'ip' => array(
17+
'type' => Schema::DT_VARCHAR128
18+
),
19+
'agent' => array(
20+
'type' => Schema::DT_TEXT
21+
),
22+
'stamp' => array(
23+
'type' => Schema::DT_VARCHAR128
24+
),
25+
'desktop' => array(
26+
'has-one' => array('App\Models\Desktop', 'session_id')
27+
)
28+
);
29+
}

app/Models/User.php

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Bcrypt;
6+
use DB\SQL\Schema;
7+
8+
class User extends Model {
9+
protected $table = 'users';
10+
protected $fields = array(
11+
'fName' => array(
12+
'type' => Schema::DT_VARCHAR128,
13+
'required' => true,
14+
'nullable' => false
15+
),
16+
'lName' => array(
17+
'type' => Schema::DT_VARCHAR128,
18+
'required' => true,
19+
'nullable' => false
20+
),
21+
'email' => array(
22+
'type' => Schema::DT_VARCHAR128,
23+
'nullable' => false,
24+
'required' => true,
25+
'unique' => true
26+
),
27+
'password' => array(
28+
'type' => Schema::DT_VARCHAR256,
29+
'nullable' => false,
30+
'required' => true
31+
),
32+
'isActive' => array(
33+
'type' => Schema::DT_BOOLEAN,
34+
'default' => false
35+
),
36+
'desktop' => array(
37+
'has-one' => array('App\Models\Desktop', 'session_id')
38+
)
39+
);
40+
41+
public function set_fName($fName) {
42+
return ucfirst($fName);
43+
}
44+
public function set_lName($lName) {
45+
return ucfirst($lName);
46+
}
47+
public function set_password($pswd) {
48+
return Bcrypt::instance()->hash($pswd);
49+
}
50+
51+
public function create(array $data) {
52+
$this->reset();
53+
$this->copyfrom($data, array_keys($this->fieldConf));
54+
$this->save();
55+
}
56+
57+
public function login($id, $password, $remember = true) {
58+
$user = $this->load(array('_id = :id OR email = :id', array(':id' => $id)));
59+
60+
if($user->dry()) {
61+
error(trans('error.auth.not_registered', $id));
62+
return false;
63+
}
64+
65+
if(!Bcrypt::instance()->verify()) {
66+
error(trans('error.auth.password', $id));
67+
return false;
68+
}
69+
70+
if($remember) {
71+
$this->app->set('SESSION.UID', $user->_id);
72+
}
73+
74+
return true;
75+
}
76+
}

bootstrap/app.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require(__DIR__.'/../vendor/autoload.php');
4+
5+
$f3 = Base::instance();
6+
7+
loadConfig($f3);
8+
loadRoutes($f3);
9+
10+
$db = $f3->set('DB', new DB\Jig($f3->get('DB_PATH'), DB\Jig::FORMAT_JSON));
11+
$session = new DB\Jig\Session($db, 'sessions', null, 'csrf');
12+
13+
$assets = Assets::instance();
14+
$f3->set('ASSETS.onFileNotFound',function($file) use ($f3){
15+
echo 'file not found: '.$file;
16+
});
17+
18+
return $f3;

0 commit comments

Comments
 (0)