Random password is now default when creating a user, also an option when editing. Mods part of master group go straight to tests when clicking show test

This commit is contained in:
mwalbeck 2016-11-03 16:19:16 +01:00
parent 4196b8df9e
commit 090da3469a
8 changed files with 51 additions and 22 deletions

View file

@ -34,6 +34,10 @@ class ModeratorController extends Controller
public function showGroups()
{
if (Auth::user()->group_id === 1) {
return redirect()->action('ModeratorController@showAllTests');
}
$groups = Group::find([1, Auth::user()->group_id]);
return view('admin.groups', compact("groups"));
}

View file

@ -45,7 +45,7 @@ class StoreUser extends FormRequest
Rule::unique('users')->ignore($user_id),
"max:255",
],
"password" => "required|min:8",
"password" => "sometimes|required|min:8",
"group_id" => "integer|exists:groups,id|min:1",
"enabled" => "required|boolean",
"access_level" => "required|integer|min:1|max:3|access_mod",

View file

@ -70,7 +70,7 @@ class User extends Authenticatable
public function resetPassword()
{
$this->password = $this->passwordHash($this->generatePassword(10));
$this->password = $this->passwordHash($this->generatePassword(12));
$this->update();
return true;
}
@ -100,10 +100,15 @@ class User extends Authenticatable
{
$this->name = $request["name"];
$this->email = trim($request["email"]);
$this->password = $this->passwordHash($request["password"]);
$this->enabled = $request["enabled"];
$this->access_level = $request["access_level"];
if (array_key_exists("password", $request)) {
$this->password = $this->passwordHash($request["password"]);
} else {
$this->password = $this->passwordHash($this->generatePassword(12));
}
if (Auth::user()->isModerator()) {
$this->group_id = Auth::user()->group_id;
}
@ -113,7 +118,6 @@ class User extends Authenticatable
}
$this->save();
return true;
}
/**
@ -127,16 +131,19 @@ class User extends Authenticatable
$this->email = trim($request["email"]);
$this->enabled = $request["enabled"];
if ($request["password"]) {
if (array_key_exists("password", $request)) {
$this->password = $this->passwordHash($request["password"]);
}
if ($request["reset-password"]) {
$this->password = $this->passwordHash($this->generatePassword(12));
}
if (Auth::user()->isAdministrator()) {
$this->access_level = $request["access_level"];
$this->group_id = $request["group_id"];
}
$this->update();
return true;
}

View file

@ -20,18 +20,26 @@ $(document).ready(function() {
});
$('.delete-modal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var delete_url = button.data('url'); // Extract info from data-* attributes
var delete_id = button.data('id'); // Extract info from data-* attributes
var modal = $(this);
var admin_path = modal.find('#modal-button-delete').attr("formaction");
modal.find('#modal-button-delete').attr("formaction", admin_path + delete_url + "/" + delete_id + "/delete");
var button = $(event.relatedTarget); // Button that triggered the modal
var delete_url = button.data('url'); // Extract info from data-* attributes
var delete_id = button.data('id'); // Extract info from data-* attributes
var modal = $(this);
var admin_path = modal.find('#modal-button-delete').attr("formaction");
modal.find('#modal-button-delete').attr("formaction", admin_path + delete_url + "/" + delete_id + "/delete");
})
$('.reset-password-modal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var reset_password_id = button.data('id'); // Extract info from data-* attributes
var modal = $(this);
var admin_path = modal.find('#modal-button-reset-password').attr("formaction");
modal.find('#modal-button-reset-password').attr("formaction", admin_path + "users/" + reset_password_id + "/reset-password");
var button = $(event.relatedTarget); // Button that triggered the modal
var reset_password_id = button.data('id'); // Extract info from data-* attributes
var modal = $(this);
var admin_path = modal.find('#modal-button-reset-password').attr("formaction");
modal.find('#modal-button-reset-password').attr("formaction", admin_path + "users/" + reset_password_id + "/reset-password");
})
$('#manual-password-check').click(function(){
if (this.checked) {
$("#manual-password-field").removeAttr("disabled");
} else {
$("#manual-password-field").attr("disabled", "disabled");
}
})

View file

@ -18,8 +18,14 @@
<input type="email" class="form-control" name="email" value="{{ $user->email }}" required maxlength="255">
</div>
<div class="form-group">
<div class="pull-right">
<label>Reset password</label>
<input id="reset-password-check" type="checkbox" name="reset_password">
<label>Manually change password</label>
<input id="manual-password-check" type="checkbox" name="type_password">
</div>
<label>Password</label>
<input type="password" class="form-control" name="password" required>
<input id="manual-password-field" type="password" class="form-control" name="password" disabled required>
</div>
<div class="form-group">
<label>Enabled</label>

View file

@ -18,8 +18,12 @@
<input type="email" class="form-control" name="email" required maxlength="255">
</div>
<div class="form-group">
<div class="pull-right">
<label>Manually type password</label>
<input id="manual-password-check" type="checkbox" name="type_password">
</div>
<label>Password</label>
<input type="password" class="form-control" name="password" required>
<input id="manual-password-field" type="password" class="form-control" name="password" disabled required>
</div>
<div class="form-group">
<label>Enabled</label>

View file

@ -21,10 +21,10 @@
<button type="button" class="btn btn-sm btn-danger pull-right" data-toggle="modal" data-target=".delete-modal" data-url="users" data-id="{{ $user->id }}">Delete</button>
@endcan
@can('update', $user)
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}/edit">Edit</button>
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}/edit">Edit</button>
@endcan
@can('resetPassword', $user)
<button type="button" class="btn btn-sm btn-default pull-right" data-toggle="modal" data-target=".reset-password-modal" data-id="{{ $user->id }}">Reset Password</button>
<button type="button" class="btn btn-sm btn-default pull-right" data-toggle="modal" data-target=".reset-password-modal" data-id="{{ $user->id }}">Reset Password</button>
@endcan
</form>
@endif

View file

@ -46,7 +46,7 @@ Route::group(['prefix' => 'mod', 'middleware' => 'is.mod'], function () {
Route::get('/', 'ModeratorController@index');
Route::get('/tests', 'ModeratorController@showGroups');
Route::get('/tests/all', 'ModeratorController@ShowAllTests');
Route::get('/tests/all', 'ModeratorController@showAllTests');
Route::get('/tests/group/{group}', 'ModeratorController@showGroupTests');
Route::get('/tests/new', 'AdministrativeTestController@newTest');
Route::post('/tests/new', 'AdministrativeTestController@addTest');