Skip to content

Commit 37aa8b0

Browse files
committed
Update files to PSR-2 standards
1 parent d640cc1 commit 37aa8b0

File tree

3 files changed

+335
-331
lines changed

3 files changed

+335
-331
lines changed

app/Http/Controllers/Auth/LoginController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ protected function authenticated(Request $request, Authenticatable $user)
9797
auth()->login($user);
9898
}
9999

100-
// ldap groups refresh
101-
if (config('services.ldap.user_to_groups') !== false && $request->filled('username')) {
102-
$ldapRepo = new LdapRepo($this->userRepo);
103-
$ldapRepo->syncGroups($user,$request->input('username'));
104-
}
100+
// ldap groups refresh
101+
if (config('services.ldap.user_to_groups') !== false && $request->filled('username')) {
102+
$ldapRepo = new LdapRepo($this->userRepo);
103+
$ldapRepo->syncGroups($user, $request->input('username'));
104+
}
105105

106106

107-
$path = session()->pull('url.intended', '/');
107+
$path = session()->pull('url.intended', '/');
108108
$path = baseUrl($path, true);
109109
return redirect($path);
110110
}

app/Repos/LdapRepo.php

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,77 +8,77 @@
88
class LdapRepo
99
{
1010

11-
protected $ldap = null;
12-
protected $ldapService = null;
11+
protected $ldap = null;
12+
protected $ldapService = null;
1313

14-
protected $config;
14+
protected $config;
1515

16-
/**
17-
* LdapRepo constructor.
18-
* @param \BookStack\Repos\UserRepo $userRepo
19-
*/
20-
public function __construct(UserRepo $userRepo)
21-
{
22-
$this->config = config('services.ldap');
16+
/**
17+
* LdapRepo constructor.
18+
* @param \BookStack\Repos\UserRepo $userRepo
19+
*/
20+
public function __construct(UserRepo $userRepo)
21+
{
22+
$this->config = config('services.ldap');
2323

24-
if (config('auth.method') !== 'ldap') {
25-
return false;
26-
}
24+
if (config('auth.method') !== 'ldap') {
25+
return false;
26+
}
2727

28-
$this->ldapService = new LdapService(new Ldap);
29-
$this->userRepo = $userRepo;
30-
}
28+
$this->ldapService = new LdapService(new Ldap);
29+
$this->userRepo = $userRepo;
30+
}
3131

32-
/**
33-
* If there is no ldap connection, all methods calls to this library will return null
34-
*/
35-
public function __call($method, $arguments)
36-
{
37-
if ($this->ldap === null) {
38-
return null;
39-
}
32+
/**
33+
* If there is no ldap connection, all methods calls to this library will return null
34+
*/
35+
public function __call($method, $arguments)
36+
{
37+
if ($this->ldap === null) {
38+
return null;
39+
}
4040

41-
return call_user_func_array(array($this,$method),$arguments);
42-
}
41+
return call_user_func_array(array($this,$method), $arguments);
42+
}
4343

44-
/**
45-
* Sync the LDAP groups to the user roles for the current user
46-
* @param \BookStack\User $user
47-
* @param string $userName
48-
* @throws \BookStack\Exceptions\NotFoundException
49-
*/
50-
public function syncGroups($user,$userName)
51-
{
52-
$userLdapGroups = $this->ldapService->getUserGroups($userName);
53-
$userLdapGroups = $this->groupNameFilter($userLdapGroups);
54-
// get the ids for the roles from the names
55-
$ldapGroupsAsRoles = Role::whereIn('name',$userLdapGroups)->pluck('id');
56-
// sync groups
57-
if ($this->config['remove_from_groups']) {
58-
$user->roles()->sync($ldapGroupsAsRoles);
59-
$this->userRepo->attachDefaultRole($user);
60-
} else {
61-
$user->roles()->syncWithoutDetaching($ldapGroupsAsRoles);
62-
}
44+
/**
45+
* Sync the LDAP groups to the user roles for the current user
46+
* @param \BookStack\User $user
47+
* @param string $userName
48+
* @throws \BookStack\Exceptions\NotFoundException
49+
*/
50+
public function syncGroups($user, $userName)
51+
{
52+
$userLdapGroups = $this->ldapService->getUserGroups($userName);
53+
$userLdapGroups = $this->groupNameFilter($userLdapGroups);
54+
// get the ids for the roles from the names
55+
$ldapGroupsAsRoles = Role::whereIn('name', $userLdapGroups)->pluck('id');
56+
// sync groups
57+
if ($this->config['remove_from_groups']) {
58+
$user->roles()->sync($ldapGroupsAsRoles);
59+
$this->userRepo->attachDefaultRole($user);
60+
} else {
61+
$user->roles()->syncWithoutDetaching($ldapGroupsAsRoles);
62+
}
6363

64-
// make the user an admin?
65-
if (in_array($this->config['admin'],$userLdapGroups)) {
66-
$this->userRepo->attachSystemRole($user,'admin');
67-
}
68-
}
64+
// make the user an admin?
65+
if (in_array($this->config['admin'], $userLdapGroups)) {
66+
$this->userRepo->attachSystemRole($user, 'admin');
67+
}
68+
}
6969

70-
/**
71-
* Filter to convert the groups from ldap to the format of the roles name on BookStack
72-
* Spaces replaced with -, all lowercase letters
73-
* @param array $groups
74-
* @return array
75-
*/
76-
private function groupNameFilter($groups)
77-
{
78-
$return = [];
79-
foreach ($groups as $groupName) {
80-
$return[] = str_replace(' ', '-', strtolower($groupName));
81-
}
82-
return $return;
83-
}
84-
}
70+
/**
71+
* Filter to convert the groups from ldap to the format of the roles name on BookStack
72+
* Spaces replaced with -, all lowercase letters
73+
* @param array $groups
74+
* @return array
75+
*/
76+
private function groupNameFilter($groups)
77+
{
78+
$return = [];
79+
foreach ($groups as $groupName) {
80+
$return[] = str_replace(' ', '-', strtolower($groupName));
81+
}
82+
return $return;
83+
}
84+
}

0 commit comments

Comments
 (0)