Skip to content

Commit

Permalink
Merge pull request #44 from civictechro/feature/DSU-audits
Browse files Browse the repository at this point in the history
Audits
  • Loading branch information
tudor-rusu authored Mar 24, 2018
2 parents 2410f48 + 9636b4e commit 0f2fbcd
Show file tree
Hide file tree
Showing 12 changed files with 813 additions and 6 deletions.
15 changes: 15 additions & 0 deletions api-man/app/Audit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Audit extends Model
{
/**
* Get the user that owns the audit log.
*/
public function user() {
return $this -> belongsTo(User::class);
}
}
8 changes: 4 additions & 4 deletions api-man/app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'nume' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'parola' => 'required|string|min:6|confirmed',
]);
}

Expand All @@ -63,9 +63,9 @@ protected function validator(array $data)
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'nume' => $data['nume'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'parola' => bcrypt($data['parola']),
]);
}
}
18 changes: 18 additions & 0 deletions api-man/app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Str;

class ResetPasswordController extends Controller
{
Expand Down Expand Up @@ -36,4 +37,21 @@ public function __construct()
{
$this->middleware('guest');
}

/**
* override Reset the given user's password.
*
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
* @param string $password
* @return void
*/
protected function resetPassword($user, $password)
{
$user->forceFill([
'parola' => bcrypt($password),
'remember_token' => Str::random(60),
])->save();

$this->guard()->login($user);
}
}
22 changes: 20 additions & 2 deletions api-man/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class User extends \TCG\Voyager\Models\User
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'nume', 'prenume', 'email', 'telefon_s', 'telefon_p', 'adresa', 'cod_postal', 'parola',
];

/**
Expand All @@ -25,9 +25,19 @@ class User extends \TCG\Voyager\Models\User
* @var array
*/
protected $hidden = [
'password', 'remember_token',
'parola', 'remember_token',
];

/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->parola;
}

/**
* Send the password reset notification.
*
Expand All @@ -38,4 +48,12 @@ public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}

/**
* Get the audit logs that belongs to user.
*/
public function audits()
{
return $this->hasMany(Audit::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class RenameColumnsToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->renameColumn('name', 'nume');
$table->renameColumn('password', 'parola');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->renameColumn('nume', 'name');
$table->renameColumn('parola', 'password');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class AddFieldsToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('prenume')->nullable()->after('nume');
$table->string('telefon_s')->nullable()->after('parola');
$table->string('telefon_p')->nullable()->after('telefon_s');
$table->string('adresa')->nullable()->after('telefon_p');
$table->string('cod_postal')->nullable()->after('adresa');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('prenume');
$table->dropColumn('telefon_s');
$table->dropColumn('telefon_p');
$table->dropColumn('adresa');
$table->dropColumn('cod_postal');
});
}
}
118 changes: 118 additions & 0 deletions api-man/resources/views/users/browse.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
@extends('voyager::master')

@section('page_header')
<h1 class="page-title"><i class="{{ $dataType->icon }}"></i> {{ $dataType->display_name_plural }}
@if (Voyager::can('add_'.$dataType->name)) <a href="{{ route('voyager.'.$dataType->slug.'.create') }}" class="btn btn-success"> <i class="voyager-plus"></i> Add New </a> @endif </h1>
@stop

@section('content')
<div class="page-content container-fluid">
<div class="row">
<div class="col-md-12">
<div class="panel panel-bordered">
<div class="panel-body">
<table id="dataTable" class="table table-hover">
<thead>
<tr>
<th>Nume</th>
<th>Email</th>
<th>Telefon S</th>
<th>Telefon P</th>
<th>Adresa</th>
<th>Creat la</th>
<th>Dezactivat la</th>
<th>Avatar</th>
<th>Role</th>
<th class="actions">Actions</th>
</tr>
</thead>
<tbody>
@foreach($dataTypeContent as $data)
<tr>
<td>{{ucwords($data->prenume . '&nbsp;' . $data->nume)}}</td>
<td>{{$data->email}}</td>
<td>{{$data->telefon_s}}</td>
<td>{{$data->telefon_p}}</td>
<td>{{$data->adresa . ',&nbsp;' . $data->cod_postal}}</td>
<td>{{ \Carbon\Carbon::parse($data->created_at)->format('F jS, Y h:i A') }}</td>
<td>{{ \Carbon\Carbon::parse($data->deleted_at)->format('F jS, Y h:i A') }}</td>

<td><img src="@if( strpos($data->avatar, 'http://') === false && strpos($data->avatar, 'https://') === false){{ Voyager::image( $data->avatar ) }}@else{{ $data->avatar }}@endif" style="width:100px"></td>
<td>{{ $data->role ? $data->role->display_name : '' }}</td>
<td class="no-sort no-click"> @if (Voyager::can('delete_'.$dataType->name))
<div class="btn-sm btn-danger pull-right delete" data-id="{{ $data->id }}" id="delete-{{ $data->id }}">
<i class="voyager-trash"></i> Delete
</div> @endif
@if (Voyager::can('edit_'.$dataType->name)) <a href="{{ route('voyager.'.$dataType->slug.'.edit', $data->id) }}" class="btn-sm btn-primary pull-right edit"> <i class="voyager-edit"></i> Edit </a> @endif
@if (Voyager::can('read_'.$dataType->name)) <a href="{{ route('voyager.'.$dataType->slug.'.show', $data->id) }}" class="btn-sm btn-warning pull-right"> <i class="voyager-eye"></i> View </a> @endif </td>
</tr>
@endforeach
</tbody>
</table>
@if (isset($dataType->server_side) && $dataType->server_side)
<div class="pull-left">
<div role="status" class="show-res" aria-live="polite">
Showing {{ $dataTypeContent->firstItem() }} to {{ $dataTypeContent->lastItem() }} of {{ $dataTypeContent->total() }} entries
</div>
</div>
<div class="pull-right">
{{ $dataTypeContent->links() }}
</div>
@endif
</div>
</div>
</div>
</div>
</div>

<div class="modal modal-danger fade" tabindex="-1" id="delete_modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span
aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title"><i class="voyager-trash"></i> Are you sure you want to delete
this {{ $dataType->display_name_singular }}?</h4>
</div>
<div class="modal-footer">
<form action="{{ route('voyager.'.$dataType->slug.'.index') }}" id="delete_form" method="POST">
{{ method_field("DELETE") }}
{{ csrf_field() }}
<input type="submit" class="btn btn-danger pull-right delete-confirm"
value="Yes, Delete This {{ $dataType->display_name_singular }}">
</form>
<button type="button" class="btn btn-default pull-right" data-dismiss="modal">
Cancel
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
@stop

@section('javascript')
<!-- DataTables -->
<script>
@if (!$dataType->server_side)
$(document).ready(function () {
$('#dataTable').DataTable({ "order": [] });
});
@endif
$('td').on('click', '.delete', function (e) {
var form = $('#delete_form')[0];
form.action = parseActionUrl(form.action, $(this).data('id'));
$('#delete_modal').modal('show');
});
function parseActionUrl(action, id) {
return action.match(/\/[0-9]+$/)
? action.replace(/([0-9]+$)/, id)
: action + '/' + id;
}
</script>
@stop
Loading

0 comments on commit 0f2fbcd

Please sign in to comment.