diff --git a/libraries/Routes.php b/libraries/Routes.php index 6988a5d..43a7000 100644 --- a/libraries/Routes.php +++ b/libraries/Routes.php @@ -223,6 +223,14 @@ class Url { class Controller { - + public function json($arr_return) { + + $final_return=json_encode($arr_return); + + header('Content-Type: application/json; charset=utf-8'); + + return $final_return; + + } } diff --git a/libraries/Utils.php b/libraries/Utils.php index dcbe96a..5d959fd 100644 --- a/libraries/Utils.php +++ b/libraries/Utils.php @@ -395,13 +395,13 @@ class Utils { //Get randomly elements from the randomly generated array. - $c=count($disorder_abc); + $c=count($disorder_abc)-1; $password_final=''; for($x=0;$x<$length_pass;$x++) { - $num_element_pass=random_int(0, $c-1); + $num_element_pass=random_int(0, $c); $password_final.=$disorder_abc[$num_element_pass]; diff --git a/modules/admin/controllers/app.php b/modules/admin/controllers/app.php index 5410a54..b5a4593 100644 --- a/modules/admin/controllers/app.php +++ b/modules/admin/controllers/app.php @@ -34,148 +34,148 @@ class AppController extends TplController{ $this->db->connect(); - $c_user=$this->db->select_count('', []); + $c_user=$this->db->select_count('useradmin', '', []); if(!$c_user) { header('Location: '.Url::make_url('admin', 'app', ['signup'])); } + else { + + if($_SERVER['REQUEST_METHOD']=='POST') { + + $username=trim($_POST['username']); + $password=trim($_POST['password']); + + $error=1; + + $error_form=['username_error' => '']; + + if($username=='') { + + $error_form['username_error']=_('Username empty'); + + } + + $arr_user=$this->db->select_a_row('useradmin', [], 'WHERE username=?', [$username]); + + if($arr_user) { + + if(password_verify($password, $arr_user['password'])) { + + $error=0; + + $_SESSION['admin_login']=1; + + } + else { + + $error_form['username_error']=_('Wrong user or password'); + + } + + } + else { + + $error_form['username_error']=_('Wrong user or password'); + + } + + echo $this->json(['error' => $error, 'error_form' => $error_form, 'message' => '']); + + } + else { + + echo $this->tpl->load_template('login', ['title' => 'Login']); + + } + + } break; case 'signup': - echo $this->tpl->load_template('signup', ['title' => 'Signup']); + $this->db->connect(); - break; - - case 'login_check': - - /*$conn=MySQL::get_pdo_connection(); + $c_user=$this->db->select_count('useradmin', '', []); - $data=['error' => 1]; - - $username=$_POST['username']; - - $password=$_POST['password']; + if(!$c_user) { - $sth=$conn->prepare('SELECT id, password from useradmin where username=?'); - - $sth->execute([$username]); - - $rows=$sth->fetchAll(); - - if(count($rows)>0) { - - $password_hash=$rows[0]['password']; - - if(password_verify($password, $password_hash)) { + if($_SERVER['REQUEST_METHOD']=='POST') { - $data['error']=0; + $error=0; - $_SESSION['phango_login']=1; + $error_form=[]; + + $arr_data=['username', 'email', 'password', 'repeat_password']; + + foreach($arr_data as $v) { + + settype($_POST[$v], 'string'); + + } + + $username=trim($_POST['username']); + + if(!preg_match('/^[A-Za-z0-9_-]+$/', $username) || $username=='') { + + $error=1; + $error_form['username_error']=_("Error: empty value"); + + } + + $email=filter_var($_POST['email'], FILTER_VALIDATE_EMAIL); + + if(!$email) { + + $error=1; + $error_form['email_error']=_("Error: email is not valid"); + + + } + + $password=trim($_POST['password']); + $repeat_password=trim($_POST['repeat_password']); + + if($password=='') { + + $error=1; + $error_form['password_error']=_("Error: password empty"); + + } + else { + + if($password!=$repeat_password) { + + $error=1; + $error_form['password_error']=_("Error: password not equal"); + + } + + } + + if(!$error) { + + if(!$this->db->insert('useradmin', ['username' => $username, 'password' => password_hash($password, PASSWORD_DEFAULT), 'email' => $email])) { + + $error=1; + + $error_form['username_error']=_("Error: cannot create the user, please contact with the administrator"); + } + + } + + echo $this->json(['error' => $error, 'error_form' => $error_form, 'message' => '']); } - - } - - header('Content-Type: application/json; charset=utf-8'); - - return json_encode($data); - - break; - - case 'register': - - $conn=MySQL::get_pdo_connection(); - - $sth=$conn->query('SELECT count(*) as num_items from useradmin'); - - $count=$sth->fetch()[0]; - - if($count==0) { - - echo View::load_view(['login' => 0], 'login'); - - } - - break; - - case 'signup_check': - - $data=['error' => 0]; - - $arr_data=['username', 'email', 'password', 'repeat_password']; - - foreach($arr_data as $v) { - - settype($_POST[$v], 'string'); - - } - - //$username=$_POST['username']; - //^[A-Za-z0-9_-]+$ - - $username=trim($_POST['username']); - - if(!preg_match('/^[A-Za-z0-9_-]+$/', $username)) { - - $data['error']=1; - $data['username']=_("Error: empty value"); - - } - - $email=filter_var($_POST['email'], FILTER_VALIDATE_EMAIL); - - if(!$email) { - - $data['error']=1; - $data['email']=_("Error: email is not valid"); - - - } - - $password=trim($_POST['password']); - $repeat_password=trim($_POST['repeat_password']); - - if($password=='') { - - $data['error']=1; - $data['password']=_("Error: password empty"); - - } - else { - - if($password!=$repeat_password) { + else { - $data['error']=1; - $data['password']=_("Error: password not equal"); + echo $this->tpl->load_template('signup', ['title' => 'Signup']); } - } - - if($data['error']==0) { - - $password=password_hash($password, PASSWORD_DEFAULT); - - $conn=MySQL::get_pdo_connection(); - - if(!$conn->prepare('INSERT into useradmin (`username`, `password`, `email`) VALUES (?, ?, ?)')->execute([$username, $password, $email])) { - - $data['error']=1; - $data['username']=_("Error: cannot insert the new user in database, check your database connection"); - - } - - //$sth->execute([$username, $password, $email]); - - } - - header('Content-Type: application/json; charset=utf-8'); - - return json_encode($data);*/ break; diff --git a/modules/admin/libraries/tplcontroller.php b/modules/admin/libraries/tplcontroller.php index b471b7f..500b5e6 100644 --- a/modules/admin/libraries/tplcontroller.php +++ b/modules/admin/libraries/tplcontroller.php @@ -3,7 +3,7 @@ use PhangoApp\WPDO; use PhaTemplates\Templates; -class TplController { +class TplController extends PhangoApp\PhaRouter\Controller { public $tpl; public $db; @@ -12,9 +12,9 @@ class TplController { session_start(); - $table=new WPDO\WTable('useradmin', ['username', 'password', 'email']); + $table=new WPDO\WTable('useradmin', ['username', 'password', 'email', 'num_attempts']); - $this->db=new WPDO\WPDO($table); + $this->db=new WPDO\WPDO(['useradmin' => $table]); $this->tpl=new Templates(['theme/admin/templates', 'modules/admin/templates']); diff --git a/modules/admin/media/fonts/FontAwesome.otf b/modules/admin/media/fonts/FontAwesome.otf deleted file mode 100644 index 401ec0f..0000000 Binary files a/modules/admin/media/fonts/FontAwesome.otf and /dev/null differ diff --git a/modules/admin/media/fonts/fontawesome-webfont.eot b/modules/admin/media/fonts/fontawesome-webfont.eot deleted file mode 100644 index e9f60ca..0000000 Binary files a/modules/admin/media/fonts/fontawesome-webfont.eot and /dev/null differ diff --git a/modules/admin/media/fonts/fontawesome-webfont.svg b/modules/admin/media/fonts/fontawesome-webfont.svg deleted file mode 100644 index 855c845..0000000 --- a/modules/admin/media/fonts/fontawesome-webfont.svg +++ /dev/null @@ -1,2671 +0,0 @@ - - - - -Created by FontForge 20120731 at Mon Oct 24 17:37:40 2016 - By ,,, -Copyright Dave Gandy 2016. All rights reserved. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/admin/media/fonts/fontawesome-webfont.ttf b/modules/admin/media/fonts/fontawesome-webfont.ttf deleted file mode 100644 index 35acda2..0000000 Binary files a/modules/admin/media/fonts/fontawesome-webfont.ttf and /dev/null differ diff --git a/modules/admin/media/fonts/fontawesome-webfont.woff b/modules/admin/media/fonts/fontawesome-webfont.woff deleted file mode 100644 index 400014a..0000000 Binary files a/modules/admin/media/fonts/fontawesome-webfont.woff and /dev/null differ diff --git a/modules/admin/media/fonts/fontawesome-webfont.woff2 b/modules/admin/media/fonts/fontawesome-webfont.woff2 deleted file mode 100644 index 4d13fc6..0000000 Binary files a/modules/admin/media/fonts/fontawesome-webfont.woff2 and /dev/null differ diff --git a/modules/admin/templates/login.php b/modules/admin/templates/login.php new file mode 100644 index 0000000..5cd768f --- /dev/null +++ b/modules/admin/templates/login.php @@ -0,0 +1,69 @@ +layout('login_tpl', ['title' => $title])?> +start('content')?> +
+

+

+

+

+ +

+ +

+
+end('content')?> +start('footer_js')?> + +end('footer_js')?> diff --git a/modules/admin/templates/login_tpl.php b/modules/admin/templates/login_tpl.php index 9322c9e..9c9ffc4 100644 --- a/modules/admin/templates/login_tpl.php +++ b/modules/admin/templates/login_tpl.php @@ -69,16 +69,72 @@ background-color: #0056b3; /* Un azul más oscuro */ } + .error { + + color: #ee0000; + + } + + /*Loader layer*/ + + #loader-wrapper { + + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + + background-color: transparent; + + z-index: 99999; + + display: flex; + justify-content: center; + align-items: center; + + opacity: 1; + transition: opacity 0.5s ease-out; + /*display: none;*/ + } + + + .loader-hidden { + opacity: 0; + pointer-events: none; + } + + + .spinner { + border: 8px solid #f3f3f3; + border-top: 8px solid #007bff; + border-radius: 50%; + width: 50px; + height: 50px; + animation: spin 1s linear infinite; + } + + + @keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } + } + section('header_js')?> +
-

Login

+

section('content')?>
+ +section('footer_js')?> diff --git a/modules/admin/templates/signup.php b/modules/admin/templates/signup.php index 9fc653c..4196085 100644 --- a/modules/admin/templates/signup.php +++ b/modules/admin/templates/signup.php @@ -1,14 +1,67 @@ layout('login_tpl', ['title' => 'Signup'])?> start('content')?> +

-

+

-

+

+

- +

+
end('content')?> +start('footer_js')?> + +end('footer_js')?> diff --git a/modules/phatemplates/libraries/templates.php b/modules/phatemplates/libraries/templates.php index bb7877f..7ae36ba 100644 --- a/modules/phatemplates/libraries/templates.php +++ b/modules/phatemplates/libraries/templates.php @@ -15,7 +15,7 @@ class Templates { public $yes_layout=false; public $layout=''; - + public function __construct($search_dir) { $this->search_dir=$search_dir; @@ -28,9 +28,7 @@ class Templates { $template=''; - $this->yes_layout=0; - - //$yes_template=false; + $this->yes_layout=false; $z=0; @@ -48,8 +46,6 @@ class Templates { if($this->yes_layout) { - //$sections_layout=implode("\n", $this->section_content); - $final_template=$this->load_template($this->layout, $args); echo $final_template; @@ -110,12 +106,6 @@ class Templates { echo $this->section_content[$section_name]; } - else { - - echo $section_name.' dont have any content'; - - } - } @@ -131,7 +121,7 @@ class Templates { } /** - * Method for finisha section in a template with a layout + * Method for finish section in a template with a layout * */ @@ -149,5 +139,17 @@ class Templates { return html_entities($str); } + + public function make_url($module, $script='', $args=[]) { + + return \PhangoApp\PhaRouter\Url::make_url($module, $script, $args); + + } + + public function make_media_url($file) { + + return \PhangoApp\PhaRouter\Url::make_media_url($file); + + } }