Completed
Pull Request — master (#10)
by
unknown
16s
created
components/CodeLogin.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -16,137 +16,137 @@
 block discarded – undo
16 16
 
17 17
 class CodeLogin extends ComponentBase
18 18
 {
19
-    public function componentDetails()
20
-    {
21
-        return [
22
-            'name'        => 'vojtasvoboda.codelogin::lang.logincomponent.name',
23
-            'description' => 'vojtasvoboda.codelogin::lang.logincomponent.description'
24
-        ];
25
-    }
26
-
27
-    public function defineProperties()
28
-    {
29
-        return [
30
-            'redirect' => [
31
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.title',
32
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.description',
33
-                'type'        => 'dropdown',
34
-                'default'     => ''
35
-            ],
36
-            'visible' => [
37
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.visible.title',
38
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.visible.description',
39
-                'type'        => 'checkbox',
40
-                'default'     => false
41
-            ],
42
-            'button' => [
43
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.button.title',
44
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.button.description',
45
-                'type'        => 'string',
46
-                'default'     => 'enter'
47
-            ],
48
-            'group' => [
49
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.group.title',
50
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.group.description',
51
-                'type'        => 'dropdown',
52
-                'default'     => null
53
-            ]
54
-        ];
55
-    }
56
-
57
-    public function getRedirectOptions()
58
-    {
59
-        $default = [
60
-            '' => '- none -'
61
-        ];
62
-        $pages = Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
63
-
64
-        return $default + $pages;
65
-    }
66
-
67
-    public function getGroupOptions()
68
-    {
69
-        $groups = (new UserRepository())->getAllGroups(['id', 'name']);
70
-        return [
71
-                '' => '- none -'
72
-            ] + $groups->pluck('name', 'id')->toArray();
73
-    }
74
-
75
-    /**
76
-     * Executed when this component is bound to a page or layout.
77
-     */
78
-    public function onRun()
79
-    {
80
-        $this->page['visible'] = $this->property('visible');
81
-        $this->page['button'] = $this->property('button');
82
-    }
83
-
84
-    /**
85
-     * Sign in the user
86
-     */
87
-    public function onCodesignin()
88
-    {
89
-        try {
90
-            return $this->doSignin();
91
-
92
-        } catch (Exception $ex) {
93
-            if (Request::ajax()) {
94
-                throw $ex;
95
-            }
96
-            Flash::error($ex->getMessage());
97
-        }
98
-    }
99
-
100
-    private function doSignin()
101
-    {
102
-        /*
19
+	public function componentDetails()
20
+	{
21
+		return [
22
+			'name'        => 'vojtasvoboda.codelogin::lang.logincomponent.name',
23
+			'description' => 'vojtasvoboda.codelogin::lang.logincomponent.description'
24
+		];
25
+	}
26
+
27
+	public function defineProperties()
28
+	{
29
+		return [
30
+			'redirect' => [
31
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.title',
32
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.description',
33
+				'type'        => 'dropdown',
34
+				'default'     => ''
35
+			],
36
+			'visible' => [
37
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.visible.title',
38
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.visible.description',
39
+				'type'        => 'checkbox',
40
+				'default'     => false
41
+			],
42
+			'button' => [
43
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.button.title',
44
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.button.description',
45
+				'type'        => 'string',
46
+				'default'     => 'enter'
47
+			],
48
+			'group' => [
49
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.group.title',
50
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.group.description',
51
+				'type'        => 'dropdown',
52
+				'default'     => null
53
+			]
54
+		];
55
+	}
56
+
57
+	public function getRedirectOptions()
58
+	{
59
+		$default = [
60
+			'' => '- none -'
61
+		];
62
+		$pages = Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
63
+
64
+		return $default + $pages;
65
+	}
66
+
67
+	public function getGroupOptions()
68
+	{
69
+		$groups = (new UserRepository())->getAllGroups(['id', 'name']);
70
+		return [
71
+				'' => '- none -'
72
+			] + $groups->pluck('name', 'id')->toArray();
73
+	}
74
+
75
+	/**
76
+	 * Executed when this component is bound to a page or layout.
77
+	 */
78
+	public function onRun()
79
+	{
80
+		$this->page['visible'] = $this->property('visible');
81
+		$this->page['button'] = $this->property('button');
82
+	}
83
+
84
+	/**
85
+	 * Sign in the user
86
+	 */
87
+	public function onCodesignin()
88
+	{
89
+		try {
90
+			return $this->doSignin();
91
+
92
+		} catch (Exception $ex) {
93
+			if (Request::ajax()) {
94
+				throw $ex;
95
+			}
96
+			Flash::error($ex->getMessage());
97
+		}
98
+	}
99
+
100
+	private function doSignin()
101
+	{
102
+		/*
103 103
          * Validate input
104 104
          */
105
-        $data = post();
105
+		$data = post();
106 106
 
107
-        $rules = [];
108
-        $rules['code'] = 'required|min:2';
107
+		$rules = [];
108
+		$rules['code'] = 'required|min:2';
109 109
 
110
-        $messages = [];
111
-        $messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');
110
+		$messages = [];
111
+		$messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');
112 112
 
113
-        $validation = Validator::make($data, $rules, $messages);
114
-        if ($validation->fails()) {
115
-            throw new ValidationException($validation);
116
-        }
113
+		$validation = Validator::make($data, $rules, $messages);
114
+		if ($validation->fails()) {
115
+			throw new ValidationException($validation);
116
+		}
117 117
 
118
-        /*
118
+		/*
119 119
          * Find user by password
120 120
          */
121
-        $users = new UserRepository();
122
-        $userToLog = $users->getUserByPassword(array_get($data, 'code'), $this->property('group', null));
123
-        if ($userToLog === null) {
124
-            $exception = new ValidationException([ 'code' => trans('vojtasvoboda.codelogin::lang.form.wrong_code') ]);
125
-            throw $exception;
126
-        }
127
-
128
-        /*
121
+		$users = new UserRepository();
122
+		$userToLog = $users->getUserByPassword(array_get($data, 'code'), $this->property('group', null));
123
+		if ($userToLog === null) {
124
+			$exception = new ValidationException([ 'code' => trans('vojtasvoboda.codelogin::lang.form.wrong_code') ]);
125
+			throw $exception;
126
+		}
127
+
128
+		/*
129 129
          * Authenticate user
130 130
          */
131
-        $remember = true;
132
-        $user = Auth::authenticate([
133
-            'login' => $userToLog->email,
134
-            'password' => array_get($data, 'code')
135
-        ], $remember);
131
+		$remember = true;
132
+		$user = Auth::authenticate([
133
+			'login' => $userToLog->email,
134
+			'password' => array_get($data, 'code')
135
+		], $remember);
136 136
 
137
-        /*
137
+		/*
138 138
          * Event just for backward compatibility. It's more then recommand use
139 139
          * standard rainlab.user.login event - see readme.
140 140
          */
141
-        Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);
141
+		Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);
142 142
 
143
-        /*
143
+		/*
144 144
          * Redirect to the intended page after successful sign in
145 145
          */
146
-        $redirectUrl = $this->pageUrl($this->property('redirect'));
146
+		$redirectUrl = $this->pageUrl($this->property('redirect'));
147 147
 
148
-        if ($redirectUrl = post('redirect', $redirectUrl)) {
149
-            return Redirect::intended($redirectUrl);
150
-        }
151
-    }
148
+		if ($redirectUrl = post('redirect', $redirectUrl)) {
149
+			return Redirect::intended($redirectUrl);
150
+		}
151
+	}
152 152
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 
67 67
     public function getGroupOptions()
68 68
     {
69
-        $groups = (new UserRepository())->getAllGroups(['id', 'name']);
69
+        $groups = (new UserRepository())->getAllGroups([ 'id', 'name' ]);
70 70
         return [
71 71
                 '' => '- none -'
72 72
             ] + $groups->pluck('name', 'id')->toArray();
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
      */
78 78
     public function onRun()
79 79
     {
80
-        $this->page['visible'] = $this->property('visible');
81
-        $this->page['button'] = $this->property('button');
80
+        $this->page[ 'visible' ] = $this->property('visible');
81
+        $this->page[ 'button' ] = $this->property('button');
82 82
     }
83 83
 
84 84
     /**
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
          */
105 105
         $data = post();
106 106
 
107
-        $rules = [];
108
-        $rules['code'] = 'required|min:2';
107
+        $rules = [ ];
108
+        $rules[ 'code' ] = 'required|min:2';
109 109
 
110
-        $messages = [];
111
-        $messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');
110
+        $messages = [ ];
111
+        $messages[ 'required' ] = trans('vojtasvoboda.codelogin::lang.form.required');
112 112
 
113 113
         $validation = Validator::make($data, $rules, $messages);
114 114
         if ($validation->fails()) {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
          * Event just for backward compatibility. It's more then recommand use
139 139
          * standard rainlab.user.login event - see readme.
140 140
          */
141
-        Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);
141
+        Event::fire('vojtasvoboda.codelogin.afterlogin', [ $user ]);
142 142
 
143 143
         /*
144 144
          * Redirect to the intended page after successful sign in
Please login to merge, or discard this patch.
lang/en/lang.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 return [
4
-    'plugin' => [
5
-        'name' => 'Code login',
6
-        'description' => 'Code/password login form'
7
-    ],
8
-    'logincomponent' => [
9
-        'name' => 'Code login',
10
-        'description' => 'Insert code/password login form',
11
-        'redirect' => [
12
-            'title' => 'Redirect to',
13
-            'description' => 'Page name to redirect to after update, sign in or registration.',
14
-        ],
15
-        'visible' => [
16
-            'title' => 'Code/password visible',
17
-            'description' => 'When checked, inserted password will be visible (input type text used).'
18
-        ],
19
-        'button' => [
20
-            'title' => 'Button label',
21
-            'description' => 'String which will be shown at login button.'
22
-        ],
23
-        'group' => [
24
-            'title' => 'Group',
25
-            'description' => 'You may select a group, in which the component should look for the user.'
26
-        ]
27
-    ],
28
-    'form' => [
29
-	    'wrong_code' => 'Wrong code!',
30
-	    'required' => 'The :attribute field is required.'
31
-    ],
4
+	'plugin' => [
5
+		'name' => 'Code login',
6
+		'description' => 'Code/password login form'
7
+	],
8
+	'logincomponent' => [
9
+		'name' => 'Code login',
10
+		'description' => 'Insert code/password login form',
11
+		'redirect' => [
12
+			'title' => 'Redirect to',
13
+			'description' => 'Page name to redirect to after update, sign in or registration.',
14
+		],
15
+		'visible' => [
16
+			'title' => 'Code/password visible',
17
+			'description' => 'When checked, inserted password will be visible (input type text used).'
18
+		],
19
+		'button' => [
20
+			'title' => 'Button label',
21
+			'description' => 'String which will be shown at login button.'
22
+		],
23
+		'group' => [
24
+			'title' => 'Group',
25
+			'description' => 'You may select a group, in which the component should look for the user.'
26
+		]
27
+	],
28
+	'form' => [
29
+		'wrong_code' => 'Wrong code!',
30
+		'required' => 'The :attribute field is required.'
31
+	],
32 32
 ];
Please login to merge, or discard this patch.
lang/de/lang.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 return [
4
-    'plugin' => [
5
-        'name' => 'Kennwort Schutz',
6
-        'description' => 'Kennwort Schutz Anmelde-Formular'
7
-    ],
8
-    'logincomponent' => [
9
-        'name' => 'Kennwort Schutz',
10
-        'description' => 'Kennwort Schutz Anmelde-Formular hinzufügen',
11
-        'redirect' => [
12
-            'title' => 'Umleiten nach',
13
-            'description' => 'Seitenname für die Umleitung nach dem Update, Anmeldung oder Registration.'
14
-        ],
15
-        'visible' => [
16
-            'title' => 'Kennwort sichtbar',
17
-            'description' => 'Wenn aktiviert, Kennwort sichtbar (Verwendet Eingabetyp Text)'
18
-        ],
19
-        'button' => [
20
-            'title' => 'Button Titel',
21
-            'description' => 'Anmelde Button Text.'
22
-        ],
23
-        'group' => [
24
-            'title' => 'Gruppe',
25
-            'description' => 'Sie können hier eine Gruppe wählen, in der nach dem Benutzer gesucht werden soll.'
26
-        ]
27
-    ],
28
-    'form' => [
29
-	    'wrong_code' => 'Falsches Kennwort!',
30
-	    'required' => 'Das :attribute Feld ist notwendig.'
31
-    ],
4
+	'plugin' => [
5
+		'name' => 'Kennwort Schutz',
6
+		'description' => 'Kennwort Schutz Anmelde-Formular'
7
+	],
8
+	'logincomponent' => [
9
+		'name' => 'Kennwort Schutz',
10
+		'description' => 'Kennwort Schutz Anmelde-Formular hinzufügen',
11
+		'redirect' => [
12
+			'title' => 'Umleiten nach',
13
+			'description' => 'Seitenname für die Umleitung nach dem Update, Anmeldung oder Registration.'
14
+		],
15
+		'visible' => [
16
+			'title' => 'Kennwort sichtbar',
17
+			'description' => 'Wenn aktiviert, Kennwort sichtbar (Verwendet Eingabetyp Text)'
18
+		],
19
+		'button' => [
20
+			'title' => 'Button Titel',
21
+			'description' => 'Anmelde Button Text.'
22
+		],
23
+		'group' => [
24
+			'title' => 'Gruppe',
25
+			'description' => 'Sie können hier eine Gruppe wählen, in der nach dem Benutzer gesucht werden soll.'
26
+		]
27
+	],
28
+	'form' => [
29
+		'wrong_code' => 'Falsches Kennwort!',
30
+		'required' => 'Das :attribute Feld ist notwendig.'
31
+	],
32 32
 ];
Please login to merge, or discard this patch.
repositories/UserRepository.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -7,60 +7,60 @@
 block discarded – undo
7 7
 
8 8
 class UserRepository
9 9
 {
10
-    /**
11
-     * Returns user by password
12
-     *
13
-     * @param $password
14
-     *
15
-     * @return User|null
16
-     */
17
-    public function getUserByPassword($password, $groupId = null)
18
-    {
19
-        $users = !empty($groupId) ? $this->getAllUsersOfGroup($groupId) : $this->getAllUsers();
10
+	/**
11
+	 * Returns user by password
12
+	 *
13
+	 * @param $password
14
+	 *
15
+	 * @return User|null
16
+	 */
17
+	public function getUserByPassword($password, $groupId = null)
18
+	{
19
+		$users = !empty($groupId) ? $this->getAllUsersOfGroup($groupId) : $this->getAllUsers();
20 20
 
21
-        foreach ($users as $user) {
21
+		foreach ($users as $user) {
22 22
 
23
-            try {
24
-                $user = Auth::findUserByCredentials([
25
-                    'email' => $user->email,
26
-                    'password' => $password,
27
-                ]);
23
+			try {
24
+				$user = Auth::findUserByCredentials([
25
+					'email' => $user->email,
26
+					'password' => $password,
27
+				]);
28 28
 
29
-                return $user;
29
+				return $user;
30 30
 
31
-            } catch (AuthException $e) {
32
-                $user = null;
33
-            }
31
+			} catch (AuthException $e) {
32
+				$user = null;
33
+			}
34 34
 
35
-        }
35
+		}
36 36
 
37
-        return null;
38
-    }
37
+		return null;
38
+	}
39 39
 
40
-    /**
41
-     * Get all users
42
-     *
43
-     * @return mixed
44
-     */
45
-    public function getAllUsersOfGroup($groupId)
46
-    {
47
-        return User::whereHas('groups', function ($groupQuery) use ($groupId) {
48
-            return $groupQuery->where('id', '=', $groupId);
49
-        })->where('is_activated', true)->get();
50
-    }
40
+	/**
41
+	 * Get all users
42
+	 *
43
+	 * @return mixed
44
+	 */
45
+	public function getAllUsersOfGroup($groupId)
46
+	{
47
+		return User::whereHas('groups', function ($groupQuery) use ($groupId) {
48
+			return $groupQuery->where('id', '=', $groupId);
49
+		})->where('is_activated', true)->get();
50
+	}
51 51
 
52
-    /**
53
-     * Get all users
54
-     *
55
-     * @return mixed
56
-     */
57
-    public function getAllUsers()
58
-    {
59
-        return User::where('is_activated', true)->get();
60
-    }
52
+	/**
53
+	 * Get all users
54
+	 *
55
+	 * @return mixed
56
+	 */
57
+	public function getAllUsers()
58
+	{
59
+		return User::where('is_activated', true)->get();
60
+	}
61 61
 
62
-    public function getAllGroups($columns = ['*'])
63
-    {
64
-        return UserGroup::select($columns)->get();
65
-    }
62
+	public function getAllGroups($columns = ['*'])
63
+	{
64
+		return UserGroup::select($columns)->get();
65
+	}
66 66
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function getAllUsersOfGroup($groupId)
46 46
     {
47
-        return User::whereHas('groups', function ($groupQuery) use ($groupId) {
47
+        return User::whereHas('groups', function($groupQuery) use ($groupId) {
48 48
             return $groupQuery->where('id', '=', $groupId);
49 49
         })->where('is_activated', true)->get();
50 50
     }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         return User::where('is_activated', true)->get();
60 60
     }
61 61
 
62
-    public function getAllGroups($columns = ['*'])
62
+    public function getAllGroups($columns = [ '*' ])
63 63
     {
64 64
         return UserGroup::select($columns)->get();
65 65
     }
Please login to merge, or discard this patch.