summaryrefslogtreecommitdiffstats
path: root/frontend/api
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/api')
-rw-r--r--frontend/api/api_test.php3
-rw-r--r--frontend/api/class.ApiLogin.php773
-rw-r--r--frontend/api/class.ApiLoginController.php15
-rw-r--r--frontend/api/fb_login.php6
-rw-r--r--frontend/api/login_AAI.php4
5 files changed, 523 insertions, 278 deletions
diff --git a/frontend/api/api_test.php b/frontend/api/api_test.php
index 8be5303..e714ed5 100644
--- a/frontend/api/api_test.php
+++ b/frontend/api/api_test.php
@@ -7,6 +7,7 @@
// Nastavimo url api-ja
$api_url = 'http://localhost/FDV/frontend/api/api.php';
+$api_url = 'https://www.1ka.si/frontend/api/api.php';
// Nastavimo identifier in key userja
$identifier = '';
@@ -19,7 +20,7 @@ $action = 'logout';
// Izvedemo klic (GET ali POST)
-//$result = executeGET();
+$result = executeGET();
//$result = executePOST();
diff --git a/frontend/api/class.ApiLogin.php b/frontend/api/class.ApiLogin.php
index aff7d0f..d63cace 100644
--- a/frontend/api/class.ApiLogin.php
+++ b/frontend/api/class.ApiLogin.php
@@ -17,8 +17,12 @@ class ApiLogin
var $pass;
+ var $method;
+
var $prijava = '';
+ var $data;
+
var $EncPass;
var $page_urls = []; // Url-ji za podstrani - to se bo verjetno nastavljalo v settings.php
@@ -32,11 +36,10 @@ class ApiLogin
global $site_path;
global $site_domain;
global $cookie_domain;
- global $virtual_domain;
// Overridi za virtualne domene na TUS strezniku
- if(isset($virtual_domain) && $virtual_domain == true){
+ if(isVirtual()){
if (getenv('apache_site_path') != '') $site_url = getenv('apache_site_url');
if (getenv('apache_site_path') != '') $site_path = getenv('apache_site_path');
if (getenv('apache_site_domain') != '') $site_domain = getenv('apache_site_domain');
@@ -156,38 +159,44 @@ class ApiLogin
global $global_user_id;
global $mysql_database_name;
global $pass_salt;
- global $is_meta;
global $cookie_domain;
- $is_meta = 0;
$global_user_id = 0;
$admin_type = 3;
- $cookie_pass = $_COOKIE['secret'];
+
+ $cookie_pass = isset($_COOKIE['secret']) ? $_COOKIE['secret'] : '';
- // UID je v resnici base64 od emaila, ker sicer odpove meta!!!
// najprej testiram meto, potem sele userje.
if (isset ($_COOKIE['uid']) && !empty($_COOKIE['g2fa'])) {
$user_email = base64_decode($_COOKIE['uid']);
- $db_meta_exists = mysqli_select_db($GLOBALS['connect_db'], "meta");
- if ($db_meta_exists) {
- $result = sisplet_query("SELECT geslo, aid, 0 as type FROM administratorji WHERE email='$user_email'");
- }
-
- // NI META
+ $result = sisplet_query("SELECT pass, id, type FROM users WHERE email='$user_email'");
if (!$result || mysqli_num_rows($result) == 0) {
- mysqli_select_db($GLOBALS['connect_db'], $mysql_database_name);
- $meta = 0;
+ // najprej poradiraij cookije!
+ setcookie('uid', "", time() - 3600, $cookie_domain);
+ setcookie('secret', "", time() - 3600, $cookie_domain);
+
+ if (substr_count($cookie_domain, ".") > 1) {
+ $nd = substr($cookie_domain,strpos($cookie_domain, ".") + 1);
+
+ setcookie('uid', "", time() - 3600, $nd);
+ setcookie('secret', "", time() - 3600, $nd);
+ }
- $result = sisplet_query("SELECT pass, id, type FROM users WHERE email='$user_email'");
- if (!$result || mysqli_num_rows($result) == 0) {
+ return -1;
+ }
+ else {
+ $r = mysqli_fetch_row($result);
+
+ if ($cookie_pass != $r[0]) {
// najprej poradiraij cookije!
setcookie('uid', "", time() - 3600, $cookie_domain);
setcookie('secret', "", time() - 3600, $cookie_domain);
if (substr_count($cookie_domain, ".") > 1) {
- $nd = substr($cookie_domain,strpos($cookie_domain, ".") + 1);
+ $nd = substr($cookie_domain,
+ strpos($cookie_domain, ".") + 1);
setcookie('uid', "", time() - 3600, $nd);
setcookie('secret', "", time() - 3600, $nd);
@@ -195,86 +204,14 @@ class ApiLogin
return -1;
} else {
- $r = mysqli_fetch_row($result);
-
- if ($cookie_pass != $r[0]) {
- // najprej poradiraij cookije!
- setcookie('uid', "", time() - 3600, $cookie_domain);
- setcookie('secret', "", time() - 3600, $cookie_domain);
-
- if (substr_count($cookie_domain, ".") > 1) {
- $nd = substr($cookie_domain,
- strpos($cookie_domain, ".") + 1);
-
- setcookie('uid', "", time() - 3600, $nd);
- setcookie('secret', "", time() - 3600, $nd);
- }
-
- return -1;
- } else {
- $admin_type = $r[2];
- $global_user_id = $r[1];
-
- return $r[2];
- }
- }
-
- } // JE META
- else {
- $r = mysqli_fetch_row($result);
-
- if ($cookie_pass == base64_encode((hash('SHA256', base64_decode($r[0]).$pass_salt)))) {
-
- $is_meta = 1;
- $admin_type = "0";
-
- mysqli_select_db($GLOBALS['connect_db'],
- $mysql_database_name);
-
- $result = sisplet_query("SELECT pass, id, type FROM users WHERE email='$user_email'");
- if (mysqli_num_rows($result) > 0) {
- $r = mysqli_fetch_row($result);
- $global_user_id = $r[1];
- }
-
- return 0;
- } else {
- mysqli_select_db($GLOBALS['connect_db'],
- $mysql_database_name);
- // Obstaja tudi primer ko je IN meta IN navaden- in se je pac prijavil kot navaden user
-
-
- $result = sisplet_query("SELECT pass, id, type FROM users WHERE email='$user_email'");
- if (!$result || mysqli_num_rows($result) == 0) {
- return -1;
- } else {
- $r = mysqli_fetch_row($result);
-
- if ($cookie_pass != $r[0]) {
- // najprej poradiraij cookije!
- setcookie('uid', "", time() - 3600, $cookie_domain);
- setcookie('secret', "", time() - 3600,
- $cookie_domain);
-
- if (substr_count($cookie_domain, ".") > 1) {
- $nd = substr($cookie_domain,
- strpos($cookie_domain, ".") + 1);
+ $admin_type = $r[2];
+ $global_user_id = $r[1];
- setcookie('uid', "", time() - 3600, $nd);
- setcookie('secret', "", time() - 3600, $nd);
- }
-
- return -1;
- } else {
- $admin_type = $r[2];
- $global_user_id = $r[1];
-
- return $r[2];
- }
- }
+ return $r[2];
}
- }
- } // Ni prijavljen
+ }
+ }
+ // Ni prijavljen
else {
$admin_type = -1;
@@ -285,14 +222,13 @@ class ApiLogin
// Preveri ce je user ze logiran v 1ko in nastavi globalne spremenljivke in cookie (kopirano iz function.php)
- public function executeAction($params, $data)
+ public function executeAction($params, $data, $method='')
{
global $site_url;
global $global_user_id;
global $lang;
global $cookie_domain;
-
// Nastavimo prejete podatke
if (isset($data['ime'])) {
$this->ime = $data['ime'];
@@ -306,10 +242,17 @@ class ApiLogin
if (isset($data['pass'])) {
$this->pass = $data['pass'];
}
+ if (isset($data['method'])){
+ $this->method = $data['method'];
+ }
+ if (isset($data)){
+ $this->data = $data;
+ }
if (!isset($params['action'])) {
$response = 'Napaka! Manjkajo parametri!';
- } else {
+ }
+ else {
switch ($params['action']) {
// Login userja
@@ -349,13 +292,11 @@ class ApiLogin
$response = $this->userLoginAAI();
break;
-
// Logout userja
case 'logout':
$response = $this->userLogout();
break;
-
// Registracija userja - prvi vnos podatkov s preverjanjem
case 'register':
$response = $this->userRegister();
@@ -376,18 +317,11 @@ class ApiLogin
$response = $this->userActivateAlternativEmail();
break;
-
- // Odregistracija userja - preverjanje ce se res zeli odjaviti
- // case 'unregister':
- // $response = $this->userUnregister();
- // break;
-
// Odregistracija userja - potrditev in dejanska odjava
case 'unregister_confirm':
$response = $this->userUnregisterConfirm();
break;
-
// Reset passworda userja
case 'reset_password':
$response = $this->userResetPassword();
@@ -397,10 +331,13 @@ class ApiLogin
case 'reset_password_activate':
$response = $this->userResetPasswordActivate();
break;
+
+ default:
+ $response = 'Napaka! Manjkajo parametri!';
+ break;
}
}
-
echo $response;
}
@@ -411,23 +348,45 @@ class ApiLogin
{
global $mysql_database_name;
global $site_url;
- global $lang;
global $pass_salt;
global $cookie_domain;
global $originating_domain;
global $keep_domain;
- global $app_settings;
+
+ $piskotek = [];
+ $error = [];
+
+ $language = 1;
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
+ }
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
+ }
+
+ if(is_numeric($language)){
+ include('../../lang/'.$language.'.php');
+ }
// Ce imamo vklopljeno blokiranje dostopa do admina glede na ip
- if(isset($app_settings['admin_allow_only_ip']) && $app_settings['admin_allow_only_ip'] != '' && !empty($app_settings['admin_allow_only_ip'])){
+ $admin_allow_only_ip = AppSettings::getInstance()->getSetting('app_limits-admin_allow_only_ip');
+ if($admin_allow_only_ip !== false && !empty($admin_allow_only_ip)){
$ip = $_SERVER['REMOTE_ADDR'];
// Preverimo ip - ce se ne ujema ne pustimo logina
- if(!in_array($ip, $app_settings['admin_allow_only_ip'])){
- header('location: '.$this->page_urls['page_login'.$this->prijava]);
- die();
+ if(!in_array($ip, $admin_allow_only_ip)){
+ if($this->method == 'AJAX'){
+
+ return $this->ajaxResponse('error', 'Napaka pri prijavi.');
+
+ }else {
+
+ header('location: '.$this->page_urls['page_login'.$this->prijava]);
+ die();
+
+ }
}
}
@@ -441,12 +400,17 @@ class ApiLogin
$LifeTime = $row[0];
// Cookie "remember-me" nastavimo pri FB, Google in AAi prijavi in tukaj preverjamo, če je nastavljena ta opcija
- if ((isset($_POST['remember']) && $_POST['remember'] == "1") || (isset($_COOKIE['remember-me']) && $_COOKIE['remember-me'] == 1)) {
+ if (
+ (isset($_POST['remember']) && $_POST['remember'] == "1") ||
+ (isset($_COOKIE['remember-me']) && $_COOKIE['remember-me'] == 1) ||
+ (isset($this->data['remember']) && $this->data['remember'] == 1)
+ ) {
$LifeTime = 3600 * 24 * 365;
} else {
$LifeTime = $LifeTime;
}
+
// Preverimo ce obstaja uporabnik s tem emailom
$user_id = User::findByEmail($this->email);
if (!empty($user_id)) {
@@ -455,8 +419,17 @@ class ApiLogin
// BAN
if ($r['status'] == 0) {
- header('Location: '.$this->page_urls['page_user_ban'.$this->prijava].'&error=user_ban&email='.$this->email);
- die();
+
+ if($this->method == 'AJAX'){
+
+ return $this->ajaxResponse('error', $lang['cms_error_user_ban']);
+
+ }else {
+
+ header('Location: '.$this->page_urls['page_user_ban'.$this->prijava].'&error=user_ban&email='.$this->email);
+ die();
+
+ }
}
$user_lang = 1;
@@ -464,6 +437,7 @@ class ApiLogin
$user_lang = 2;
}
+
// Preverimo ce je password ok
if (base64_encode((hash('SHA256', $this->pass.$pass_salt))) == $r['pass'] || $this->EncPass == $r['pass']) {
@@ -482,41 +456,153 @@ class ApiLogin
// Ustvarimo login cookie
- setcookie("uid", base64_encode($r['email']), time() + $LifeTime, '/', $cookie_domain);
+ if($this->method == 'AJAX') {
+ $piskotek['uid'] = [
+ 'ime' => 'uid',
+ 'vrednost' => base64_encode($r['email']),
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ //'secure' => true
+ ]
+ ];
+ }
+ else {
+ setcookie("uid", base64_encode($r['email']), time() + $LifeTime, '/', $cookie_domain);
+ }
//Preverimo če gre za Google 2FA
$user_2fa_enabled = User::option($r['id'], 'google-2fa-validation');
if(!empty($user_2fa_enabled) && $user_2fa_enabled != 'NOT'){
- setcookie("g2fa", base64_encode($user_2fa_enabled), time() + $LifeTime, '/', $cookie_domain);
- header('location: '.$this->page_urls['page_login_2fa']);
- die();
+
+ // TODO - 2fa v drupalu - pootrebno narediti, zaenkrat ugasnjeno
+ if($this->method == 'AJAX'){
+
+ $piskotek['g2fa'] = [
+ 'ime' => 'g2fa',
+ 'vrednost' => base64_encode($user_2fa_enabled),
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ //'secure' => true
+ ]
+ ];
+
+ return $this->ajaxResponse('success', [
+ 'google_2fa' => true,
+ 'piskotek' => $this->cookieEncode($piskotek)
+ ]);
+ }
+ else{
+ setcookie("g2fa", base64_encode($user_2fa_enabled), time() + $LifeTime, '/', $cookie_domain);
+
+ header('location: '.$this->page_urls['page_login_2fa']);
+ die();
+ }
}
// Ustvarimo piškotek še z imenom in geslom
- setcookie("unam", base64_encode($r['name'].' '.$r['surname']),time() + $LifeTime, '/', $cookie_domain);
- setcookie("secret", $r['pass'], time() + $LifeTime, '/', $cookie_domain);
+
+ if($this->method == 'AJAX'){
+
+ $piskotek['unam'] = [
+ 'ime' => 'unam',
+ 'vrednost' => base64_encode($r['name'].' '.$r['surname']),
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ //'secure' => true
+ ]
+ ];
+
+
+ $piskotek['secret'] = [
+ 'ime' => 'secret',
+ 'vrednost' => $r['pass'],
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ //'secure' => true
+ ]
+ ];
+
+
+ } else {
+ setcookie("unam", base64_encode($r['name'].' '.$r['surname']),time() + $LifeTime, '/', $cookie_domain);
+ setcookie("secret", $r['pass'], time() + $LifeTime, '/', $cookie_domain);
+ }
- if ($r['status'] == "2" || $r['status'] == "6") {
- setcookie("P", time(), time() + $LifeTime, '/', $cookie_domain);
- header('location: '.$this->page_urls['page_login'.$this->prijava].'&email='.$this->email.'&error=password');
- die();
+ // Ce imamo v aplikaciji vklopljeno potrjevanje adminov
+ if (AppSettings::getInstance()->getSetting('confirm_registration') === true){
+
+ if ($r['status'] == "2" || $r['status'] == "6") {
+
+ if($this->method == 'AJAX'){
+
+ $piskotek['P'] = [
+ 'ime' => 'P',
+ 'vrednost' => time(),
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ 'secure' => true
+ ]
+ ];
+ $error['password'] = $lang['cms_error_password'];
+
+ return $this->ajaxResponse('error', [
+ 'piskotek' => $this->cookieEncode($piskotek),
+ 'error' => $error
+ ]);
+
+ }
+ else{
+ setcookie("P", time(), time() + $LifeTime, '/', $cookie_domain);
+ header('location: '.$this->page_urls['page_login'.$this->prijava].'&email='.$this->email.'&error=password');
+ die();
+ }
+ }
}
}
else {
// Password prompt
- header('location: '.$this->page_urls['page_login'.$this->prijava].'&email='.$this->email.'&error=password');
- die();
+ if($this->method == 'AJAX'){
+
+ return $this->ajaxResponse('error', $lang['cms_error_password']);
+
+ }else{
+ header('location: '.$this->page_urls['page_login'.$this->prijava].'&email='.$this->email.'&error=password');
+ die();
+ }
}
}
else {
// Preverimo, če je sploh vpisal email
if (validEmail($this->email)) {
- // Emaila ni v bazi
- header('location: '.$this->page_urls['page_login_noEmail'.$this->prijava].'&email='.$this->email);
+ if($this->method == 'AJAX'){
+
+ return $this->ajaxResponse('error', $lang['cms_error_email_or_password_doesnt_exist']);
+
+ }else{
+ // Emaila ni v bazi
+ header('location: '.$this->page_urls['page_login_noEmail'.$this->prijava].'&email='.$this->email);
+ }
} else {
- // Ni vpisana prava oblika maila
- header('location: '.$this->page_urls['page_login_noEmail'.$this->prijava].'&email='.$this->email);
+ if($this->method == 'AJAX'){
+
+ return $this->ajaxResponse('error', $lang['cms_error_email']);
+
+
+ }else{
+ // Ni vpisana prava oblika maila
+ header('location: '.$this->page_urls['page_login_noEmail'.$this->prijava].'&email='.$this->email);
+ }
}
die();
}
@@ -531,41 +617,84 @@ class ApiLogin
die();
}
+
// Vse je ok - prijavljenega preusmerimo na moje ankete
+ if($this->method == 'AJAX'){
+ return $this->ajaxResponse('success', [
+ 'url' => $site_url.'admin/survey/index.php?lang='.$user_lang,
+ 'piskotek' => $this->cookieEncode($piskotek)
+ ]);
+ }
+
header('location: '.$site_url.'admin/survey/index.php?lang='.$user_lang);
+
die();
}
// Prijava z Google 2 FA
private function userLogin2fa()
{
- global $site_url, $cookie_domain;
+ global $site_url, $cookie_domain, $lang;
$email = null;
if(!empty($_COOKIE['uid'])){
$email = base64_decode($_COOKIE['uid']);
+ }elseif(empty($email) && !empty($this->data['uid'])){
+ $email = base64_decode($this->data['uid']);
}
$user_id = User::findByEmail($email);
$user= sisplet_query("SELECT type, pass, status, name, surname, email FROM users WHERE id='".$user_id."'", "obj");
$secret = User::option($user_id, 'google-2fa-secret');
- if(!empty($secret) && $_POST['google_2fa_number']){
+
+ $google2fa_number = $_POST['google_2fa_number'];
+ if(empty($google2fa_number)){
+ $google2fa_number = $this->data['google_2fa_number'];
+ }
+
+ if(!empty($secret) && $google2fa_number){
$google2fa = new \Sonata\GoogleAuthenticator\GoogleAuthenticator();
+
$user_lang = 1;
- if (!empty($_POST['jezik']) && $_POST['jezik'] == 'en') {
+ if (!empty($_POST['jezik']) && $_POST['jezik'] == 'en' || !empty($this->data['jezik']) && $this->data['jezik'] == 'en') {
$user_lang = 2;
}
// 2FA je bila uspešna
- if ($google2fa->checkCode($secret, $_POST['google_2fa_number'])) {
+ if ($google2fa->checkCode($secret, $google2fa_number)) {
$result = sisplet_query("SELECT value FROM misc WHERE what='CookieLife'", "obj");
$LifeTime = $result->value;
-
- // Ustvarimo piškotek še z imenom in geslom
- setcookie("unam", base64_encode($user->name.' '.$user->surname),time() + $LifeTime, '/', $cookie_domain);
- setcookie("secret", $user->pass, time() + $LifeTime, '/', $cookie_domain);
+ $piskotek = [];
+
+ if($this->method == 'AJAX') {
+ $piskotek['unam'] = [
+ 'ime' => 'unam',
+ 'vrednost' => base64_encode($user->name.' '.$user->surname),
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ //'secure' => true
+ ]
+ ];
+ $piskotek['secret'] = [
+ 'ime' => 'secret',
+ 'vrednost' => $user->pass,
+ 'opcije' => [
+ 'expires' => time() + $LifeTime,
+ 'path' => '/',
+ 'domain' => $cookie_domain,
+ //'secure' => true
+ ]
+ ];
+ }
+ else {
+ // Ustvarimo piškotek še z imenom in geslom
+ setcookie("unam", base64_encode($user->name.' '.$user->surname),time() + $LifeTime, '/', $cookie_domain);
+ setcookie("secret", $user->pass, time() + $LifeTime, '/', $cookie_domain);
+ }
// Zabelezimo datum prijave
@@ -580,13 +709,24 @@ class ApiLogin
$hostname = $_SERVER["REMOTE_ADDR"];
}
sisplet_query("INSERT INTO user_login_tracker (uid, IP, kdaj) VALUES ('".$user_id."', '".$hostname."', NOW())");
-
+
+
+ if($this->method == 'AJAX'){
+ return $this->ajaxResponse('success', [
+ 'url' => $site_url.'admin/survey/index.php?lang='.$user_lang,
+ 'piskotek' => $this->cookieEncode($piskotek)
+ ]);
+ }
// Vse je ok - prijavljenega preusmerimo na moje ankete
header('location: '.$site_url.'admin/survey/index.php?lang='.$user_lang);
die();
}
+ if($this->method == 'AJAX'){
+ return $this->ajaxResponse('error', $lang['google_2fa_user_error_code']);
+ }
+
// Vse neuspešne poskuse ali napačen email
header('location: '. $this->page_urls['page_login_2fa'].'&error=2fa');
die();
@@ -602,12 +742,21 @@ class ApiLogin
{
require_once('../../function/JWT.php');
- global $google_login_client_id;
- global $google_login_client_secret;
global $site_url;
- global $lang;
global $proxy;
+ $language = 1;
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
+ }
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
+ }
+
+ if(is_numeric($language)){
+ include('../../lang/'.$language.'.php');
+ }
+
$oauth2_code = $_GET['code'];
$discovery = json_decode(file_get_contents('https://accounts.google.com/.well-known/openid-configuration'));
@@ -617,8 +766,8 @@ class ApiLogin
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query([
- 'client_id' => $google_login_client_id,
- 'client_secret' => $google_login_client_secret,
+ 'client_id' => AppSettings::getInstance()->getSetting('google-login_client_id'),
+ 'client_secret' => AppSettings::getInstance()->getSetting('google-login_client_secret'),
'code' => $oauth2_code,
'grant_type' => 'authorization_code',
'redirect_uri' => $site_url.'frontend/api/google-oauth2.php',
@@ -634,8 +783,8 @@ class ApiLogin
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query([
- 'client_id' => $google_login_client_id,
- 'client_secret' => $google_login_client_secret,
+ 'client_id' => AppSettings::getInstance()->getSetting('google-login_client_id'),
+ 'client_secret' => AppSettings::getInstance()->getSetting('google-login_client_secret'),
'code' => $oauth2_code,
'grant_type' => 'authorization_code',
'redirect_uri' => $site_url.'frontend/api/google-oauth2.php',
@@ -713,11 +862,9 @@ class ApiLogin
// Prijavi userja v 1ko z FB racunom (kopirano iz ProfileClass.php) - PRETESTIRATI
private function userLoginFacebook()
{
- global $facebook_appid;
- global $facebook_appsecret;
global $cookie_path;
- if ($r = file_get_contents("https://graph.facebook.com/v2.9/oauth/access_token?client_id=".$facebook_appid."&redirect_uri=https://www.1ka.si/frontend/api/fb_login.php&client_secret=".$facebook_appsecret."&code=".$_GET['code'])) {
+ if ($r = file_get_contents("https://graph.facebook.com/v2.9/oauth/access_token?client_id=".AppSettings::getInstance()->getSetting('facebook-appid')."&redirect_uri=https://www.1ka.si/frontend/api/fb_login.php&client_secret=".AppSettings::getInstance()->getSetting('facebook-appsecret')."&code=".$_GET['code'])) {
$at = json_decode($r);
$user = json_decode(file_get_contents('https://graph.facebook.com/me?fields=email,first_name,last_name&access_token='.$at->{'access_token'}));
@@ -895,11 +1042,14 @@ class ApiLogin
sort($mails);
$mail = $mails[0];
- $ime = $data[1];
- $priimek = $data[2];
+ // Pridobimo aai (shibboleth) "uuid"
+ $aai_id = $data[1];
- $njegova = $data[3];
- $moja = $data[4];
+ $ime = $data[2];
+ $priimek = $data[3];
+
+ $njegova = $data[4];
+ $moja = $data[5];
// Preverimo ce ima veljaven token (najprej pobrisemo stare)
@@ -911,14 +1061,15 @@ class ApiLogin
$pass = base64_encode((hash('SHA256', "e5zhbWRTEGW&u375ejsznrtztjhdtz%WZ&".$pass_salt)));
// Preverimo ce obstaja user v bazi
- $user_id_1ka = User::findByEmail($mail);
+ $user_id_1ka = User::findByEmail_AAI($mail, $aai_id);
+
if (empty($user_id_1ka)) {
// Nastavimo pass
$pass = base64_encode(hash('SHA256', "e5zhbWRTEGW&u375ejsznrtztjhdtz%WZ&".$pass_salt));
// dodaj ga v bazo
- sisplet_query("INSERT INTO users (email, name, surname, type, pass, eduroam, when_reg) VALUES ('$mail', '$ime', '$priimek', '3', '".$pass."', '1', NOW())");
+ sisplet_query("INSERT INTO users (email, aai_id, name, surname, type, pass, eduroam, when_reg) VALUES ('$mail', '$aai_id', '$ime', '$priimek', '3', '".$pass."', '1', NOW())");
// Pridobimo id dodanega userja
$user_id = mysqli_insert_id($GLOBALS['connect_db']);
@@ -926,10 +1077,11 @@ class ApiLogin
else {
// potegni geslo in mu daj kuki
- $result = sisplet_query("SELECT pass, id FROM users WHERE id='".$user_id_1ka."'");
+ $result = sisplet_query("SELECT pass, email FROM users WHERE id='".$user_id_1ka."'");
$r = mysqli_fetch_row($result);
$pass = $r[0];
+ $mail = $r[1];
$user_id = $user_id_1ka;
}
@@ -976,7 +1128,49 @@ class ApiLogin
global $site_url;
global $cookie_domain;
global $global_user_id;
- global $aai_instalacija;
+
+ if($this->method == 'AJAX') {
+
+ $domene[] = $cookie_domain;
+ if(substr_count($cookie_domain, '.') > 1){
+ $domene[] = substr($cookie_domain, strpos($cookie_domain, '.') + 1);
+ }
+
+ foreach($domene as $key => $domena) {
+ $piskotek['uid_'.$key] = [
+ 'ime' => 'uid',
+ 'vrednost' => '',
+ 'opcije' => [
+ 'expires' => time() - 3600,
+ 'path' => '/',
+ 'domain' => $domena
+ ]
+ ];
+ $piskotek['unam_'.$key] = [
+ 'ime' => 'unam',
+ 'vrednost' => '',
+ 'opcije' => [
+ 'expires' => time() - 3600,
+ 'path' => '/',
+ 'domain' => $domena
+ ]
+ ];
+ $piskotek['secret_'.$key] = [
+ 'ime' => 'secret',
+ 'vrednost' => '',
+ 'opcije' => [
+ 'expires' => time() - 3600,
+ 'path' => '/',
+ 'domain' => $domena
+ ]
+ ];
+ }
+
+ return $this->ajaxResponse('success', [
+ 'url' => $site_url,
+ 'piskotek' => $this->cookieEncode($piskotek)
+ ]);
+ }
setcookie('uid', '', time() - 3600, '/', $cookie_domain);
setcookie('unam', '', time() - 3600, '/', $cookie_domain);
@@ -1017,7 +1211,7 @@ class ApiLogin
}
// Ce gre za arnes aai odjavo odjavimo posebej
- if ($aai_instalacija){
+ if (isAAI()){
setcookie("aai", '', time() - 3600, '/', $cookie_domain);
header('location: '.$site_url.'/logout_AAI.php?return='.$site_url);
die();
@@ -1030,31 +1224,37 @@ class ApiLogin
// Registrira userja v 1ko - vnos podatkov
private function userRegister()
{
- global $secret_captcha;
-
$error = [];
- $email = (isset($_POST['email'])) ? $_POST['email'] : '';
- $ime = (isset($_POST['ime'])) ? $_POST['ime'] : '';
- $geslo = (isset($_POST['geslo'])) ? $_POST['geslo'] : '';
- $geslo2 = (isset($_POST['geslo2'])) ? $_POST['geslo2'] : '';
- $agree = (isset($_POST['agree'])) ? $_POST['agree'] : '0';
- $gdprAgree = (isset($_POST['gdpr-agree'])) ? $_POST['gdpr-agree'] : '0';
- $ajaxKlic = (isset($_POST['ajax'])) ? $_POST['ajax'] : '0'; // Če izvajamo registracjo preko drupala, ker se pošlje post request preko ajaxa
+ $email = (isset($this->data['email'])) ? $this->data['email'] : '';
+ $ime = (isset($this->data['ime'])) ? $this->data['ime'] : '';
+ $geslo = (isset($this->data['geslo'])) ? $this->data['geslo'] : '';
+ $geslo2 = (isset($this->data['geslo2'])) ? $this->data['geslo2'] : '';
+ $agree = (isset($this->data['agree'])) ? $this->data['agree'] : '0';
+ $gdprAgree = (isset($this->data['gdpr-agree'])) ? $this->data['gdpr-agree'] : '0';
+ $ajaxKlic = (isset($this->data['ajax'])) ? $this->data['ajax'] : '0'; // Če izvajamo registracjo preko drupala, ker se pošlje post request preko ajaxa
- $varnostno_polje = (isset($_POST['varnostno-polje'])) ? $_POST['varnostno-polje'] : false;
+ $varnostno_polje = (isset($this->data['varnostno-polje'])) ? $this->data['varnostno-polje'] : false;
if (!empty($varnostno_polje)) {
- header('Location: '.$this->page_urls['page_robot_redirect']);
- die();
+
+ if($this->method == 'AJAX'){
+ return $this->ajaxResponse('error', [
+ 'url' => $this->page_urls['page_robot_redirect'],
+ 'message' => 'Robot'
+ ]);
+ } else {
+ header('Location: ' . $this->page_urls['page_robot_redirect']);
+ die();
+ }
}
// Preverimo ReCaptcha
- if (!empty($secret_captcha)) {
- $recaptchaResponse = $_POST['g-recaptcha-response'];
- $requestReCaptcha = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret_captcha."&response=".$recaptchaResponse);
+ if (AppSettings::getInstance()->getSetting('google-secret_captcha') !== false) {
+ $recaptchaResponse = $this->data['g-recaptcha-response'];
+ $requestReCaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . AppSettings::getInstance()->getSetting('google-secret_captcha') . '&response=' . $recaptchaResponse);
- if (!strstr($requestReCaptcha, "true")) {
+ if (!strstr($requestReCaptcha, 'true')) {
$error['invalid_recaptcha'] = '1';
}
}
@@ -1097,13 +1297,12 @@ class ApiLogin
if($ime != ''){
do {
$add++;
- $sqln = sisplet_query("SELECT * from users WHERE name='".str_replace("'",
- "", $ime).$add."'");
+ $sqln = sisplet_query("SELECT * from users WHERE name='".str_replace("'","", $ime).$add."'");
if (mysqli_num_rows($sqln) == 0) {
$najdu = 1;
}
- } while ($najdu = 0);
+ } while ($najdu == 0);
// Novo ime ki ga predlagamo
$ime = $ime.$add;
@@ -1122,8 +1321,7 @@ class ApiLogin
if (!empty($error)) {
if($ajaxKlic){
- echo json_encode($this->preveriNapake($error));
- die();
+ return $this->ajaxResponse('error', $this->preveriNapake($error));
}
// Ime in email posljemo nazaj v urlju
@@ -1140,11 +1338,8 @@ class ApiLogin
} // Vse je ok - preusmerimo na potrditveno stran
else {
- if($ajaxKlic){
- echo json_encode([
- 'success' => '1'
- ]);
- die();
+ if($ajaxKlic || $this->method == 'AJAX'){
+ return $this->ajaxResponse('success');
}
// Hidden form, ki ga z js potem postamo naprej (da prenesemo vnesene podatke na naslednjo stran)
@@ -1166,21 +1361,20 @@ class ApiLogin
}
}
-
private function preveriNapake($parametri)
{
// Nastavimo jezik
$language = 1;
- if(isset($_POST['language'])){
- $language = $_POST['language'];
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
}
- elseif(isset($_POST['jezik'])){
- $language = ($_POST['jezik'] == 'en' ? 2 : 1);
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
}
if(is_numeric($language)){
- include_once('../../lang/'.$language.'.php');
+ include('../../lang/'.$language.'.php');
}
$napaka = [];
@@ -1260,32 +1454,28 @@ class ApiLogin
global $site_url;
global $site_path;
global $site_domain;
- global $virtual_domain;
global $pass_salt;
- global $lang;
- global $confirm_registration;
- global $app_settings;
- $email = (isset($_POST['email']) ? $_POST['email'] : '');
- $ime = (isset($_POST['ime']) ? $_POST['ime'] : '');
- //$geslo = (isset($_POST['geslo']) ? base64_decode($_POST['geslo']) : '');
- $geslo = (isset($_POST['geslo']) ? $_POST['geslo'] : '');
- $gdprAgree = (isset($_POST['gdpr-agree']) ? $_POST['gdpr-agree'] : 0);
- $ajax = (isset($_POST['ajax']) ? $_POST['ajax'] : 0); // če je Drupal ajax request
+ $email = (isset($this->data['email']) ? $this->data['email'] : '');
+ $ime = (isset($this->data['ime']) ? $this->data['ime'] : '');
+ //$geslo = (isset($this->data['geslo']) ? base64_decode($this->data['geslo']) : '');
+ $geslo = (isset($this->data['geslo']) ? $this->data['geslo'] : '');
+ $gdprAgree = (isset($this->data['gdpr-agree']) ? $this->data['gdpr-agree'] : 0);
+ $ajax = (isset($this->data['ajax']) ? $this->data['ajax'] : 0); // če je Drupal ajax request
// Nastavimo jezik
$language = 1;
- if(isset($_POST['language'])){
- $language = $_POST['language'];
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
}
- elseif(isset($_POST['jezik'])){
- $language = ($_POST['jezik'] == 'en' ? 2 : 1);
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
}
if(is_numeric($language)){
- include_once('../../lang/'.$language.'.php');
+ include('../../lang/'.$language.'.php');
}
@@ -1301,7 +1491,7 @@ class ApiLogin
$priimek = '';
// Ce imamo vklopljeno potrjevanje urednika aplikacije ga potrdi admin
- if (isset($confirm_registration) && $confirm_registration == 1)
+ if (AppSettings::getInstance()->getSetting('confirm_registration') === true)
$status = 2;
else
$status = 1;
@@ -1312,6 +1502,13 @@ class ApiLogin
// naredi link za aktivacijo
$code = base64_encode((hash('SHA256', time().$pass_salt.$email.$ime)));
+
+ // Dodatno preverimo ce imamo vse podatke da ne morejo spamati - dodatno varnostno
+ if ($email == '' || !validEmail($email) || $ime == '' || $g == '') {
+ die();
+ }
+
+
// Vstavimo novega userja v users_to_be kjer caka na aktivacijo
$result = sisplet_query("INSERT INTO users_to_be
(type, email, name, surname, pass, status, gdpr_agree, when_reg, came_from, timecode, code, lang)
@@ -1332,16 +1529,16 @@ class ApiLogin
$Content .= $lang['confirm_user_mail_ignore'];
// Ce gre slucajno za virutalko
- $Subject = ($virtual_domain) ? $lang['confirm_user_mail_subject_virtual'] : $lang['confirm_user_mail_subject'];
+ $Subject = (isVirtual()) ? $lang['confirm_user_mail_subject_virtual'] : $lang['confirm_user_mail_subject'];
// Ce mora admin potrditi dobi email admin in ne uporabnik!
- if(isset($confirm_registration) && $confirm_registration == 1){
+ if(AppSettings::getInstance()->getSetting('confirm_registration') === true){
// Popravimo besedilo emaila
$Content = $lang['confirm_user_mail_admin'];
}
- $PageName = $app_settings['app_name'];
+ $PageName = AppSettings::getInstance()->getSetting('app_settings-app_name');
$ZaMail = '<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">'.'<html><head> <title>'.$Subject.'</title><meta content="text/html; charset=utf-8" http-equiv=Content-type></head><body>';
@@ -1358,7 +1555,7 @@ class ApiLogin
$Subject = str_replace("SFPAGENAME", $PageName, $Subject);
// Ce gre slucajno za virutalko
- if($virtual_domain)
+ if(isVirtual())
$Subject = str_replace("SFVIRTUALNAME", $site_domain, $Subject);
@@ -1368,7 +1565,8 @@ class ApiLogin
// Za testiranje brez posiljanja maila
if(isDebug()) {
- echo $ZaMail;
+ return $this->ajaxResponse('success',['mail' => $ZaMail, 'code' => $code]);
+ echo $ZaMail;
die();
}
@@ -1377,8 +1575,8 @@ class ApiLogin
$MA = new MailAdapter(null, 'account');
// Ce mora admin potrditi, posljemo njemu mail
- if(isset($confirm_registration) && $confirm_registration == 1){
- global $confirm_registration_admin;
+ if(AppSettings::getInstance()->getSetting('confirm_registration') === true){
+ $confirm_registration_admin = AppSettings::getInstance()->getSetting('confirm_registration_admin');
if(is_array($confirm_registration_admin)){
// Mail posljemo vsem nastavljenim adminom
@@ -1401,11 +1599,8 @@ class ApiLogin
}
- if($ajax){
- echo json_encode([
- 'success' => 1
- ]);
- die();
+ if($ajax || $this->method == 'AJAX'){
+ return $this->ajaxResponse('success');
}
@@ -1419,15 +1614,23 @@ class ApiLogin
// Po poslanem mailu po registraciji, user klikne na url in ga aktiviramo (kopiramo iz tabele users_to_be v tabelo users)
private function userRegisterActivate()
{
- global $lang;
global $site_url;
global $site_path;
global $site_domain;
- global $virtual_domain;
global $pass_salt;
global $cookie_domain;
- global $confirm_registration;
- global $app_settings;
+
+ $language = 1;
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
+ }
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
+ }
+
+ if(is_numeric($language)){
+ include('../../lang/'.$language.'.php');
+ }
if (!isset ($_GET['code'])) {
@@ -1457,14 +1660,14 @@ class ApiLogin
$pass = $r['pass'];
$ime = $r['name'];
- $PageName = $app_settings['app_name'];
+ $PageName = AppSettings::getInstance()->getSetting('app_settings-app_name');
include_once('../../lang/'.$r['lang'].'.php');
$Content = $lang['confirm_user_content'];
$Subject = $lang['confirm_user_subject'];
// Ce je ga moramo po registraciji odobriti dobi drugacno sporocilo
- if (isset($confirm_registration) && $confirm_registration == 1){
+ if (AppSettings::getInstance()->getSetting('confirm_registration') === true){
$UserContent = $lang['register_user_banned_content'];
}
else{
@@ -1481,7 +1684,7 @@ class ApiLogin
$out = '<a href="'.$this->page_urls['page_unregister'].'?email='.$email.'">';
// Ce gre slucajno za virtualko
- $Subject = ($virtual_domain) ? $lang['register_user_subject_virtual'] : $lang['register_user_subject'];
+ $Subject = (isVirtual()) ? $lang['register_user_subject_virtual'] : $lang['register_user_subject'];
$UserContent = str_replace("SFNAME", $ime, $UserContent);
$UserContent = str_replace("SFMAIL", $email, $UserContent);
@@ -1493,7 +1696,7 @@ class ApiLogin
$Subject = str_replace("SFPAGENAME", $PageName, $Subject);
// Ce gre slucajno za virtualko
- if($virtual_domain)
+ if(isVirtual())
$Subject = str_replace("SFVIRTUALNAME", $site_domain, $Subject);
if ($geslo2 == "") {
@@ -1532,7 +1735,7 @@ class ApiLogin
}
// Ce imamo vklopljeno potrjevanje urednika aplikacije je to izvedel admin in ne prijavljamo
- if (!isset($confirm_registration) || $confirm_registration != 1){
+ if (AppSettings::getInstance()->getSetting('confirm_registration') !== true){
// določi še, od kje se je prijavil
$hostname = "";
@@ -1566,7 +1769,17 @@ class ApiLogin
private function userActivateAlternativEmail()
{
- global $lang;
+ $language = 1;
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
+ }
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
+ }
+
+ if(is_numeric($language)){
+ include('../../lang/'.$language.'.php');
+ }
if (!isset ($_GET['enc'])) {
echo $lang['alternative_email_confirm_error'];
@@ -1615,7 +1828,6 @@ class ApiLogin
global $lang;
global $global_user_id;
global $cookie_domain;
- global $app_settings;
$email = $global_user_id;
@@ -1630,14 +1842,14 @@ class ApiLogin
}
}
- $result = sisplet_query("SELECT value FROM misc WHERE what='ByeEmail'");
- list ($ByeEmail) = mysqli_fetch_row($result);
- $result = sisplet_query("SELECT value FROM misc WHERE what='ByeEmailSubject'");
- list ($ByeEmailSubject) = mysqli_fetch_row($result);
+
+ $ByeEmail = '<p>Spoštovani,</p><p>Uspešno ste se odjavili iz spletnega mesta www.1ka.si.</p><p>Veseli nas, da ste preizkusili orodje 1ka.</p><p>SFPAGENAME ekipa</p>';
+ $ByeEmailSubject = 'Uspešna odjava';
+
$result = sisplet_query("SELECT name FROM users WHERE email='$email'");
- list ($ime) = mysqli_fetch_row($result);
+ [$ime] = mysqli_fetch_row($result);
- $PageName = $app_settings['app_name'];
+ $PageName = AppSettings::getInstance()->getSetting('app_settings-app_name');
$ByeEmail = str_replace("SFPAGENAME", $PageName, $ByeEmail);
if (strlen($ime) > 2) {
@@ -1705,16 +1917,25 @@ class ApiLogin
// Resetira geslo userja (kopirano iz ProfileClass.php) - PRETESTIRATI
private function userResetPassword()
{
- global $lang;
global $site_url;
global $pass_salt;
global $site_path;
global $site_domain;
- global $virtual_domain;
global $cookie_domain;
- global $app_settings;
- if (isset ($_GET['email']) || isset ($_POST['email'])) {
+ $language = 1;
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
+ }
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
+ }
+
+ if(is_numeric($language)){
+ include('../../lang/'.$language.'.php');
+ }
+
+ if (isset ($_GET['email']) || isset ($_POST['email']) || isset($this->email)) {
if (isset ($_GET['email'])) {
$email = strtolower($_GET['email']);
@@ -1722,15 +1943,18 @@ class ApiLogin
if (isset ($_POST['email'])) {
$email = strtolower($_POST['email']);
}
+ if (isset ($this->email)) {
+ $email = strtolower($this->email);
+ }
$email = CleanXSS($email);
// Ali gre za ajax klic
$ajaxKlic = false;
- if(!empty($_POST['ajax'])){
+ if(!empty($_POST['ajax']) || $this->method == 'AJAX'){
$ajaxKlic = true;
- if($_POST['lang'] == 'en' || $_POST['jezik'] == 'en'){
+ if($this->data['lang'] == 'en' || $this->data['jezik'] == 'en'){
include('../../lang/2.php');
}
else {
@@ -1744,40 +1968,39 @@ class ApiLogin
// Ce emaila ni v bazi
$user_id_1ka = User::findByEmail($email);
+
if (empty($user_id_1ka)) {
- if($ajaxKlic){
- echo json_encode([
- 'type' => 'error',
- 'text' => $lang['cms_error_no_email']
- ]);
+ if($ajaxKlic || $this->method == 'AJAX'){
+ return $this->ajaxResponse('error', ['text' => $lang['cms_error_no_email']]);
}else {
header('location: '.$this->page_urls['page_login_noEmail'.$this->prijava].'&email='.$email);
}
die();
} else {
$result = sisplet_query("SELECT name, pass, surname FROM users WHERE id='".$user_id_1ka."'");
- list ($ime, $geslo, $priimek) = mysqli_fetch_row($result);
+ [$ime, $geslo, $priimek] = mysqli_fetch_row($result);
}
// Novo geslo sestavis iz dveh nakljucnih besed + stevilke
- include_once($site_path.'lang/words_'.$lang['language_short'].'.php');
+ include($site_path.'lang/words_'.$lang['language_short'].'.php');
- $geslo = strtolower($words[rand(0, 999)].rand(0, 9).$words[rand(0, 999)]);
+ // Prva črka je velika začetnica št in male črke, da je v skladu s kompleksnostjo
+ $geslo = ucfirst(strtolower($words[rand(0, 999)].rand(0, 9).$words[rand(0, 999)]));
// passhint je parameter v linku ki ga skombiniras skupaj z emailom in mu potem aktiviras novo geslo
$passhint = base64_encode((hash('SHA256', time().$pass_salt)));
$chk = sisplet_query("SELECT id FROm users WHERE email='$email' AND UNIX_TIMESTAMP(NOW())-LastLP>600");
if (mysqli_num_rows($chk) > 0) {
- $result = sisplet_query("UPDATE users SET LastLP=UNIX_TIMESTAMP(NOW()), lost_password='".base64_encode((hash(SHA256, $geslo.$pass_salt)))."', lost_password_code='$passhint' WHERE email='$email'");
+ $result = sisplet_query("UPDATE users SET LastLP=UNIX_TIMESTAMP(NOW()), lost_password='".base64_encode((hash('SHA256', $geslo.$pass_salt)))."', lost_password_code='$passhint' WHERE email='$email'");
// Ce gre slucajno za virtualko
- $Subject = ($virtual_domain) ? $lang['lost_pass_subject_virtual'] : $lang['lost_pass_subject'];
+ $Subject = (isVirtual()) ? $lang['lost_pass_subject_virtual'] : $lang['lost_pass_subject'];
$Content = $lang['lost_pass_mail'];
- $PageName = $app_settings['app_name'];
+ $PageName = AppSettings::getInstance()->getSetting('app_settings-app_name');
$ZaMail = '<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">'.'<html><head> <title>'.$Subject.'</title><meta content="text/html; charset=utf-8" http-equiv=Content-type></head><body>';
@@ -1799,7 +2022,7 @@ class ApiLogin
$Subject = str_replace("SFPAGENAME", $PageName, $Subject);
// Ce gre slucajno za virtualko
- if($virtual_domain)
+ if(isVirtual())
$Subject = str_replace("SFVIRTUALNAME", $site_domain, $Subject);
if ($LoginWith == 1) {
@@ -1832,11 +2055,8 @@ class ApiLogin
}
}
- if($ajaxKlic){
- echo json_encode([
- 'type' => 'success',
- 'text' => $lang['lp_sent'].'.'
- ]);
+ if($ajaxKlic || $this->method == 'AJAX'){
+ return $this->ajaxResponse('success', ['text' => $lang['lp_sent']]);
}else {
// Preusmerimo na stran potrditve
header('location: '.$this->page_urls['page_reset_password'].'&email='.$email);
@@ -1850,11 +2070,22 @@ class ApiLogin
// Aktivira resetirano geslo userja (kopirano iz ProfileClass.php) - PRETESTIRATI
private function userResetPasswordActivate()
{
- global $lang;
global $site_url;
global $pass_salt;
global $cookie_domain;
+ $language = 1;
+ if(isset($this->data['language'])){
+ $language = $this->data['language'];
+ }
+ elseif(isset($this->data['jezik'])){
+ $language = ($this->data['jezik'] == 'en' ? 2 : 1);
+ }
+
+ if(is_numeric($language)){
+ include('../../lang/'.$language.'.php');
+ }
+
$ajaxKlic = (!empty($_POST['ajax']) ? true : false);
if (isset($_POST['code']) && isset($_POST['email']) && isset($_POST['pass'])) {
@@ -1911,4 +2142,22 @@ class ApiLogin
header('location: '.$this->page_urls['page_reset_password_activate'].'&code='.$code.'&error=1');
}
}
+
+ private function ajaxResponse($type, $data = [])
+ {
+ echo json_encode([
+ 'type' => $type,
+ 'data' => $data
+ ]);
+
+ die();
+ }
+
+ /*
+ * Kodiramo piškotek, ki ga posredujemo preko cUrl-ja
+ */
+ private function cookieEncode(array $piskotek)
+ {
+ return base64_encode(serialize($piskotek));
+ }
} \ No newline at end of file
diff --git a/frontend/api/class.ApiLoginController.php b/frontend/api/class.ApiLoginController.php
index d3a0100..222adcf 100644
--- a/frontend/api/class.ApiLoginController.php
+++ b/frontend/api/class.ApiLoginController.php
@@ -22,8 +22,11 @@ class ApiLoginController{
// Preberemo poslane podatke
- //$this->processCall();
- $this->processCallForm();
+ $this->processCall();
+
+ if(empty($this->data)) {
+ $this->processCallForm();
+ }
/*echo 'Params:';
@@ -31,11 +34,10 @@ class ApiLoginController{
echo '<br>Data:';
var_dump($this->data);
echo 'Metoda: '.$this->method;*/
-
-
+
// Izvedemo akcijo
- $login = new ApiLogin();
- $login->executeAction($this->params, $this->data);
+ $login = new ApiLogin();
+ $login->executeAction($this->params, $this->data, $this->method);
}
@@ -51,6 +53,7 @@ class ApiLoginController{
// Preberemo podatke iz post-a
$this->data = json_decode(file_get_contents('php://input'), true);
+
}
// Preberemo poslane podatke (ce posiljamo direktno iz forme)
diff --git a/frontend/api/fb_login.php b/frontend/api/fb_login.php
index 07e4842..f772c0f 100644
--- a/frontend/api/fb_login.php
+++ b/frontend/api/fb_login.php
@@ -1,20 +1,16 @@
<?php
include_once '../../settings.php';
- include_once '../../settings_optional.php';
include_once '../../function.php';
include_once '../../vendor/autoload.php';
if (isset ($_GET['code']) && $_GET['code'] != "") {
-
- /*$profile = new Profile();
- $profile->FBLogin();*/
$login = new ApiLogin();
$login->executeAction($params=array('action'=>'login_facebook'), $data=array());
}
else {
- header ('location: https://www.facebook.com/v2.10/dialog/oauth?client_id=' .$facebook_appid .'&redirect_uri=https://www.1ka.si/frontend/api/fb_login.php&auth_type=rerequest&scope=email,public_profile');
+ header ('location: https://www.facebook.com/v2.10/dialog/oauth?client_id=' .AppSettings::getInstance()->getSetting('facebook-appid') .'&redirect_uri=https://www.1ka.si/frontend/api/fb_login.php&auth_type=rerequest&scope=email,public_profile');
}
?>
diff --git a/frontend/api/login_AAI.php b/frontend/api/login_AAI.php
index 2cb7da0..4268af0 100644
--- a/frontend/api/login_AAI.php
+++ b/frontend/api/login_AAI.php
@@ -4,10 +4,6 @@
require_once ('../../function.php');
include_once '../../vendor/autoload.php';
- /*require_once ('../../function/ProfileClass.php');
- $profil = new Profile();
- $profil->eduroamAnotherServerLogin();*/
-
$login = new ApiLogin();
$login->executeAction($params=array('action'=>'login_AAI'), $data=array());