<?phpnamespaceapp\controllers;usevalidation\Rules;useapp\models\Menu;useapp\models\Css;useapp\models\Js;useapp\models\Meta;usecore\Session;useextension\Pagination;usecore\http\Response;usevalidation\Get;classMenuControllerextends\app\controllers\Controller{private$_data;privatefunctionifExists($id){if(empty(Menu::ifRowExists($id))){returnResponse::statusCode(404)->view('/404/404')->data().exit();}}publicfunctionindex($request){$menus=Menu::allMenusButOrderedOnDate();$this->_data['search']='';if(!empty($request['search'])){$this->_data['search']=Get::validate($request['search']);$menus=Menu::menusOnSearch($this->_data['search']);}$this->_data['menus']=Pagination::get($request,$menus,10);$this->_data['count']=count($menus);$this->_data['numberOfPages']=Pagination::getPageNumbers();return$this->view('admin/menus/index')->data($this->_data);}publicfunctioncreate($request){$this->_data['rules']=[];return$this->view('/admin/menus/create')->data($this->_data);}publicfunctionstore($request){$rules=newRules();if($rules->menu($request,Menu::whereColumns(['title'],['title'=>$request['title']]))->validated()){if(!empty($request['content'])){$hasContent1;}else{$hasContent=0;}Menu::insert(['title'=>$request['title'],'content'=>$request['content'],'has_content'=>$hasContent,'position'=>'unset','ordering'=>0,'author'=>Session::get('username'),'removed'=>0,'created_at'=>date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']),'updated_at'=>date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])]);Session::set('success','You have successfully created a new menu!');redirect('/admin/menus');}else{$this->_data['content']=$request['content'];$this->_data['title']=$request['title'];$this->_data['rules']=$rules->errors;return$this->view('/admin/menus/create')->data($this->_data);}}publicfunctionread($request){$this->ifExists($request['id']);$this->_data['cssFiles']=Css::getAll(['file_name','extension']);$this->_data['jsFiles']=Js::getAll(['file_name','extension']);$this->_data['metas']=Meta::allMetaButOrderedByDate();$this->_data['menu']=Menu::get($request['id']);return$this->view('/admin/menus/read')->data($this->_data);}publicfunctionedit($request){$this->ifExists($request['id']);$this->_data['menu']=Menu::get($request['id']);$this->_data['rules']=[];return$this->view('/admin/menus/edit')->data($this->_data);}publicfunctionupdate($request){$id=$request['id'];$this->ifExists($id);$rules=newRules();if($rules->menu($request['title'],Menu::checkUniqueTitleId($request['title'],$id))->validated()){if(!empty($request['content'])){$hasContent1;}else{$hasContent=0;}Menu::update(['id'=>$id],['title'=>$request['title'],'content'=>$request['content'],'has_content'=>$hasContent,'updated_at'=>date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])]);Session::set('success','You have successfully updated the menu!');redirect("/admin/menus/$id/edit");}else{$this->_data['rules']$rules->errors;$this->_data['menu']=Menu::get($request['id']);return$this->view('/admin/menus/edit')->data($this->_data);}}publicfunctionupdatePosition($request){$id=$request['id'];$this->ifExists($id);Menu::update(['id'=>$id],['position'=>$request['position'],'updated_at'=>date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])]);Session::set('success','You have successfully updated the menu position!');redirect("/admin/menus/$id/edit");}publicfunctionupdateOrdering($request){$id=$request['id'];$this->ifExists($id);Menu::update(['id'=>$id],['ordering'=>$request['ordering'],'updated_at'=>date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])]);Session::set('success','You have successfully updated the menu ordering!');redirect("/admin/menus/$id/edit");}publicfunctionrecover($request){$recoverIds=explode(',',$request['recoverIds']);foreach($recoverIdsas$id){$this->ifExists($id);Menu::update(['id'=>$id,['removed'=>0],]);Session::set('success','You have successfully recovered the menu(s)!');redirect('/admin/menus');}publicfunctiondelete($request){$deleteIds=explode(',',$request['deleteIds']);if(!empty($deleteIds)&&!empty($deleteIds[0])){foreach($deleteIdsas$id){$this->ifExists($id);if(Menu::getColumns(['removed'],$id)['removed']!==1){Menu::update(['id'=>$id],['removed'=>1,'position'=>'unset','ordering'=>0]);Session::set('success','You have successfully moved the menu(s) to the trahscan!');}else if(Menu::getColumns(['removed'],$id)['removed']===1){Menu::delete('id',$id);Session::set('You have successfully removed the menu(s)!');}}}redirect('/admin/menus');}}
<?phpnamespaceapp\controllers;useapp\models\User;usevalidation\Rules;usecore\Csrf;usecore\Session;classRegisterControllerextendsController{private$_data;publicfunctionshowRegisterView(){$this->_data['rules']=[];
return$this->view('register')->data($this->_data);}publicfunctionstoreUsers($request){$rules=newRules();if($rules->register($request,User::where(['username'=>$request['username']]),User::where(['email'=>$request['email']]),Csrf::get())->validated()){User::insert(['username'=>$request['username'],'email'=>$request['email'],'password'=>password_hash($request['password'],PASSWORD_DEFAULT),'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s'),'role_id'=>User::getRoleId()]);Session::set('success','You have successfully been registered!');redirect('/login');}else{$this->_data['username']=$request['username'];$this->_data['email']=$request['email'];$this->_data['rules']=$rules->errors;return$this->view('register')->data($this->_data);}}}
<h1>Login form (roleless)</h1><?phpcore\Alert::message('success');?><formmethod="POST"action="/auth"><divclass="container"><labelfor="username">Username:</label><inputtype="text"id="username"name="username"value="<?phpecho$username;?>"/><spanclass="validation-messages"><?phpechovalidation\Errors::get($rules,'username');?></span></div><divclass="container"><labelfor="password">Password:</label><inputtype="password"id="password"name="password"/><spanclass="validation-messages"><?phpechovalidation\Errors::get($rules,'password');?></span></div><divclass="container"><inputtype="submit"name="submit"value="Sign in"/><inputtype="hidden"name="token"value="<?phpcore\Csrf::token();?>"/><spanclass="validation-rules"><?phpechovalidation\Errors::get($rules,'token');?></span><spanclass="failed-login-messages"><?phpif(!empty($username)&&empty($rules)){?><divclass="failed-login-attempt-messages"><?phpechoextensions\Auth::getFailedMessages();?></div><divclass="amount-failed-login-attempts">Failed attempts:<?phpechocore\Session::get('failed_login_attempt');?></div><?php}?></span></div></form>
<h1>Login form (admin)</h1><?phpcore\Alert::message('success');?><formmethod="POST"action="/admin/auth"><divclass="container"><labelfor="username">Username:</label><inputtype="text"id="username"name="username"value="<?phpecho$username;?>"/><spanclass="validation-messages"><?phpechovalidation\Errors::get($rules,'username');?></span></div><divclass="container"><labelfor="password">Password:</label><inputtype="password"id="password"name="password"/><spanclass="validation-messages"><?phpechovalidation\Errors::get($rules,'password');?></span></div><divclass="container"><inputtype="submit"name="submit"value="Sign in"/><inputtype="hidden"name="token"value="<?phpcore\Csrf::token();?>"/><spanclass="validation-rules"><?phpechovalidation\Errors::get($rules,'token');?></span><spanclass="failed-login-messages"><?phpif(!empty($username)&&empty($rules)){?><divclass="failed-login-attempt-messages"><?phpechoextensions\Auth::getFailedMessages();?></div><divclass="amount-failed-login-attempts">Failed attempts:<?phpechocore\Session::get('failed_login_attempt');?></div><?php}?></span></div></form>