-
Notifications
You must be signed in to change notification settings - Fork 3
/
users.php
55 lines (50 loc) · 1.65 KB
/
users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?
public function updateUsers($users)
{
foreach ($users as $user) {
try {
if ($user['name'] && $user['login'] && $user['email'] && $user['password'] && strlen($user['name']) >= 10)
DB::table('users')->where('id', $user['id'])->update([
'name' => $user['name'],
'login' => $user['login'],
'email' => $user['email'],
'password' => md5($user['password'])
]);
} catch (\Throwable $e) {
return Redirect::back()->withErrors(['error', ['We couldn\'t update user: ' . $e->getMessage()]]);
}
}
return Redirect::back()->with(['success', 'All users updated.']);
}
public function storeUsers($users)
{
foreach ($users as $user) {
try {
if ($user['name'] && $user['login'] && $user['email'] && $user['password'] && strlen($user['name']) >= 10)
DB::table('users')->insert([
'name' => $user['name'],
'login' => $user['login'],
'email' => $user['email'],
'password' => md5($user['password'])
]);
} catch (\Throwable $e) {
return Redirect::back()->withErrors(['error', ['We couldn\'t store user: ' . $e->getMessage()]]);
}
}
$this->sendEmail($users);
return Redirect::back()->with(['success', 'All users created.']);
}
private function sendEmail($users)
{
foreach ($users as $user) {
$message = 'Account has beed created. You can log in as <b>' . $user['login'] . '</b>';
if ($user['email']) {
Mail::to($user['email'])
->cc('[email protected]')
->subject('New account created')
->queue($message);
}
}
return true;
}
?>