Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CookieAuth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stud.IP
Plugins
CookieAuth
Commits
cfde5646
Commit
cfde5646
authored
6 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
studip 6.0, fixes
#5
parent
18f15b0d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
CookieAuth.php
+33
-55
33 additions, 55 deletions
CookieAuth.php
migrations/1_setup_user_configuration.php
+26
-0
26 additions, 0 deletions
migrations/1_setup_user_configuration.php
plugin.manifest
+2
-2
2 additions, 2 deletions
plugin.manifest
templates/login.php
+0
-10
0 additions, 10 deletions
templates/login.php
with
61 additions
and
67 deletions
CookieAuth.php
+
33
−
55
View file @
cfde5646
...
...
@@ -15,13 +15,13 @@
*/
final
class
CookieAuth
extends
StudIPPlugin
implements
SystemPlugin
{
const
CONFIG_NAME
=
'COOKIE_AUTH_TOKEN'
;
public
const
CONFIG_NAME
=
'COOKIE_AUTH_TOKEN'
;
/** @property User|null $cookie_login_user */
private
$cookie_login_user
=
null
;
private
User
|
null
$cookie_login_user
=
null
;
/** @property string $cookie_name */
private
$cookie_name
;
private
string
$cookie_name
;
/**
* Initialize a new instance of the plugin.
...
...
@@ -30,20 +30,15 @@ final class CookieAuth extends StudIPPlugin implements SystemPlugin
{
parent
::
__construct
();
$this
->
cookie_name
=
md5
(
Config
::
get
()
->
STUDIP_INSTALLATION_ID
)
.
self
::
class
;
$this
->
cookie_name
=
md5
(
Config
::
get
()
->
getValue
(
'
STUDIP_INSTALLATION_ID
'
)
)
.
self
::
class
;
if
(
!
User
::
findCurrent
())
{
$cookie_token
=
$_COOKIE
[
$this
->
cookie_name
]
??
null
;
if
(
$cookie_token
)
{
if
(
class_exists
(
'UserConfigEntry'
))
{
$user_config_entry
=
UserConfigEntry
::
findOneBySQL
(
"field = ? AND value = ?"
,
[
self
::
CONFIG_NAME
,
$cookie_token
]);
$this
->
cookie_login_user
=
User
::
find
(
$user_config_entry
->
user_id
);
}
else
{
$user_config_entry
=
ConfigValue
::
findOneBySQL
(
"field = ? AND value = ?"
,
[
self
::
CONFIG_NAME
,
$cookie_token
]);
if
(
$user_config_entry
)
{
$this
->
cookie_login_user
=
User
::
find
(
$user_config_entry
->
range_id
);
}
}
if
(
$this
->
cookie_login_user
&&
$this
->
cookie_login_user
->
locked
)
{
$this
->
cookie_login_user
=
null
;
...
...
@@ -54,56 +49,44 @@ final class CookieAuth extends StudIPPlugin implements SystemPlugin
if
(
isset
(
$this
->
cookie_login_user
))
{
$index
=
array_keys
(
Navigation
::
getItem
(
'/login'
)
->
getSubNavigation
())[
0
];
$navigation
=
new
Navigation
(
_
(
'Direkter Login'
),
URLHelper
::
getURL
(
'plugins.php/'
.
__CLASS__
,
[
'cid'
=>
null
,
'cancel_login'
=>
1
]));
$navigation
=
new
Navigation
(
_
(
'Direkter Login'
),
PluginEngine
::
getURL
(
$this
,
[
'cancel_login'
=>
1
],
'login'
)
);
$navigation
->
setDescription
(
sprintf
(
_
(
'von Nutzer: %s'
),
$this
->
cookie_login_user
->
username
));
Navigation
::
insertItem
(
'/login/remote_user'
,
$navigation
,
$index
);
if
(
StudipVersion
::
olderThan
(
'5.5'
)
&&
(
$GLOBALS
[
'auth'
]
->
auth
[
'uid'
]
===
''
||
$GLOBALS
[
'auth'
]
->
auth
[
'uid'
]
===
'form'
)
)
{
$selector
=
StudipVersion
::
newerThan
(
'5.2'
)
?
'#loginbox div a'
:
'div.index_main div a'
;
$this
->
inject_js
(
$selector
,
'login.php'
,
[
'username'
=>
$this
->
cookie_login_user
->
username
,
'url'
=>
URLHelper
::
getURL
(
'plugins.php/'
.
__CLASS__
,
[
'cancel_login'
=>
1
,
'return_to'
=>
$_SERVER
[
'REQUEST_URI'
]],
true
),
],
'before'
);
}
}
if
(
match_route
(
'dispatch.php/settings/general*'
))
{
$user
=
User
::
findCurrent
();
if
(
$user
&&
$user
->
getConfiguration
()
->
COOKIE_AUTH_TOKEN
&&
!
$this
->
cookie_login_user
)
{
if
(
$user
&&
$user
->
getConfiguration
()
->
getValue
(
self
::
CONFIG_NAME
)
&&
!
$this
->
cookie_login_user
)
{
$this
->
setCookie
(
$user
->
getConfiguration
()
->
COOKIE_AUTH_TOKEN
,
$user
->
getConfiguration
()
->
getValue
(
self
::
CONFIG_NAME
)
,
strtotime
(
'+1 year'
)
);
$this
->
cookie_login_user
=
$
GLOBALS
[
'
user
'
]
;
$this
->
cookie_login_user
=
$user
;
}
if
(
isset
(
$_POST
[
'forced_language'
]))
{
if
(
Request
::
get
(
'cookie_auth_token'
))
{
$token
=
$user
->
getConfiguration
()
->
COOKIE_AUTH_TOKEN
?:
$this
->
getNewToken
();
$user
->
getConfiguration
()
->
store
(
'COOKIE_AUTH_TOKEN'
,
$token
);
$token
=
$user
->
getConfiguration
()
->
getValue
(
self
::
CONFIG_NAME
)
?:
$this
->
getNewToken
();
$user
->
getConfiguration
()
->
store
(
self
::
CONFIG_NAME
,
$token
);
$this
->
setCookie
(
$token
,
strtotime
(
'+1 year'
)
);
}
else
{
$user
->
getConfiguration
()
->
delete
(
'COOKIE_AUTH_TOKEN'
);
$user
->
getConfiguration
()
->
delete
(
self
::
CONFIG_NAME
);
$this
->
setCookie
(
''
,
0
);
}
}
if
(
Navigation
::
hasItem
(
'/profile/settings'
))
{
$selector
=
StudipVersion
::
newerThan
(
'5.2'
)
?
'main#content-wrapper form fieldset'
:
'#layout_content form fieldset'
;
$this
->
inject_js
(
$selector
,
'main#content-wrapper form fieldset'
,
'settings.php'
,
[
'checked'
=>
$this
->
cookie_login_user
],
'append'
...
...
@@ -112,7 +95,7 @@ final class CookieAuth extends StudIPPlugin implements SystemPlugin
}
}
public
function
show
_action
()
public
function
login
_action
()
:
void
{
$redirect
=
Request
::
get
(
'return_to'
,
'index.php'
);
...
...
@@ -123,19 +106,10 @@ final class CookieAuth extends StudIPPlugin implements SystemPlugin
||
$this
->
cookie_login_user
->
id
!==
User
::
findCurrent
()
->
id
)
)
{
$GLOBALS
[
'sess'
]
->
regenerate_session_id
([
'auth'
]);
$GLOBALS
[
'auth'
]
->
unauth
();
$GLOBALS
[
'auth'
]
->
auth
[
'jscript'
]
=
true
;
$GLOBALS
[
'auth'
]
->
auth
[
'perm'
]
=
$this
->
cookie_login_user
[
'perms'
];
$GLOBALS
[
'auth'
]
->
auth
[
'uname'
]
=
$this
->
cookie_login_user
[
'username'
];
$GLOBALS
[
'auth'
]
->
auth
[
'auth_plugin'
]
=
$this
->
cookie_login_user
[
'auth_plugin'
];
$GLOBALS
[
'auth'
]
->
auth_set_user_settings
(
$this
->
cookie_login_user
->
id
);
$GLOBALS
[
'auth'
]
->
auth
[
'uid'
]
=
$this
->
cookie_login_user
->
id
;
auth
()
->
setAuthenticatedUser
(
$this
->
cookie_login_user
);
}
page_close
();
header
(
'Location: '
.
URLHelper
::
getURL
(
$redirect
));
die
();
}
public
static
function
onEnable
(
$plugin_id
)
...
...
@@ -145,8 +119,12 @@ final class CookieAuth extends StudIPPlugin implements SystemPlugin
$rp
->
assignPluginRoles
(
$plugin_id
,
range
(
1
,
7
));
}
private
function
inject_js
(
string
$selector
,
string
$template
,
array
$variables
,
string
$location
=
'after'
)
{
private
function
inject_js
(
string
$selector
,
string
$template
,
array
$variables
=
[],
string
$location
=
'after'
):
void
{
$factory
=
new
Flexi_TemplateFactory
(
__DIR__
.
'/templates'
);
$snippet
=
$factory
->
render
(
$template
,
$variables
);
$snippet
=
str_replace
(
"
\n
"
,
"
\\\n
"
,
$snippet
);
...
...
@@ -161,7 +139,7 @@ final class CookieAuth extends StudIPPlugin implements SystemPlugin
);
}
private
function
setCookie
(
string
$value
,
int
$expires
)
private
function
setCookie
(
string
$value
,
int
$expires
)
:
void
{
$url_parts
=
parse_url
(
$GLOBALS
[
'ABSOLUTE_URI_STUDIP'
]);
...
...
This diff is collapsed.
Click to expand it.
migrations/1_setup_user_configuration.php
0 → 100644
+
26
−
0
View file @
cfde5646
<?php
final
class
SetupUserConfiguration
extends
Migration
{
public
function
__construct
(
$verbose
=
false
)
{
parent
::
__construct
(
$verbose
);
require_once
__DIR__
.
'/../CookieAuth.php'
;
}
public
function
up
()
{
Config
::
get
()
->
create
(
CookieAuth
::
CONFIG_NAME
,
[
'value'
=>
''
,
'type'
=>
'string'
,
'range'
=>
'user'
,
'section'
=>
''
,
'description'
=>
'Token für die Authentifizierung via CookieAuth'
,
]);
}
protected
function
down
()
{
Config
::
get
()
->
delete
(
CookieAuth
::
CONFIG_NAME
);
}
}
This diff is collapsed.
Click to expand it.
plugin.manifest
+
2
−
2
View file @
cfde5646
pluginname=CookieAuth
pluginclassname=CookieAuth
origin=data-quest
version=10
studipMinVersion=
4
.0
version=1
.
0
studipMinVersion=
6
.0
This diff is collapsed.
Click to expand it.
templates/login.php
deleted
100644 → 0
+
0
−
10
View file @
18f15b0d
<?php
/**
* @var string $url
* @var string $username
*/
?>
<a
href=
"
<?=
htmlReady
(
$url
)
?>
"
>
<?=
sprintf
(
_
(
'Direkter Login von "%s"'
),
htmlReady
(
$username
))
?>
</a>
/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment