158 lines
4.4 KiB
PHP
158 lines
4.4 KiB
PHP
<?php
|
|
namespace controls;
|
|
|
|
class Users
|
|
{
|
|
|
|
public static function permissions( $user_id, $module = '', $action = '' )
|
|
{
|
|
// Pyziak Jacek
|
|
$permissions[ 1 ][ 'projects' ] = true;
|
|
$permissions[ 1 ][ 'finances' ] = true;
|
|
$permissions[ 1 ][ 'wiki' ] = true;
|
|
$permissions[ 1 ][ 'crm' ] = true;
|
|
// Pyziak Grzegorz
|
|
$permissions[ 3 ][ 'projects' ] = true;
|
|
$permissions[ 3 ][ 'finances' ] = true;
|
|
$permissions[ 3 ][ 'wiki' ] = true;
|
|
$permissions[ 3 ][ 'crm' ] = true;
|
|
// Roman Pyrih
|
|
$permissions[ 5 ][ 'projects' ] = true;
|
|
$permissions[ 5 ][ 'finances' ] = false;
|
|
$permissions[ 5 ][ 'wiki' ] = true;
|
|
$permissions[ 5 ][ 'crm' ] = false;
|
|
|
|
if ( $action and isset( $permissions[ $user_id ][ $module ][ $action ] ) )
|
|
{
|
|
return $permissions[ $user_id ][ $module ][ $action ];
|
|
}
|
|
|
|
if ( isset( $permissions[ $user_id ][ $module ] ) )
|
|
{
|
|
return $permissions[ $user_id ][ $module ];
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function logout()
|
|
{
|
|
$domain = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] );
|
|
$cookie_name = str_replace( '.', '-', $domain );
|
|
|
|
setcookie( $cookie_name, "", strtotime( "-1 year" ), "/", $domain );
|
|
session_destroy();
|
|
header( 'Location: /' );
|
|
exit;
|
|
}
|
|
|
|
public static function settings_save()
|
|
{
|
|
global $mdb, $user;
|
|
|
|
if ( \factory\Users::settings_save( $user[ 'id' ], \S::get( 'pushover_api' ), \S::get( 'pushover_user' ) ) )
|
|
{
|
|
$user = $mdb -> get( 'users', '*', [ 'id' => $user[ 'id' ] ] );
|
|
\S::set_session( 'user', $user );
|
|
\S::alert( 'Ustawienia zostały zapisane.' );
|
|
}
|
|
header( 'Location: /settings' );
|
|
exit;
|
|
}
|
|
|
|
public static function settings()
|
|
{
|
|
global $user;
|
|
|
|
if ( !$user )
|
|
{
|
|
header( 'Location: /login' );
|
|
exit;
|
|
}
|
|
|
|
return \view\Users::settings(
|
|
$user
|
|
);
|
|
}
|
|
|
|
public static function settings_save_google_ads()
|
|
{
|
|
$fields = [
|
|
'google_ads_developer_token',
|
|
'google_ads_client_id',
|
|
'google_ads_client_secret',
|
|
'google_ads_refresh_token',
|
|
'google_ads_manager_account_id',
|
|
];
|
|
|
|
foreach ( $fields as $field )
|
|
{
|
|
\services\GoogleAdsApi::set_setting( $field, \S::get( $field ) );
|
|
}
|
|
|
|
// wyczyść cached token przy zmianie credentials
|
|
\services\GoogleAdsApi::set_setting( 'google_ads_access_token', null );
|
|
\services\GoogleAdsApi::set_setting( 'google_ads_access_token_expires', null );
|
|
|
|
\S::alert( 'Ustawienia Google Ads zostały zapisane.' );
|
|
header( 'Location: /settings' );
|
|
exit;
|
|
}
|
|
|
|
public static function settings_save_openai()
|
|
{
|
|
\services\GoogleAdsApi::set_setting( 'openai_enabled', \S::get( 'openai_enabled' ) ? '1' : '0' );
|
|
\services\GoogleAdsApi::set_setting( 'openai_api_key', \S::get( 'openai_api_key' ) );
|
|
\services\GoogleAdsApi::set_setting( 'openai_model', \S::get( 'openai_model' ) );
|
|
|
|
\S::alert( 'Ustawienia OpenAI zostały zapisane.' );
|
|
header( 'Location: /settings' );
|
|
exit;
|
|
}
|
|
|
|
public static function settings_save_claude()
|
|
{
|
|
\services\GoogleAdsApi::set_setting( 'claude_enabled', \S::get( 'claude_enabled' ) ? '1' : '0' );
|
|
\services\GoogleAdsApi::set_setting( 'claude_api_key', \S::get( 'claude_api_key' ) );
|
|
\services\GoogleAdsApi::set_setting( 'claude_model', \S::get( 'claude_model' ) );
|
|
|
|
\S::alert( 'Ustawienia Claude zostały zapisane.' );
|
|
header( 'Location: /settings' );
|
|
exit;
|
|
}
|
|
|
|
public static function login()
|
|
{
|
|
if ( $user = \factory\Users::login(
|
|
\S::get( 'email' ),
|
|
md5( \S::get( 'password' ) )
|
|
) )
|
|
{
|
|
// zapamiętaj logowanie
|
|
if ( \S::get( 'remember' ) )
|
|
{
|
|
$domain = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] );
|
|
$cookie_name = str_replace( '.', '-', $domain );
|
|
|
|
$value = [ 'email' => \S::get( 'email' ), 'hash' => md5( \S::get( 'password' ) ) ];
|
|
$value = json_encode( $value );
|
|
|
|
setcookie( $cookie_name, $value, strtotime( "+1 year" ), "/", $domain );
|
|
}
|
|
|
|
\S::set_session( 'user', $user );
|
|
echo json_encode( [ 'result' => 'true', 'msg' => 'Właśnie zostałeś zalogowany. Za chwilę nastąpi przekierowanie.', 'default_project' => $user[ 'default_project' ] ] );
|
|
}
|
|
else
|
|
{
|
|
echo json_encode( [ 'result' => 'false', 'msg' => 'Podany login i hasło są nieprawidłowe.' ] );
|
|
}
|
|
exit;
|
|
}
|
|
|
|
public static function login_form()
|
|
{
|
|
return \Tpl::view( 'users/login-form' );
|
|
}
|
|
|
|
} |