131 lines
No EOL
4.3 KiB
PHP
Executable file
131 lines
No EOL
4.3 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Mail\MailContact;
|
|
use App\Mail\MailVerifyAccount;
|
|
use App\Models\Homeparty;
|
|
use App\Models\HomepartyUser;
|
|
use App\Repositories\UserRepository;
|
|
use App\Services\UserService;
|
|
use App\User;
|
|
use GuzzleHttp\Client;
|
|
use Request;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use App\Services\Util;
|
|
use Validator;
|
|
|
|
|
|
class HomepartyController extends Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
|
|
}
|
|
public function detail($token = null, $gid = null)
|
|
{
|
|
if(!$token){
|
|
abort(404);
|
|
}
|
|
|
|
$homeparty = Homeparty::where('token', $token)->where('token_active', true)->first();
|
|
if(!$homeparty){
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
}
|
|
$homeparty_user = null;
|
|
if($gid){
|
|
if($gid === 'new'){
|
|
$homeparty_user = new HomepartyUser();
|
|
$homeparty_user->same_as_billing = true;
|
|
$homeparty_user->billing_country_id = $homeparty->country_id;
|
|
$homeparty_user->shipping_country_id = $homeparty->country_id;
|
|
|
|
}else{
|
|
//no edit
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
|
|
$homeparty_user = HomepartyUser::find($gid);
|
|
if(!$homeparty_user || $homeparty_user->homeparty_id !== $homeparty->id){
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
}
|
|
}
|
|
}
|
|
$data = [
|
|
'homeparty' => $homeparty,
|
|
'homeparty_user' => $homeparty_user,
|
|
'homeparty_host' => $homeparty->homeparty_host,
|
|
'mivita_member' => $homeparty->auth_user
|
|
];
|
|
return view('user.homeparty.self_guest_detail', $data);
|
|
}
|
|
|
|
|
|
public function detailStore($token = null, $gid = null)
|
|
{
|
|
if(!$token){
|
|
abort(404);
|
|
}
|
|
$homeparty = Homeparty::where('token', $token)->where('token_active', true)->first();
|
|
if(!$homeparty){
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
}
|
|
|
|
$rules = array(
|
|
'billing_salutation' => 'required',
|
|
'billing_firstname' => 'required',
|
|
'billing_lastname' => 'required',
|
|
'billing_address' => 'required',
|
|
'billing_zipcode' => 'required',
|
|
'billing_city' => 'required',
|
|
'billing_country_id' => 'required',
|
|
'checkbox_datenverarbeitung' => 'required',
|
|
'checkbox_daten_completely' => 'required'
|
|
);
|
|
|
|
if (!Request::get('same_as_billing')) {
|
|
$rules = array_merge($rules, [
|
|
'shipping_firstname' => 'required',
|
|
'shipping_lastname' => 'required',
|
|
'shipping_address' => 'required',
|
|
'shipping_zipcode' => 'required',
|
|
'shipping_city' => 'required',
|
|
'shipping_salutation' => 'required',
|
|
'shipping_country_id' => 'required'
|
|
]);
|
|
}
|
|
|
|
$validator = Validator::make(Request::all(), $rules);
|
|
if ($validator->fails()) {
|
|
return back()->withErrors($validator)->withInput(Request::all());
|
|
}
|
|
|
|
if($gid === null){
|
|
$homeparty_user = HomepartyUser::create([
|
|
'homeparty_id' => $homeparty->id,
|
|
'auth_user_id' => $homeparty->auth_user_id,
|
|
'is_host' => false,
|
|
]);
|
|
}else{
|
|
//no edit
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
$homeparty_user = HomepartyUser::find($gid);
|
|
if(!$homeparty_user || $homeparty_user->homeparty_id !== $homeparty->id){
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
}
|
|
}
|
|
|
|
if(!$homeparty_user){
|
|
abort(403, __('msg.link_for_homeparty_not_found'));
|
|
}
|
|
|
|
$data = Request::all();
|
|
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
|
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
|
$homeparty_user->fill($data)->save();
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('homeparty', [$token]));
|
|
}
|
|
} |