commit 773eb1092daea25bdd93d77be3582cbf9f4bf276 Author: Christian Wolf Date: Sat Mar 30 17:01:31 2019 +0100 Initial version with functionality to log into the component using frontend diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..e9e2cb4 --- /dev/null +++ b/.buildpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..b6e535a --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com_clubs + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + + org.eclipse.php.core.PHPNature + org.eclipse.wst.common.project.facet.core.nature + + diff --git a/.settings/org.eclipse.php.core.prefs b/.settings/org.eclipse.php.core.prefs new file mode 100644 index 0000000..d0241b4 --- /dev/null +++ b/.settings/org.eclipse.php.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +include_path=1;/srv/slt-dev diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..76b9d03 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/.directory b/src/.directory new file mode 100644 index 0000000..117a104 --- /dev/null +++ b/src/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,3,30,10,20,7 +Version=4 +ViewMode=1 diff --git a/src/admin/clubs.php b/src/admin/clubs.php new file mode 100644 index 0000000..aea8f99 --- /dev/null +++ b/src/admin/clubs.php @@ -0,0 +1,5 @@ + + + + + Vereinsmanagement + Vereinsportal des saarländischen Tanzsportverbands + + + 30.03.2019 + + + Christian Wolf + + homepage@slt.wolf-stuttgart.net + + + + + 0.0.1 + + + + + + + clubs.php + controller.php + controller + helpers + models + views + + + + + + + Vereinsmanagement + + + + + clubs.php + controller.php + sql + + + + + + sql/mysql/install.sql + + + + + sql/mysql/uninstall.sql + + + + + sql/updates/mysql + + + + + + + + http://slt.wolf-stuttgart.net/update/clubs/slt-update.xml + + + diff --git a/src/site/clubs.php b/src/site/clubs.php new file mode 100644 index 0000000..638e005 --- /dev/null +++ b/src/site/clubs.php @@ -0,0 +1,15 @@ +input; + +$task = $input->getCmd("task", "display"); + +$controller->execute($task); +$controller->redirect(); diff --git a/src/site/controller.php b/src/site/controller.php new file mode 100644 index 0000000..6f76b47 --- /dev/null +++ b/src/site/controller.php @@ -0,0 +1,20 @@ +logoffCookie(); + + $input = Factory::getApplication()->input; + $user = $input->get('user'); + $pwd = $input->get('password'); + $success = $helper->checkUser($user, $pwd); + + if($success) + { + // Login succeeded + $keep = (bool) $input->get('keep', false); + $helper->loginCookie($user, $keep); + + $this->setRedirect("?option=com_clubs"); + } + else + { + $this->setRedirect("?option=com_clubs&view=login&state=failed"); + } + } + + public function logout() + { + $helper = new ClubsHelperAuth(); + $helper->logoffCookie(); + $this->setRedirect("?option=com_clubs&view=login"); + } +} diff --git a/src/site/helpers/auth.php b/src/site/helpers/auth.php new file mode 100644 index 0000000..6fd944c --- /dev/null +++ b/src/site/helpers/auth.php @@ -0,0 +1,109 @@ +getPassword($user); + + return password_verify($pwd, $savedHash); + } + + public function logoffCookie() + { + Factory::getApplication()->input->cookie->set("clubsLogin", ""); + } + + public function loginCookie($user, $keep) + { + $authCookie = array(); + $authCookie['user'] = $user; + $authCookie['start'] = time(); + + $value = array(); + $value['auth'] = $authCookie; + + $keys = $this->getKeys(); + $pkey = openssl_pkey_get_private($keys['priv']); + $signature = ''; + openssl_sign(json_encode($authCookie), $signature, $pkey) or die("Problem signing request."); + $value['sign'] = convert_uuencode($signature); + + $jsonValue = json_encode($value); + $uue = convert_uuencode($jsonValue); + + $c = Factory::getApplication()->input->cookie; + if(! $keep) + { + $time = 0; + $c->set('clubsLoginKeepLoggedIn', '', 0); + } + else + { + $time = time() + 3600*24*15; + $c->set('clubsLoginKeepLoggedIn', 'true', time() + 3600*24*356*10); + } + $c->set('clubsLogin', $uue, $time); + } + + public function checkCookie() + { + $cookie = Factory::getApplication()->input->cookie; + $uue = $cookie->get('clubsLogin', '', 'raw'); + + if($uue === '') + return false; + + $jsonValue = convert_uudecode($uue); + + $value = json_decode($jsonValue, true); + $keys = $this->getKeys(); + $pubkey = openssl_pkey_get_public($keys['public']); + $ret = openssl_verify(json_encode($value['auth']), convert_uudecode($value['sign']), $pubkey); + + if($ret == -1) + die("Error checking signature."); + + if($ret == 1) + { + // correct signature + $this->loginCookie($value['auth']['user'], Factory::getApplication()->input->cookie->get('clubsLoginKeepLoggedIn', false)); + return true; + } + else + { + // wrong signature + $this->logoffCookie(); + return false; + } + } + + private function getKeys() + { + $keyModel = BaseDatabaseModel::getInstance('signkey', 'ClubsModel'); + return $keyModel->getKeys(); + } + + public function setKeepLoggedIn($keep) + { + $c = Factory::getApplication()->input->cookie; + + if($keep) + { + $c->set('clubsLoginKeepLoggedIn', 'true', time() + 3600*24*365*10); + } + else + { + $c->set('clubsLoginKeepLoggedIn', '', 0); + } + } + +} diff --git a/src/site/models/signkey.php b/src/site/models/signkey.php new file mode 100644 index 0000000..c95a641 --- /dev/null +++ b/src/site/models/signkey.php @@ -0,0 +1,60 @@ +getQuery(true); + $query->select('privkey,publickey') + ->from("#__club_keys"); + $db->setQuery($query); + $result = $db->loadAssoc(); + $query->clear(); + + $ret = array(); + if($result == null) + { + // No key was yet generated + $ret = $this->genKeyPair(); + $this->saveKeyPair($db, $ret); + } + else + { + $ret['priv'] = $result['privkey']; + $ret['public'] = $result['publickey']; + } + return $ret; + } + + private function genKeyPair() + { + $ret = array(); + + $pkey = openssl_pkey_new(); + openssl_pkey_export($pkey, $ret['priv']) or die ("Error generating key."); + $details = openssl_pkey_get_details($pkey); + $ret['public'] = $details['key']; + + return $ret; + } + + private function saveKeyPair($db, $ret) + { + $query = $db->getQuery(true); + $query->insert('#__club_keys'); + $query->into('privkey, publickey'); + $query->values($db->q($ret['priv']) . ', ' . $db->q($ret['public'])); + $db->setQuery($query); + $db->execute(); + $query->clear(); + } + +} diff --git a/src/site/models/user.php b/src/site/models/user.php new file mode 100644 index 0000000..57b2d97 --- /dev/null +++ b/src/site/models/user.php @@ -0,0 +1,24 @@ +getQuery(true); + $query->select('password') + ->from("#__club_users") + ->where("user = " . $dbo->quote($username)); + $dbo->setQuery($query); + $result = $dbo->loadResult(); + + return $result; + } +} diff --git a/src/site/views/clubs/tmpl/default.php b/src/site/views/clubs/tmpl/default.php new file mode 100644 index 0000000..6131173 --- /dev/null +++ b/src/site/views/clubs/tmpl/default.php @@ -0,0 +1,7 @@ + +asd diff --git a/src/site/views/clubs/view.html.php b/src/site/views/clubs/view.html.php new file mode 100644 index 0000000..ef2c307 --- /dev/null +++ b/src/site/views/clubs/view.html.php @@ -0,0 +1,10 @@ +state === "failed") +{ +?> +

Benutzername oder Passwort sind falsch.

+ +
+

+Username:
+ +

+

+Passwort:
+ +

+

input->cookie->get('clubsLoginKeepLoggedIn','') === 'true') echo "checked";?>> Keep me logged in

+

+
diff --git a/src/site/views/login/tmpl/logout.php b/src/site/views/login/tmpl/logout.php new file mode 100644 index 0000000..72c176e --- /dev/null +++ b/src/site/views/login/tmpl/logout.php @@ -0,0 +1,7 @@ + +Logout diff --git a/src/site/views/login/view.html.php b/src/site/views/login/view.html.php new file mode 100644 index 0000000..0d03c86 --- /dev/null +++ b/src/site/views/login/view.html.php @@ -0,0 +1,30 @@ +checkCookie()) + { + // we are logged in + $this->setLayout('logout'); + parent::display(null); + } + else + { + $this->state = Factory::getApplication()->input->get("state", ""); + parent::display($tpl); + } + } + +}