From 1e438654005bd408447dc19c8a96099d228bb1aa Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Thu, 16 Mar 2023 01:09:44 +0200 Subject: working on user management --- core/classes/authentication/Core/PasswordTrait.php | 10 ++- core/classes/authentication/Core/UserManager.php | 33 +++++++- core/classes/authentication/Token/UserToken.php | 12 +++ core/classes/authentication/User.php | 12 ++- html/app/models/market/Payment_template.txt | 98 ++++++++++++++++++++++ 5 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 html/app/models/market/Payment_template.txt diff --git a/core/classes/authentication/Core/PasswordTrait.php b/core/classes/authentication/Core/PasswordTrait.php index 18d67b5..2d3cbd2 100644 --- a/core/classes/authentication/Core/PasswordTrait.php +++ b/core/classes/authentication/Core/PasswordTrait.php @@ -10,21 +10,27 @@ trait PasswordTrait { - private $cost = 10; + + private $cost = 10; // Cost must be in the range of 4-31 + // a cost value in the range of 8-11 + // is a good balance between performance and security + public function cryptPassword(string $plainPassword): string { return password_hash($plainPassword, PASSWORD_BCRYPT, ['cost' => $this->cost]); } + public function isPasswordValid(UserInterface $user, string $plainPassword): bool { return password_verify($plainPassword, $user->getPassword()); } + public function setCost(int $cost): void { - if ($cost < 4 || $cost > 12) { + if ($cost < 4 || $cost > 31) { throw new \InvalidArgumentException('Cost must be in the range of 4-31.'); } $this->cost = $cost; diff --git a/core/classes/authentication/Core/UserManager.php b/core/classes/authentication/Core/UserManager.php index 3b380b8..22a87f5 100644 --- a/core/classes/authentication/Core/UserManager.php +++ b/core/classes/authentication/Core/UserManager.php @@ -15,6 +15,7 @@ class UserManager implements UserManagerInterface use PasswordTrait; + public function __construct() { if (session_status() === PHP_SESSION_NONE) { @@ -22,6 +23,11 @@ class UserManager implements UserManagerInterface } } + + /** getUserToken() + * == get user from session + * + */ public function getUserToken(): ?UserTokenInterface { $userToken = null; @@ -32,15 +38,31 @@ class UserManager implements UserManagerInterface return $userToken; } + + /** hasUserToken() + * == is user loged in + * + */ public function hasUserToken(): bool { $key = UserTokenInterface::DEFAULT_PREFIX_KEY; return (array_key_exists($key, $_SESSION) && unserialize($_SESSION[$key]) !== false); } + + /** isGranted + * + * checks if user is granded some role(s) + * from the array of roles that are passed + * + * ex. $token->isGranted(['editor', 'designer']) ... + * returns true if the user is editor or designer (or both) + * + */ public function isGranted(array $roles): bool { - if (!is_null($userToken = $this->getUserToken())) { + // if (!is_null($userToken = $this->getUserToken())) { + if (is_null($userToken = $this->getUserToken())) { return false; } @@ -51,6 +73,10 @@ class UserManager implements UserManagerInterface return false; } + + /** createUserToken() + * == serializes user and stores it into session + */ public function createUserToken(UserInterface $user): UserTokenInterface { $userToken = new UserToken($user); @@ -59,6 +85,11 @@ class UserManager implements UserManagerInterface return $userToken; } + + /** logout + * == clear session + * + */ public function logout(): void { if ($this->hasUserToken()) { diff --git a/core/classes/authentication/Token/UserToken.php b/core/classes/authentication/Token/UserToken.php index 6ce2eb6..520d4ad 100644 --- a/core/classes/authentication/Token/UserToken.php +++ b/core/classes/authentication/Token/UserToken.php @@ -15,16 +15,28 @@ class UserToken implements UserTokenInterface */ private $user; + public function __construct(UserInterface $user) { $this->user = $user; } + + /** getUser + * + */ public function getUser(): UserInterface { return $this->user; } + + /** serialize() + * + * serializes the user structure (with user's property values) + * ... then it will be saved into session[DEFAULT_PREFIX_KEY] + * + */ public function serialize(): string { return serialize($this); diff --git a/core/classes/authentication/User.php b/core/classes/authentication/User.php index 8f5aecb..4aef375 100644 --- a/core/classes/authentication/User.php +++ b/core/classes/authentication/User.php @@ -65,7 +65,8 @@ class User implements UserInterface * ------------------------------------------------------------------------- */ - /** setUserName + /** setUserName() + * * @param string $userName * @return User */ @@ -75,7 +76,8 @@ class User implements UserInterface return $this; } - /** setPassword + /** setPassword() + * * @param string $password * @return User */ @@ -85,7 +87,8 @@ class User implements UserInterface return $this; } - /** setRoles + /** setRoles() + * * @param array $roles * @return User */ @@ -95,7 +98,8 @@ class User implements UserInterface return $this; } - /** + /** setEnabled + * * @param bool $enabled * @return User */ diff --git a/html/app/models/market/Payment_template.txt b/html/app/models/market/Payment_template.txt new file mode 100644 index 0000000..4a66a1a --- /dev/null +++ b/html/app/models/market/Payment_template.txt @@ -0,0 +1,98 @@ +class WC_Piraeusbank_Gateway extends WC_Payment_Gateway { + + public function __construct() + + function pb_get_pages($title = false, $indent = true) + + function pb_get_installments($title = false, $indent = true) + + function generate_piraeusbank_form($order_id) + + function process_payment($order_id) + + function receipt_page($order) + + function check_piraeusbank_response() + + function piraeusbank_message() + + function woocommerce_add_piraeusbank_gateway($methods) + + function piraeusbank_plugin_action_links($links, $file) + +} + + + +class WC_NBG_Gateway extends WC_Payment_Gateway { + + public function __construct() + + public function admin_options() + + function init_form_fields() + + function nbg_get_pages($title = false, $indent = true) + + function nbg_get_installments($title = false, $indent = true) + + function generate_nbg_form($order_id) + + function process_payment($order_id) + + function receipt_page($order) { + + function check_nbg_response() + + function nbg_message() + + function woocommerce_add_nbg_gateway($methods) + + function nbg_plugin_action_links($links, $file) + +} + + + +global $wc; + + $this->id = 'nbg_gateway'; + $this->icon = apply_filters('nbg_icon', plugins_url('assets/nbg.png', __FILE__)); + $this->has_fields = false; + $this->notify_url = WC()->api_request_url('WC_NBG_Gateway'); + $this->method_description = __('National Bank Greece Payment Gateway allows you to accept payment through various channels such as Maestro, Mastercard and Visa cards On your Woocommerce Powered Site.', 'woocommerce-nbg-payment-gateway'); + $this->redirect_page_id = $this->get_option('redirect_page_id'); + $this->method_title = 'National Bank of Greece Gateway'; + + // Load the form fields. + $this->init_form_fields(); + + //dhmioyrgia vashs + + global $wpdb; + + if ($wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "nbg_transactions'") === $wpdb->prefix . 'nbg_transactions') { + // The database table exist + } else { + // Table does not exist + $query = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'nbg_transactions (id int(11) unsigned NOT NULL AUTO_INCREMENT,merchantreference varchar(30) not null, reference varchar(100) not null, orderid varchar(100) not null , timestamp datetime default null, PRIMARY KEY (id))'; + $wpdb->query($query); + } + + + // Load the settings. + $this->init_settings(); + + + // Define user set variables + $this->title = $this->get_option('title'); + $this->description = $this->get_option('description'); + $this->nbg_Username = $this->get_option('nbg_Username'); + $this->nbg_Password = $this->get_option('nbg_Password'); + + $this->nbg_description= $this->get_option('nbg_description'); + $this->mode = $this->get_option('mode'); + $this->nbg_installments= $this->get_option('nbg_installments'); + //Actions + add_action('woocommerce_receipt_nbg_gateway', array($this, 'receipt_page')); + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this -- cgit v1.2.3