Skip to content

Commit

Permalink
Add invites page
Browse files Browse the repository at this point in the history
  • Loading branch information
Earl0fPudding committed Jul 27, 2019
1 parent 658f0c3 commit 9cf0f34
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
TIMEZONE=Europe/Vienna

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
Expand Down
36 changes: 35 additions & 1 deletion app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Admin;
use Hash;
use App\Alias;
use App\Invite;

class AdminController extends Controller
{
Expand Down Expand Up @@ -46,7 +47,9 @@ public function showAliases(Request $request){
}

public function showInvites(Request $request){
return view('showinvites');
$invites = Invite::with('domain')->get();
$domains = Domain::all();
return view('showinvites', [ 'invites' => $invites, 'domains' => $domains ]);
}

public function changePassword(Request $request){
Expand Down Expand Up @@ -165,4 +168,35 @@ public function deleteAlias(Request $request){

return redirect(route('Admin.showAliases'));
}

// --- INVITE ---

public function addInvite(Request $request){
$invite = new Invite();
do {
$invite->token = str_replace('.', '0', str_replace('/', '0', substr(Hash::make('Lelouch'), 7, -3)));
} while(Invite::where('token', $invite->token)->count()>0);
if(isset($request->name_preset)){
$invite->name_preset = $request->name_preset;
}
$invite->termination_date = $request->termination_date.' '.$request->termiantion_time;
$invite->domain_id = $request->domain_id;
$invite->save();

return redirect(route('Admin.showInvites'));
}

public function updateInvite(Request $request){
$invite = Invite::findOrFail($request->id);
// not needed yet
$invite->save();

return redirect(route('Admin.showInvites'));
}

public function deleteInvite(Request $request){
Invite::destroy($request->id);

return redirect(route('Admin.showInvites'));
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
|
*/

'timezone' => 'UTC',
'timezone' => env('TIMEZONE', 'UTC'),

/*
|--------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions resources/views/showaliases.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@
</div>
<div class="row">
<div class="input-field col m12">
<select name="user_id">
<option value="" selected disabled>Choose a domain</option>
<select name="user_id" id="user_id">
<option value="" selected disabled>Choose a mail address</option>
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->username.'@'.$user->domain->name }}</option>
@endforeach
</select>
<label for="user_id">Destination address</label>
</div>
</div>
</div>
Expand Down
118 changes: 118 additions & 0 deletions resources/views/showinvites.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<title>MailMan - Invites</title>
@include('headdata')
</head>
<body>
@include('cookieConsent::index')
@include('navbar')
<main>
<div class="container">
<div class="row">
<div class="col m10">
<h2>Invites {{ date('Y-m-d H:i:s') }}</h2>
</div>
<div class="col m2">
<a class="waves-effect waves-light modal-trigger add-button" href="#create-modal"><ion-icon size="large" name="add-circle"></ion-icon></a>
</div>
</div>
<div class="row">
<div class="col m12">
<table class="striped">
<thead>
<tr>
<th>Invite link</th>
<th>Name preset</th>
<th>Domain</th>
<th>Date of termination</th>
<th>Options</th>
</tr>
</thead>
<tbody>
@foreach($invites as $invite)
<tr>
<td><a href="{{ route('Login.processInvite', [ 'token' => $invite->token ]) }}">Link</a></td>
<td> @if($invite->name_preset === NULL) - @else {{ $invite->name_preset }} @endif </td>
<td>{{ $invite->domain->name }}</td>
<td>{{ $invite->termination_date }} <!-- @if(strtotime($invite->terminaiton_date)>strtotime(date('Y-m-d H:i:s'))) <span class="green-text">Active</span> @else <span class="red-text">Expired</span> @endif --></td>
<td>
<a href="{{route('Admin.deleteInvite', ['id' => $invite->id])}}"><button type="button" class="btn-flat">Delete</button></a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</main>
@include('footer')

<div id="create-modal" class="modal">
<form method="post" action="{{route('Admin.addInvite')}}">
<div class="modal-content">
<h4>Add a new invite</h4>
@csrf
<div class="container">
<div class="row">
<div class="input-field col m12">
<select id="d_id" name="domain_id">
<option value="" disabled selected>Choose a domain</option>
@foreach($domains as $domain)
<option value="{{ $domain->id }}">{{ $domain->name }}</option>
@endforeach
</select>
<label for="d_id">Domain</label>
</div>
</div>
<div class="row">
<div class="input-field col m12">
<input name="name_preset" id="p_id" type="text" class="validate">
<label for="p_id">Name preset (optional)</label>
</div>
</div>
<div class="row">
<div class="input-field col m6">
<input type="text" value="{{ date('Y-m-d') }}" class="datepicker" name="termination_date" id="td_id" required>
<label for="td_id">Date of termination</label>
</div>
<div class="input-field col m6">
<input type="text" value="" class="timepicker" name="termiantion_time" id="tt_id" required>
<label for="tt_id">Time of termination</label>
</div>
</div>
</div>
</div>
<div class="modal-footer" style="text-align:center;">
<button type="submit" href="#!" class="modal-close waves-effect waves-light btn blue darken-2">Add</button>
</div>
</form>
</div>

<script>
$(document).ready(function(){
$('.modal').modal();
$('select').formSelect();
$('.datepicker').datepicker({
monthsFull: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
weekdays: [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
selectMonths: true,
selectYears: 15,
today: 'Today',
clear: 'Clear',
close: 'Ok',
closeOnSelect: false,
format: 'yyyy-mm-dd',
firstDay: 1
});
$('.timepicker').timepicker({
twelveHour: false
});
});
</script>
</body>
</html>

0 comments on commit 9cf0f34

Please sign in to comment.