UserRepository::getUserByPassword()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php namespace VojtaSvoboda\CodeLogin\Repositories;
2
3
use Auth;
4
use October\Rain\Auth\AuthException;
5
use RainLab\User\Models\User;
6
7
class UserRepository
8
{
9
	/**
10
	 * Get all users
11
	 *
12
	 * @return mixed
13
	 */
14
	public function getAllUsers()
15
	{
16
		return User::where('is_activated', true)->get();
17
	}
18
19
	/**
20
	 * Returns user by password
21
	 *
22
	 * @param $password
23
	 *
24
	 * @return User|null
25
	 */
26
	public function getUserByPassword($password)
27
	{
28
		foreach ($this->getAllUsers() as $user) {
29
30
			try {
31
				$user = Auth::findUserByCredentials([
32
					'email' => $user->email,
33
					'password' => $password,
34
				]);
35
36
				return $user;
37
38
			} catch(AuthException $e) {
39
				$user = null;
40
			}
41
42
		}
43
44
		return null;
45
	}
46
}
47