1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-11-23 19:32:29 +01:00

Added User managment. Fixes #5

This commit is contained in:
Dan Brown 2015-08-08 20:05:30 +01:00
parent 588364a202
commit fc50a1400d
13 changed files with 298 additions and 3 deletions

View File

@ -0,0 +1,132 @@
<?php
namespace Oxbow\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Oxbow\Http\Requests;
use Oxbow\Http\Controllers\Controller;
use Oxbow\User;
class UserController extends Controller
{
protected $user;
/**
* UserController constructor.
* @param $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Display a listing of the users.
*
* @return Response
*/
public function index()
{
$users = $this->user->all();
return view('users/index', ['users'=> $users]);
}
/**
* Show the form for creating a new user.
*
* @return Response
*/
public function create()
{
return view('users/create');
}
/**
* Store a newly created user in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'password' => 'required|min:5',
'password-confirm' => 'required|same:password'
]);
$user = $this->user->fill($request->all());
$user->password = Hash::make($request->get('password'));
$user->save();
return redirect('/users');
}
/**
* Show the form for editing the specified user.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$user = $this->user->findOrFail($id);
return view('users/edit', ['user' => $user]);
}
/**
* Update the specified user in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'password' => 'min:5',
'password-confirm' => 'same:password'
]);
$user = $this->user->findOrFail($id);
$user->fill($request->all());
if($request->has('password') && $request->get('password') != '') {
$password = $request->get('password');
$user->password = Hash::make($password);
}
$user->save();
return redirect('/users');
}
/**
* Show the user delete page.
* @param $id
* @return \Illuminate\View\View
*/
public function delete($id)
{
$user = $this->user->findOrFail($id);
return view('users/delete', ['user' => $user]);
}
/**
* Remove the specified user from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$user = $this->user->findOrFail($id);
$user->delete();
return redirect('/users');
}
}

View File

@ -17,8 +17,7 @@ class Authenticate
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
* @param Guard $auth
*/
public function __construct(Guard $auth)
{

View File

@ -50,11 +50,24 @@ Route::group(['middleware' => 'auth'], function() {
Route::post('/upload/image', 'ImageController@upload');
// Users
Route::get('/users', 'UserController@index');
Route::get('/users/create', 'UserController@create');
Route::get('/users/{id}/delete', 'UserController@delete');
Route::post('/users/create', 'UserController@store');
Route::get('/users/{id}', 'UserController@edit');
Route::put('/users/{id}', 'UserController@update');
Route::delete('/users/{id}', 'UserController@destroy');
// Image routes
Route::get('/images/all', 'ImageController@getAll');
Route::get('/images/all/{page}', 'ImageController@getAll');
Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
// Links
Route::get('/link/{id}', 'PageController@redirectFromLink');
// Search
Route::get('/pages/search/all', 'PageController@searchAll');
Route::get('/', function () {

View File

@ -43,6 +43,9 @@ $button-border-radius: 3px;
&.secondary {
@include generate-button-colors(#EEE, $secondary);
}
&.muted {
@include generate-button-colors(#EEE, #888);
}
}
.button-group {

View File

@ -0,0 +1,18 @@
table.table {
width: 100%;
tr {
border-bottom: 1px solid #DDD;
}
th, td {
text-align: left;
border: none;
padding: $-xs $-xs;
}
th {
font-weight: bold;
}
tr:hover {
background-color: #EEE;
}
}

View File

@ -7,6 +7,7 @@
@import "blocks";
@import "buttons";
@import "forms";
@import "tables";
@import "tinymce";
header {

View File

@ -46,6 +46,7 @@
</div>
<ul class="menu">
<li><a href="/books"><i class="zmdi zmdi-book"></i>Books</a></li>
<li><a href="/users"><i class="zmdi zmdi-accounts"></i>Users</a></li>
<li><a href="/logout"><i class="zmdi zmdi-run zmdi-hc-flip-horizontal"></i>Logout</a></li>
</ul>
@if(isset($book) && !isset($books))

View File

@ -1,7 +1,7 @@
<input type="password" id="{{ $name }}" name="{{ $name }}"
@if($errors->has($name)) class="neg" @endif
@if(isset($placeholder)) placeholder="{{$placeholder}}" @endif
@if(isset($model) || old($name)) value="{{ old($name) ? old($name) : $model->$name}}" @endif>
@if(old($name)) value="{{ old($name)}}" @endif>
@if($errors->has($name))
<div class="text-neg text-small">{{ $errors->first($name) }}</div>
@endif

View File

@ -0,0 +1,15 @@
@extends('base')
@section('content')
<div class="page-content">
<h1>Create User</h1>
<form action="/users/create" method="post">
{!! csrf_field() !!}
@include('users/form')
</form>
</div>
@stop

View File

@ -0,0 +1,22 @@
@extends('base')
@section('content')
<div class="page-content">
<h1>Delete User</h1>
<p>This will fully delete this user with the name '<span class="text-neg">{{$user->name}}</span>' from the system.</p>
<p class="text-neg">Are you sure you want to delete this user?</p>
<form action="/users/{{$user->id}}" method="POST">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="DELETE">
<a href="/user/{{$user->id}}" class="button muted">Cancel</a>
<button type="submit" class="button neg">Confirm</button>
</form>
</div>
@stop
@section('bottom')
@include('pages/image-manager')
@stop

View File

@ -0,0 +1,25 @@
@extends('base')
@section('content')
<div class="row faded-small">
<div class="col-md-6"></div>
<div class="col-md-6 faded">
<div class="action-buttons">
<a href="/users/{{$user->id}}/delete" class="text-neg"><i class="zmdi zmdi-delete"></i>Delete User</a>
</div>
</div>
</div>
<div class="page-content">
<h1>Edit User</h1>
<form action="/users/{{$user->id}}" method="post">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="put">
@include('users/form', ['model' => $user])
</form>
</div>
@stop

View File

@ -0,0 +1,33 @@
<div class="form-group">
<label for="name">Name</label>
@include('form/text', ['name' => 'name'])
</div>
<div class="form-group">
<label for="email">Email</label>
@include('form/text', ['name' => 'email'])
</div>
@if(isset($model))
<div class="form-group">
<span class="text-muted">
Only fill the below if you would like <br>to change your password:
</span>
</div>
@endif
<div class="form-group">
<label for="password">Password</label>
@include('form/password', ['name' => 'password'])
</div>
<div class="form-group">
<label for="password-confirm">Confirm Password</label>
@include('form/password', ['name' => 'password-confirm'])
</div>
<div class="form-group">
<a href="/users" class="button muted">Cancel</a>
<button class="button pos" type="submit">Save</button>
</div>

View File

@ -0,0 +1,33 @@
@extends('base')
@section('content')
<div class="row faded-small">
<div class="col-md-6"></div>
<div class="col-md-6 faded">
<div class="action-buttons">
<a href="/users/create" class="text-pos"><i class="zmdi zmdi-account-add"></i>New User</a>
</div>
</div>
</div>
<div class="page-content">
<h1>Users</h1>
<table class="table">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
@foreach($users as $user)
<tr>
<td><a href="/users/{{$user->id}}">{{$user->name}}</a></td>
<td>{{$user->email}}</td>
</tr>
@endforeach
</table>
</div>
@stop