First Commit
This commit is contained in:
commit
0c9a118281
633 changed files with 76612 additions and 0 deletions
45
app/Http/Controllers/API/DraftController.php
Executable file
45
app/Http/Controllers/API/DraftController.php
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Draft;
|
||||
use App\Models\TravelProgram;
|
||||
use HTMLHelper;
|
||||
|
||||
|
||||
class DraftController extends Controller
|
||||
{
|
||||
public $successStatus = 200;
|
||||
|
||||
|
||||
public function draft($action)
|
||||
{
|
||||
if($action == "get_draft_list"){
|
||||
$drafts = Draft::where('active', true)->get()->sortByDesc("id");
|
||||
return response()->json(['success' => $drafts], $this->successStatus);
|
||||
}
|
||||
|
||||
if($action == "get_draft_list_for_table"){
|
||||
$ret = [];
|
||||
if(request('program_id') && request('program_id') > 0){
|
||||
$travel_program = TravelProgram::find(request('program_id'));
|
||||
if(count($travel_program->travel_program_drafts)){
|
||||
foreach ($travel_program->travel_program_drafts as $travel_program_draft){
|
||||
$key = $travel_program_draft->id;
|
||||
$ret[$key]['name'] = $travel_program_draft->draft->name;
|
||||
if($travel_program_draft->travel_class){
|
||||
$ret[$key]['travel_class'] = $travel_program_draft->travel_class->name;
|
||||
}else{
|
||||
$ret[$key]['travel_class'] = "alle Kategorien";
|
||||
}
|
||||
$ret[$key]['weekdays'] = HTMLHelper::getWeekdaysString($travel_program_draft->weekdays);
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json(['success' => $ret], $this->successStatus);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
79
app/Http/Controllers/API/UserController.php
Executable file
79
app/Http/Controllers/API/UserController.php
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Validator;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public $successStatus = 200;
|
||||
|
||||
/**
|
||||
* login api
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
|
||||
$user = Auth::user();
|
||||
if(!$user->isSuperAdmin()) {
|
||||
return response()->json(['error' => 'Unauthorised'], 401);
|
||||
}
|
||||
$success['token'] = $user->createToken('SternToursCRM')->accessToken;
|
||||
return response()->json(['success' => $success], $this->successStatus);
|
||||
} else {
|
||||
return response()->json(['error' => 'Unauthorised'], 401);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register api
|
||||
* api.mein.sterntours.de
|
||||
* 6m9j,v2GE8px<bt75w
|
||||
* info@mein.sterntours.de
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
/*public function register(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
'c_password' => 'required|same:password',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => $validator->errors()], 401);
|
||||
}
|
||||
$input = $request->all();
|
||||
$input['password'] = bcrypt($input['password']);
|
||||
$user = User::create($input);
|
||||
$success['token'] = $user->createToken('SternToursCRM')->accessToken;
|
||||
$success['name'] = $user->name;
|
||||
return response()->json(['success' => $success], $this->successStatus);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* details api
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function details()
|
||||
{
|
||||
$user = Auth::user();
|
||||
return response()->json(['success' => $user], $this->successStatus);
|
||||
}
|
||||
|
||||
public function draft($action)
|
||||
{
|
||||
|
||||
$user = Auth::user();
|
||||
return response()->json(['success' => $user], $this->successStatus);
|
||||
|
||||
}
|
||||
}
|
||||
85
app/Http/Controllers/AdminUserController.php
Executable file
85
app/Http/Controllers/AdminUserController.php
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Input;
|
||||
use Illuminate\Http\Request;
|
||||
use Validator;
|
||||
|
||||
|
||||
|
||||
class AdminUserController extends Controller
|
||||
{
|
||||
protected $userRepo;
|
||||
|
||||
public function __construct(UserRepository $userRepo)
|
||||
{
|
||||
$this->middleware('superadmin');
|
||||
$this->userRepo = $userRepo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
//'values' => User::where('admin', 0)->get(),
|
||||
'values' => User::where('confirmation_code_remider', '!=', 2)->get(),
|
||||
];
|
||||
return view('admin.users', $data);
|
||||
}
|
||||
|
||||
public function edit($user_id)
|
||||
{
|
||||
$user = User::findOrFail($user_id);
|
||||
/*if(!$user->account){
|
||||
$user->account = new Account();
|
||||
}
|
||||
*/
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return view('admin.user_edit', $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = Input::all();
|
||||
$user = User::findOrFail($data['id']);
|
||||
|
||||
$user->admin = $data['admin'];
|
||||
$user->confirmed = isset($data['confirmed']) ? true : false;
|
||||
$user->active = isset($data['active']) ? true : false;
|
||||
$user->save();
|
||||
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect('/admin/users');
|
||||
|
||||
}
|
||||
|
||||
public function deleteUser($user_id)
|
||||
{
|
||||
$user = User::findOrFail($user_id);
|
||||
$this->userRepo->deleteUser($user);
|
||||
|
||||
\Session()->flash('alert-success', "Kontakt gelöscht");
|
||||
return redirect('/admin/users');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
69
app/Http/Controllers/Auth/LoginController.php
Executable file
69
app/Http/Controllers/Auth/LoginController.php
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
$user->last_login = date('Y-m-d H:i:s');
|
||||
$user->save();
|
||||
}
|
||||
protected function handleUserWasAuthenticated(Request $request, $throttles)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//*
|
||||
//
|
||||
/* protected function validateLogin(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
$this->username() => 'required|exists:users,' . $this->username() . ',active,1',
|
||||
'password' => 'required',
|
||||
], [
|
||||
$this->username() . '.exists' => trans('validation.usernotactive'),
|
||||
]);
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
80
app/Http/Controllers/Auth/RegisterController.php
Executable file
80
app/Http/Controllers/Auth/RegisterController.php
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
//register off! - to login
|
||||
return redirect('login');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file
39
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
13
app/Http/Controllers/Controller.php
Executable file
13
app/Http/Controllers/Controller.php
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
67
app/Http/Controllers/CronController.php
Normal file
67
app/Http/Controllers/CronController.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\MailVerifyAccount;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
class CronController extends Controller
|
||||
{
|
||||
|
||||
|
||||
protected $userRepo;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(UserRepository $userRepo)
|
||||
{
|
||||
$this->userRepo = $userRepo;
|
||||
|
||||
// $this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->checkConfirmation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function checkConfirmation()
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$next = date('Y-m-d H:i:s', strtotime('+3 week'));
|
||||
|
||||
$users = User::where('confirmed', '=', 0)->where('confirmation_code_to', '<', $now)->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
//delete user
|
||||
if ($user->confirmation_code_remider == 1) {
|
||||
$this->userRepo->deleteUser($user);
|
||||
|
||||
}
|
||||
//send new remider
|
||||
if ($user->confirmation_code_remider == 0) {
|
||||
Mail::to($user->email)->send(new MailVerifyAccount($user->confirmation_code, $user));
|
||||
$user->confirmation_code_to = $next;
|
||||
$user->confirmation_code_remider = 1;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
die("okay");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
76
app/Http/Controllers/DataTableController.php
Normal file
76
app/Http/Controllers/DataTableController.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\HTMLHelper;
|
||||
use DataTables;
|
||||
use App\User;
|
||||
|
||||
class DataTableController extends Controller
|
||||
{
|
||||
public function datatable()
|
||||
{
|
||||
return view('datatable');
|
||||
}
|
||||
|
||||
/*public function getLeads()
|
||||
{
|
||||
|
||||
$query = User::where('deleted_at', '=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('first_name', function (User $user) {
|
||||
return $user->account ? $user->account->first_name : '';
|
||||
})
|
||||
->addColumn('last_name', function (User $user) {
|
||||
return $user->account ? $user->account->last_name : '';
|
||||
})
|
||||
->addColumn('action', function (User $user) {
|
||||
return '<a href="' . route('admin_lead_edit', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('confirmed', function (User $user) {
|
||||
return $user->confirmed ? '<span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
})
|
||||
->addColumn('active', function (User $user) {
|
||||
return $user->active ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
})
|
||||
->orderColumn('confirmed', 'confirmed $1')
|
||||
->orderColumn('active', 'active $1')
|
||||
->rawColumns(['action', 'confirmed', 'active'])
|
||||
->make(true);
|
||||
}*/
|
||||
|
||||
public function getUsers()
|
||||
{
|
||||
//confirmation_code_remider is delete 2
|
||||
$query = User::where('deleted_at', '=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('action_edit', function (User $user) {
|
||||
return '<a href="' . route('admin_user_edit', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('admin', function (User $user) {
|
||||
return '<a href="#" data-toggle="modal" data-target="#modals-default" data-id="'.$user->id.'" data-email="'.$user->email.'" data-admin="'.$user->admin.'" data-active="'.$user->active.'" data-confirmed="'.$user->confirmed.'">'.HTMLHelper::getRoleLabel($user->admin).'</a>';
|
||||
})
|
||||
->addColumn('confirmed', function (User $user) {
|
||||
return $user->confirmed ? '<span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
})
|
||||
->addColumn('active', function (User $user) {
|
||||
return $user->active ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
})
|
||||
->addColumn('action_delete', function (User $user) {
|
||||
return '<a href="' . route('admin_user_delete', [$user->id]) . '" class="btn icon-btn btn-sm btn-danger" onclick="return confirm(\''.__('Really delete entry?').'\');"><span class="far fa-trash"></span></a>';
|
||||
})
|
||||
->orderColumn('confirmed', 'confirmed $1')
|
||||
->orderColumn('active', 'active $1')
|
||||
->orderColumn('admin', 'active $1')
|
||||
->rawColumns(['action_edit', 'admin', 'confirmed', 'active', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**/
|
||||
289
app/Http/Controllers/DraftController.php
Executable file
289
app/Http/Controllers/DraftController.php
Executable file
|
|
@ -0,0 +1,289 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Draft;
|
||||
use App\Models\DraftItem;
|
||||
use App\Models\DraftType;
|
||||
use Input;
|
||||
|
||||
class DraftController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
||||
}
|
||||
|
||||
public function index($step = false)
|
||||
{
|
||||
$data = [
|
||||
'drafts' => Draft::all()->sortByDesc("id"),
|
||||
'draft_types' => DraftType::all()->sortByDesc("id"),
|
||||
'step' => $step
|
||||
];
|
||||
return view('drafts.index', $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
if($id == "new") {
|
||||
$draft = new Draft();
|
||||
$draft->active = true;
|
||||
$id = 'new';
|
||||
|
||||
}else{
|
||||
$draft = Draft::findOrFail($id);
|
||||
$id = $draft->id;
|
||||
}
|
||||
$data = [
|
||||
'draft' => $draft,
|
||||
'id' => $id,
|
||||
];
|
||||
return view('drafts.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
if($id == "new") {
|
||||
$draft = new Draft();
|
||||
}else{
|
||||
$draft = Draft::findOrFail($id);
|
||||
}
|
||||
|
||||
$draft->name = $data['name'];
|
||||
$draft->active = isset($data['active']) ? true : false;
|
||||
$draft->save();
|
||||
|
||||
$i = 1;
|
||||
if(isset($data['draft_item'])){
|
||||
foreach ($data['draft_item'] as $draft_item_id => $draft_item){
|
||||
if($data['action'] == 'saveAllFromOld'){
|
||||
$di = $draft->draft_items()->create([]);
|
||||
}else{
|
||||
$di = DraftItem::findOrFail($draft_item_id);
|
||||
}
|
||||
$di->draft_type_id = $draft_item['draft_type_id'];
|
||||
$di->days_start = $draft_item['days_start'];
|
||||
$di->days_duration = $draft_item['days_duration'];
|
||||
$di->service = $draft_item['service'];
|
||||
$di->price_adult = $draft_item['price_adult'];
|
||||
$di->adult = $draft_item['adult'];
|
||||
$di->price_children = $draft_item['price_children'];
|
||||
$di->children = $draft_item['children'];
|
||||
$di->in_pdf = isset($draft_item['in_pdf']) ? true : false;
|
||||
$di->pos = $i++;
|
||||
|
||||
$di->save();
|
||||
}
|
||||
}
|
||||
|
||||
if($data['action'] == 'addItem'){
|
||||
$draft->draft_items()->create(['pos' => $i]);
|
||||
}
|
||||
if(strpos($data['action'], 'up_') !== false) {
|
||||
$reId = intval(str_replace('up_', '', $data['action']));
|
||||
$d_from = DraftItem::findOrFail($reId);
|
||||
$d_to = $draft->findBeforeRelation($reId);
|
||||
if($d_to) {
|
||||
$t_pos = $d_from->pos;
|
||||
$d_from->pos = $d_to->pos;
|
||||
$d_to->pos = $t_pos;
|
||||
$d_from->save();
|
||||
$d_to->save();
|
||||
}
|
||||
}
|
||||
if(strpos($data['action'], 'down_') !== false) {
|
||||
$reId = intval(str_replace('down_', '', $data['action']));
|
||||
$d_from = DraftItem::findOrFail($reId);
|
||||
$d_to = $draft->findAfterRelation($reId);
|
||||
if($d_to) {
|
||||
$t_pos = $d_from->pos;
|
||||
$d_from->pos = $d_to->pos;
|
||||
$d_to->pos = $t_pos;
|
||||
$d_from->save();
|
||||
$d_to->save();
|
||||
}
|
||||
}
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('draft_detail', [$draft->id]));
|
||||
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$draft = Draft::findOrFail($id);
|
||||
|
||||
foreach ($draft->draft_items as $draft_item){
|
||||
$draft_item->delete();
|
||||
}
|
||||
$draft->delete();
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('drafts'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function itemDelete($id){
|
||||
$draft_item = DraftItem::findOrFail($id);
|
||||
$draft_id = $draft_item->draft_id;
|
||||
$draft_item->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
return redirect(route('draft_detail', [$draft_id]));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function typeUpdate(){
|
||||
|
||||
$data = Input::all();
|
||||
if($data['id'] == "new"){
|
||||
$draft_type = DraftType::create([
|
||||
'name' => $data['name'],
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
}else{
|
||||
$draft_type = DraftType::find($data['id']);
|
||||
$draft_type->name = $data['name'];
|
||||
$draft_type->active = isset($data['active']) ? true : false;
|
||||
$draft_type->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('drafts', ['type']));
|
||||
|
||||
}
|
||||
public function typeDelete($id){
|
||||
|
||||
if(DraftItem::where('draft_type_id', $id)->count()){
|
||||
\Session()->flash('alert-error', 'Eintrag wird verwendet');
|
||||
return redirect(route('drafts'));
|
||||
}
|
||||
$draft_type = DraftType::findOrFail($id);
|
||||
$draft_type->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
return redirect(route('drafts', ['type']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function loadOldAction(){
|
||||
$data = Input::all();
|
||||
$template = \App\Models\Sym\ArrangementTemplate::findOrFail($data['load_old']);
|
||||
|
||||
$draft = new Draft();
|
||||
$draft->active = true;
|
||||
$draft->name = $template->title;
|
||||
|
||||
$draft_items = [];
|
||||
foreach ($template->arrangements as $arrangement){
|
||||
$data_s = explode("\n", $arrangement->data_s);
|
||||
$service = "";
|
||||
$priceAdult = false;
|
||||
$adult = false;
|
||||
$priceChildren = false;
|
||||
$children = false;
|
||||
|
||||
foreach ($data_s as $ds){
|
||||
if(strpos($ds, 'Name:') !== false){
|
||||
$service .= str_replace('Name: ', '', $ds);
|
||||
$ds = "";
|
||||
}
|
||||
if(strpos($ds, 'Preis:') !== false){
|
||||
$p = floatval(str_replace('Preis: ', '', $ds));
|
||||
$priceAdult = number_format($p, 2, ',', '.');
|
||||
$ds = "";
|
||||
}
|
||||
if(strpos($ds, 'Teilnehmer:') !== false){
|
||||
$adult = intval(str_replace('Teilnehmer: ', '', $ds));
|
||||
$ds = "";
|
||||
}
|
||||
if(strpos($ds, 'KindPreis:') !== false){
|
||||
$p = floatval(str_replace('KindPreis: ', '', $ds));
|
||||
$priceChildren = number_format($p, 2, ',', '.');
|
||||
$ds = "";
|
||||
}
|
||||
if(strpos($ds, 'Kind:') !== false){
|
||||
$children = intval(str_replace('Kind: ', '', $ds));
|
||||
$ds = "";
|
||||
}
|
||||
if($ds != ""){
|
||||
$service .= $ds;
|
||||
}
|
||||
}
|
||||
$draft_items[] = array(
|
||||
'draft_type_id' => $arrangement->type_id,
|
||||
'in_pdf' => $arrangement->in_pdf,
|
||||
'service' => trim($service),
|
||||
'price_adult' => $priceAdult,
|
||||
'adult' => $adult,
|
||||
'price_children' => $priceChildren,
|
||||
'children' => $children,
|
||||
'days_start' => null,
|
||||
'days_duration' => null,
|
||||
);
|
||||
}
|
||||
$data = [
|
||||
'draft' => $draft,
|
||||
'draft_items' => $draft_items,
|
||||
'id' => 'new',
|
||||
];
|
||||
return view('drafts.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function loadNew(){
|
||||
$data = [
|
||||
'drafts' => Draft::all()->sortByDesc("id"),
|
||||
];
|
||||
return view('drafts.load_new', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function loadNewAction(){
|
||||
$data = Input::all();
|
||||
$d = Draft::findOrFail($data['load_new']);
|
||||
$draft = new Draft();
|
||||
$draft->active = true;
|
||||
$draft->name = $d->name;
|
||||
|
||||
$draft_items = [];
|
||||
foreach ($d->draft_items as $di){
|
||||
$draft_items[] = array(
|
||||
'draft_type_id' => $di->draft_type_id,
|
||||
'in_pdf' => $di->in_pdf,
|
||||
'service' => $di->service,
|
||||
'price_adult' => $di->price_adult,
|
||||
'adult' => $di->adult,
|
||||
'price_children' => $di->price_children,
|
||||
'children' => $di->children,
|
||||
'days_start' => $di->days_start,
|
||||
'days_duration' => $di->days_duration,
|
||||
);
|
||||
}
|
||||
$data = [
|
||||
'draft' => $draft,
|
||||
'draft_items' => $draft_items,
|
||||
'id' => 'new',
|
||||
];
|
||||
return view('drafts.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function loadOld(){
|
||||
$data = [
|
||||
'templates' => \App\Models\Sym\ArrangementTemplate::all(),
|
||||
];
|
||||
return view('drafts.load_old', $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
120
app/Http/Controllers/HomeController.php
Executable file
120
app/Http/Controllers/HomeController.php
Executable file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\SfGuardUser;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Request;
|
||||
use Input;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if(!Auth::check()){
|
||||
return redirect('login');
|
||||
}
|
||||
return redirect('home');
|
||||
|
||||
}
|
||||
|
||||
//login
|
||||
public function show()
|
||||
{
|
||||
if(!Auth::check()){
|
||||
return redirect('login');
|
||||
}
|
||||
$data = [
|
||||
'user' => Auth::user(),
|
||||
];
|
||||
return view('home', $data);
|
||||
}
|
||||
|
||||
|
||||
public function loadingModal(){
|
||||
|
||||
$data = Input::get('data');
|
||||
$target = Input::get('target');
|
||||
|
||||
$response = "";
|
||||
if($data == "data_protection"){
|
||||
$response = view('legal.data_protect_de')->render();
|
||||
}
|
||||
if($data == "imprint"){
|
||||
$response = view('legal.imprint_de')->render();
|
||||
}
|
||||
if(Request::ajax()) {
|
||||
return response()->json(['response' => $response, 'target'=>$target]);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function checkLogin($identify, $token)
|
||||
{
|
||||
if($identify){
|
||||
//user find by $identify
|
||||
$user = User::where('identify', '=', $identify)->first();
|
||||
if(!$user){
|
||||
return abort(404);
|
||||
}
|
||||
//user - check für from $sf_guard_user - old system
|
||||
$sf_guard_user = SfGuardUser::where('identify', '=', $identify)->first();
|
||||
if(!$sf_guard_user){
|
||||
return abort(404);
|
||||
}
|
||||
if($user->id != $sf_guard_user->user_id){
|
||||
return abort(404);
|
||||
|
||||
}
|
||||
if($sf_guard_user->token != $token){
|
||||
return abort(404);
|
||||
}
|
||||
$time = Carbon::parse($sf_guard_user->token_at);
|
||||
$now = Carbon::now();
|
||||
$duration = $time->diffInSeconds($now);
|
||||
|
||||
if($duration > 3){
|
||||
return abort(404);
|
||||
}
|
||||
$sf_guard_user->token = null;
|
||||
$sf_guard_user->token_at = null;
|
||||
$sf_guard_user->save();
|
||||
if(!Auth::check()){
|
||||
$user->last_login = now();
|
||||
$user->save();
|
||||
Auth::login($user);
|
||||
}
|
||||
if(Auth::check()){
|
||||
return redirect(route('drafts'));
|
||||
}
|
||||
}
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
public function legalDataProtected()
|
||||
{
|
||||
return view('legal.data_protected');
|
||||
}
|
||||
|
||||
public function legalImprint()
|
||||
{
|
||||
return view('legal.imprint');
|
||||
}
|
||||
}
|
||||
179
app/Http/Controllers/TranslationController.php
Executable file
179
app/Http/Controllers/TranslationController.php
Executable file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use File;
|
||||
use Input;
|
||||
|
||||
class TranslationController extends Controller
|
||||
{
|
||||
|
||||
|
||||
protected $languagesPath;
|
||||
protected $directory_separator;
|
||||
protected $from;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->directory_separator = DIRECTORY_SEPARATOR;
|
||||
$this->languagesPath = App::langPath();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return redirect('admin/translate/edit/de');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $language
|
||||
* @param string $from
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function edit($language, $from = 'en')
|
||||
{
|
||||
$localisations = array_keys(config('localization.supportedLocales'));
|
||||
$files = $this->json_files($localisations);
|
||||
$translations = $this->translationsJson($language, $from);
|
||||
$show = "all";
|
||||
return view('translation.index', compact('files','translations', 'language', 'from', 'show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $lang
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function update($language)
|
||||
{
|
||||
|
||||
$path = $this->resourcePath($this->languagesPath);
|
||||
$file = $path.$language.".json";
|
||||
$data = Input::all();
|
||||
$this->backup($path, $language.".json");
|
||||
unset($data['_token']);
|
||||
|
||||
$ret = [];
|
||||
//file make keys
|
||||
$source = json_decode(File::get($path."de.json"));
|
||||
foreach ($source as $key => $v){
|
||||
$skey = $this->sanitize($key);
|
||||
if(!empty($data[$skey])) {
|
||||
$ret[$key] = $data[$skey];
|
||||
}
|
||||
}
|
||||
$jsonData = json_encode($ret, TRUE);
|
||||
file_put_contents($file, $jsonData);
|
||||
return redirect()
|
||||
->route('admin_translate_edit', [$language])
|
||||
->with('message', 'Translation added successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $langs
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function json_files($localisations){
|
||||
$path = $this->resourcePath($this->languagesPath);
|
||||
$content = array();
|
||||
foreach ($localisations as $local){
|
||||
$file = File::get($path.$local.".json");
|
||||
if($file){
|
||||
$content[$local] = array('path'=>$path.$local.".json", 'content'=>json_encode($file));
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $language
|
||||
* @param $from
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function translationsJson($language, $from)
|
||||
{
|
||||
$path = $this->resourcePath($this->languagesPath);
|
||||
$file = array();
|
||||
$file['keys'] = (array) json_decode(File::get($path."de.json"));
|
||||
$file['keys'] = $this->sanitizeKey($file['keys']);
|
||||
$file['from'] = (array) json_decode(File::get($path.$from.".json"));
|
||||
$file['from'] = $this->sanitizeKey($file['from']);
|
||||
$file['dest'] = (array) json_decode(File::get($path.$language.".json"));
|
||||
$file['dest'] = $this->sanitizeKey($file['dest']);
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
private function backup($path, $file)
|
||||
{
|
||||
|
||||
if (!File::exists(storage_path('language/'))) {
|
||||
File::makeDirectory(storage_path('language/'), 0755, true);
|
||||
}
|
||||
|
||||
return File::copy($path.$file, storage_path('language/'.time()."-".$file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
protected function resourcePath($path)
|
||||
{
|
||||
return "{$path}{$this->directory_separator}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $arr
|
||||
* @return mixed
|
||||
*/
|
||||
protected function sanitizeKey($arr){
|
||||
foreach ($arr as $key => $val){
|
||||
unset($arr[$key]);
|
||||
$arr[$this->sanitize($key)] = $val;
|
||||
}
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @param bool $force_lowercase
|
||||
* @param bool $anal
|
||||
* @return mixed|null|string|string[]
|
||||
*/
|
||||
protected function sanitize($string, $force_lowercase = true, $anal = false)
|
||||
{
|
||||
$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
|
||||
"}", "\\", "|", ";", ":", "\"", "'", "‘", "’", "“", "”", "–", "—",
|
||||
"—", "–", ",", "<", ".", ">", "/", "?");
|
||||
$clean = trim(str_replace($strip, "", strip_tags($string)));
|
||||
$clean = preg_replace('/\s+/', "_", $clean);
|
||||
$clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ;
|
||||
|
||||
return ($force_lowercase) ?
|
||||
(function_exists('mb_strtolower')) ?
|
||||
mb_strtolower($clean, 'UTF-8') :
|
||||
strtolower($clean) :
|
||||
$clean;
|
||||
}
|
||||
|
||||
}
|
||||
107
app/Http/Controllers/TravelProgramController.php
Executable file
107
app/Http/Controllers/TravelProgramController.php
Executable file
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\TravelClass;
|
||||
use App\Models\TravelProgram;
|
||||
use App\Models\TravelProgramDraft;
|
||||
use App\Repositories\TravelProgramRepository;
|
||||
use Input;
|
||||
|
||||
class TravelProgramController extends Controller
|
||||
{
|
||||
|
||||
protected $travelProgramRepo;
|
||||
|
||||
public function __construct(TravelProgramRepository $travelProgramRepo)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->travelProgramRepo = $travelProgramRepo;
|
||||
}
|
||||
|
||||
public function index($step = false)
|
||||
{
|
||||
$data = [
|
||||
'travel_programs' => TravelProgram::all()->sortByDesc("id"),
|
||||
'step' => $step
|
||||
];
|
||||
return view('travel.program.index', $data);
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
if($id == "new") {
|
||||
$program = new TravelProgram();
|
||||
$id = 'new';
|
||||
|
||||
}else{
|
||||
$program = TravelProgram::findOrFail($id);
|
||||
$id = $program->id;
|
||||
}
|
||||
$data = [
|
||||
'program' => $program,
|
||||
'id' => $id,
|
||||
];
|
||||
return view('travel.program.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
$program = $this->travelProgramRepo->update($data);
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('travel_program_detail', [$program->id]));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* PROGRAM CLASSES
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function classUpdate(){
|
||||
$data = Input::all();
|
||||
$this->travelProgramRepo->updateClass($data);
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('travel_program_detail', [$data['program_id']]));
|
||||
}
|
||||
public function classDelete($id){
|
||||
$travel_class = TravelClass::findOrFail($id);
|
||||
$pId = $travel_class->program_id;
|
||||
if(count($travel_class->travel_program_drafts)){
|
||||
\Session()->flash('alert-error', 'Eintrag wird bei den Vorlagen verwendet');
|
||||
return redirect(route('travel_program_detail', [$pId]));
|
||||
}
|
||||
$travel_class->delete();
|
||||
\Session()->flash('alert-success', 'Programm Kategorie gelöscht');
|
||||
return redirect(route('travel_program_detail', [$pId]));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* PROGRAM DRAFTS
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function draftUpdate(){
|
||||
$data = Input::all();
|
||||
$this->travelProgramRepo->updateDraft($data);
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('travel_program_detail', [$data['travel_program_id']]));
|
||||
}
|
||||
public function draftDelete($id){
|
||||
$travel_program_draft = TravelProgramDraft::findOrFail($id);
|
||||
$pId = $travel_program_draft->travel_program_id;
|
||||
$travel_program_draft->delete();
|
||||
\Session()->flash('alert-success', 'Programm Vorlage gelöscht');
|
||||
return redirect(route('travel_program_detail', [$pId]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
96
app/Http/Controllers/UserDataController.php
Executable file
96
app/Http/Controllers/UserDataController.php
Executable file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Repositories\UserRepository;
|
||||
use Auth;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
|
||||
class UserDataController extends Controller
|
||||
{
|
||||
|
||||
protected $userRepo;
|
||||
|
||||
public function __construct(UserRepository $userRepo)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->userRepo = $userRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function userEdit(){
|
||||
$user = Auth::user();
|
||||
|
||||
/*if(!$user->account){
|
||||
$user->account = new UserAccount();
|
||||
}*/
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return view('user.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function userEditStore(){
|
||||
|
||||
$user = Auth::user();
|
||||
/*if(!$user->account){
|
||||
$user->account = new UserAccount();
|
||||
}*/
|
||||
$rules = array(
|
||||
'salutation' => 'required',
|
||||
'last_name' => 'required|max:255',
|
||||
'country_id' => 'required|integer|min:1',
|
||||
'email' => 'required|string|email|max:255|exists:users,email',
|
||||
'email-confirm' => 'required|same:email',
|
||||
);
|
||||
|
||||
if(Input::get('company') == 1){
|
||||
$rules['company_name'] = 'required|max:255';
|
||||
$rules['company_country_id'] = 'required|integer|min:1';
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
// get the error messages from the validator
|
||||
$messages = $validator->messages();
|
||||
// redirect our user back to the form with the errors from the validator
|
||||
return view('user.edit', $data)->withErrors($validator);
|
||||
|
||||
} else {
|
||||
$this->userRepo->update(Input::all());
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect('/user/edit');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function userDataAcceptedForm(){
|
||||
$user = Auth::user();
|
||||
|
||||
if(Input::get('sender_accepted_infos') == "on"){
|
||||
$user->agreement = now();
|
||||
}else {
|
||||
$user->agreement = null;
|
||||
}
|
||||
|
||||
$user->save();
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
}
|
||||
73
app/Http/Controllers/UserDeleteController.php
Executable file
73
app/Http/Controllers/UserDeleteController.php
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Validator;
|
||||
use Input;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Repositories\UserRepository;
|
||||
|
||||
|
||||
|
||||
class UserDeleteController extends Controller
|
||||
{
|
||||
|
||||
|
||||
protected $userRepo;
|
||||
|
||||
/**
|
||||
* UserController constructor.
|
||||
* @param UserRepository $userRepo
|
||||
*/
|
||||
public function __construct(UserRepository $userRepo)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->userRepo = $userRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function deleteAccount(){
|
||||
return view('user.delete_account');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function deleteAccountAction(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$rules = array(
|
||||
'old_password' => 'required|old_password:' . Auth::user()->password,
|
||||
);
|
||||
|
||||
Validator::extend('old_password', function ($attribute, $value, $parameters, $validator) {
|
||||
|
||||
return Hash::check($value, current($parameters));
|
||||
|
||||
});
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
// get the error messages from the validator
|
||||
$messages = $validator->messages();
|
||||
// redirect our user back to the form with the errors from the validator
|
||||
return view('user.delete_account')->withErrors($validator);
|
||||
|
||||
}else{
|
||||
$this->userRepo->deleteUser($user);
|
||||
//make delete
|
||||
Auth::logout();
|
||||
\Session()->flash('alert-danger', __('account deleted'));
|
||||
return redirect(route('home'));
|
||||
}
|
||||
}
|
||||
}
|
||||
214
app/Http/Controllers/UserUpdateEmailController.php
Executable file
214
app/Http/Controllers/UserUpdateEmailController.php
Executable file
|
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Validator;
|
||||
use Input;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailActivateUser;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class UserUpdateEmailController extends Controller
|
||||
{
|
||||
|
||||
|
||||
protected $db;
|
||||
|
||||
protected $table = 'user_update_emails';
|
||||
|
||||
protected $resendAfter = 60; //1min
|
||||
|
||||
|
||||
public function __construct(Connection $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('user.update_email');
|
||||
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$rules = array(
|
||||
'email' => 'required|string|email|max:255|unique:users|confirmed|users_update_email:' . Auth::user()->id,
|
||||
//'email-confirm' => 'required|same:email',
|
||||
);
|
||||
|
||||
Validator::extend('users_update_email', function ($attribute, $value, $parameters, $validator) {
|
||||
if($this->db->table($this->table)->where('email', '=', $value)->where('user_id', '!=', $parameters[0])->count()){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
});
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
// redirect our user back to the form with the errors from the validator
|
||||
$messages = $validator->messages();
|
||||
|
||||
return view('user.update_email')->withErrors($validator);
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$this->sendActivationMail($user, $request->all());
|
||||
\Session()->flash('alert-success', __('We sent you an activation code. Check your email!'));
|
||||
return redirect(route('user_update_email'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* public function adminChangeMail($user_id)
|
||||
{
|
||||
if(!Auth::user()->isAdmin()){
|
||||
abort(404);
|
||||
}
|
||||
$data = [
|
||||
'user' => User::findOrFail($user_id),
|
||||
];
|
||||
return view('admin.change_email', $data);
|
||||
|
||||
}
|
||||
public function adminUpdateMail(Request $request, $user_id)
|
||||
{
|
||||
if(!Auth::user()->isAdmin()){
|
||||
abort(404);
|
||||
}
|
||||
$user = User::findOrFail($user_id);
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
|
||||
$rules = array(
|
||||
'email' => 'required|string|email|max:255|unique:users|confirmed|users_update_email:' . $user->id,
|
||||
//'email-confirm' => 'required|same:email',
|
||||
);
|
||||
|
||||
Validator::extend('users_update_email', function ($attribute, $value, $parameters, $validator) {
|
||||
if($this->db->table($this->table)->where('email', '=', $value)->where('user_id', '!=', $parameters[0])->count()){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
});
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
// redirect our user back to the form with the errors from the validator
|
||||
$messages = $validator->messages();
|
||||
|
||||
return view('admin.change_email', $data)->withErrors($validator);
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$this->sendActivationMail($user, $request->all());
|
||||
\Session()->flash('alert-success', __('An activation code was sent to the account by e-mail!'));
|
||||
return redirect(route('admin_lead_edit', [$user->id]));
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function activateMail($token)
|
||||
{
|
||||
|
||||
if ($updateEmail = $this->getUpdateEmailByToken($token)) {
|
||||
$user = User::findOrFail($updateEmail->user_id);
|
||||
if($user->id == $updateEmail->user_id){
|
||||
$user->fill([
|
||||
'email' => $updateEmail->email
|
||||
])->save();
|
||||
$this->deleteUpdateEmail($token);
|
||||
//Login!
|
||||
Auth::login($user);
|
||||
\Session()->flash('alert-success', __('Your e-mail has been changed.'));
|
||||
return redirect('/home');
|
||||
|
||||
}
|
||||
}
|
||||
return redirect('/home');
|
||||
abort(404);
|
||||
}
|
||||
|
||||
|
||||
public function sendActivationMail($user, array $data)
|
||||
{
|
||||
$token = $this->createActivation($user, $data);
|
||||
Mail::to($data['email'])->send(new MailActivateUser($token, $user));
|
||||
}
|
||||
|
||||
|
||||
protected function getToken()
|
||||
{
|
||||
return hash_hmac('sha256', str_random(40), config('app.key'));
|
||||
}
|
||||
|
||||
public function createActivation($user, array $data)
|
||||
{
|
||||
|
||||
$updateEmail = $this->getUpdateEmail($user);
|
||||
|
||||
if (!$updateEmail) {
|
||||
return $this->createToken($user, $data);
|
||||
}
|
||||
return $this->regenerateToken($user, $data);
|
||||
|
||||
}
|
||||
|
||||
private function regenerateToken($user, array $data)
|
||||
{
|
||||
|
||||
$token = $this->getToken();
|
||||
$this->db->table($this->table)->where('user_id', $user->id)->update([
|
||||
'email' => $data['email'],
|
||||
'token' => $token,
|
||||
'created_at' => new Carbon()
|
||||
]);
|
||||
return $token;
|
||||
}
|
||||
|
||||
private function createToken($user, array $data)
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$this->db->table($this->table)->insert([
|
||||
'user_id' => $user->id,
|
||||
'email' => $data['email'],
|
||||
'token' => $token,
|
||||
'created_at' => new Carbon()
|
||||
]);
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function getUpdateEmail($user)
|
||||
{
|
||||
return $this->db->table($this->table)->where('user_id', $user->id)->first();
|
||||
}
|
||||
|
||||
|
||||
public function getUpdateEmailByToken($token)
|
||||
{
|
||||
return $this->db->table($this->table)->where('token', $token)->first();
|
||||
}
|
||||
|
||||
public function deleteUpdateEmail($token)
|
||||
{
|
||||
$this->db->table($this->table)->where('token', $token)->delete();
|
||||
}
|
||||
}
|
||||
112
app/Http/Controllers/UserUpdatePasswordController.php
Executable file
112
app/Http/Controllers/UserUpdatePasswordController.php
Executable file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Validator;
|
||||
use Input;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class UserUpdatePasswordController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function updatePassword()
|
||||
{
|
||||
return view('user.update_password');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function updatePasswordStore(Request $request)
|
||||
{
|
||||
$rules = array(
|
||||
'old_password' => 'required|old_password:' . Auth::user()->password,
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
);
|
||||
|
||||
Validator::extend('old_password', function ($attribute, $value, $parameters, $validator) {
|
||||
|
||||
return Hash::check($value, current($parameters));
|
||||
|
||||
});
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
// get the error messages from the validator
|
||||
$messages = $validator->messages();
|
||||
// redirect our user back to the form with the errors from the validator
|
||||
return view('user.update_password')->withErrors($validator);
|
||||
|
||||
}else{
|
||||
$request->user()->fill([
|
||||
'password' => Hash::make($request->password)
|
||||
])->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('user_update_password'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function updatePasswordFirst(){
|
||||
if(!Auth::user()->isPasswort()){
|
||||
return view('user.update_password_first');
|
||||
}
|
||||
return redirect(route('user_update_password'));
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Update the password for the user.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function updatePasswordFirstStore(Request $request)
|
||||
{
|
||||
$rules = array(
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
);
|
||||
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
// get the error messages from the validator
|
||||
$messages = $validator->messages();
|
||||
// redirect our user back to the form with the errors from the validator
|
||||
return view('user.update_password_first')->withErrors($validator);
|
||||
|
||||
}else{
|
||||
$request->user()->fill([
|
||||
'password' => Hash::make($request->password)
|
||||
])->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect('/home');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue