Commit 811e6a61 authored by ZeMKI's avatar ZeMKI
Browse files

Send email from backend

* solution optimized and functional, needs improvment in details.
* optimization user controller.
Fixes #8
parent ed19b7b6
......@@ -176,10 +176,7 @@ class UserController extends Controller
*/
public function store(Request $request)
{
if($request->testEmail == true){
Mail::to($request->email)->send(new VerificationEmail(new User,$request->emailtext? $request->emailtext : config('utilities.emailDefaultText')));
return redirect('/admin/supervisor')->with(['message'=>'Test Email sent to '.$request->email]);
}
if($this->sendTestEmail($request))return redirect('/admin/supervisor')->with(['message' => 'Test Email sent to ' . $request->email]);
$editpermissions = Permission::where('name', 'like', '%interviews')->get()->toArray();
......@@ -190,9 +187,9 @@ class UserController extends Controller
if ($userexist) {
if ($request->exists('emailtext')) return redirect('/admin/supervisor')->with(['message' => "User it's already registered!"]);
$userexist->syncRoles([$role], $study);
$userexist->attachPermissions($editpermissions, $study);
return response("User " . $userexist->email . " has been assigned to the selected studies");
} else {
$user = new User();
......@@ -206,15 +203,15 @@ class UserController extends Controller
$user->supervised_by = Auth::user()->id;
$user->save();
$user->attachRole($role, $study);
Mail::to($user->email)->send(new VerificationEmail($user,$request->emailtext? $request->emailtext : config('utilities.emailDefaultText')));
Mail::to($user->email)->send(new VerificationEmail($user, $request->emailtext ? $request->emailtext : config('utilities.emailDefaultText')));
}
$user->attachPermissions($editpermissions, $study);
if(!$request->emailtext)return response("An email verification was sent to " . $user->email . " please let the user open it");
else return redirect('/admin/supervisor')->with(['message'=>'User registered']);
if (!$request->exists('emailtext')) return response("An email verification was sent to " . $user->email . " please let the user open it.");
else return redirect('/admin/supervisor')->with(['message' => 'User registered - Password needs to be confirmed.']);
}
......@@ -362,4 +359,18 @@ class UserController extends Controller
$array = array_values($temp_array);
return $array;
}
/**
* @param Request $request
* @return bool
*/
private function sendTestEmail(Request $request): bool
{
if ($request->testEmail == true) {
Mail::to($request->email)->send(new VerificationEmail(new User, $request->emailtext ? $request->emailtext : config('utilities.emailDefaultText')));
return true;
}
return false;
}
}
......@@ -9,8 +9,10 @@
Set Mesort Password
@endcomponent
Thanks,
{{ config('app.name') }} Team
@endcomponent
Thanks,
{{ config('app.name') }} Team
@endcomponent
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment