Commit 77444972 authored by Nicolas Widart's avatar Nicolas Widart

Adding user edit and create methods

parent 73e8ad29
<?php namespace Modules\User\Http\Controllers\Admin;
use Cartalyst\Sentinel\Laravel\Facades\Activation;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\User\Http\Requests\CreateUserRequest;
use Modules\User\Http\Requests\UpdateUserRequest;
class UserController extends AdminBaseController
{
......@@ -44,11 +49,20 @@ class UserController extends AdminBaseController
/**
* Store a newly created resource in storage.
*
* @param CreateUserRequest $request
* @return Response
*/
public function store()
public function store(CreateUserRequest $request)
{
//
$user = $this->users->create($request->all());
$code = Activation::create($user);
Activation::complete($user, $code);
Flash::success('User created.');
return Redirect::route('dashboard.user.index');
}
/**
......@@ -59,7 +73,6 @@ class UserController extends AdminBaseController
*/
public function show($id)
{
return \View::make('collection.show');
}
/**
......@@ -81,11 +94,18 @@ class UserController extends AdminBaseController
* Update the specified resource in storage.
*
* @param int $id
* @param UpdateUserRequest $request
* @return Response
*/
public function update($id)
public function update($id, UpdateUserRequest $request)
{
//
$user = $this->users->createModel()->find($id);
$this->users->update($user, $request->all());
Flash::success('User updated.');
return Redirect::route('dashboard.user.index');
}
/**
......
......@@ -7,6 +7,10 @@ class CreateUserRequest extends FormRequest
public function rules()
{
return [
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required|unique:users|email',
'password' => 'required|min:3|confirmed',
];
}
......
<?php namespace Modules\User\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateUserRequest extends FormRequest
{
public function rules()
{
return [
'email' => 'required|email',
'first_name' => 'required',
'last_name' => 'required',
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
\ No newline at end of file
......@@ -43,6 +43,22 @@
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', 'Password:') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}
{!! $errors->first('password', '<span class="help-block">:message</span>') !!}
</div>
</div>
<div class="col-sm-6">
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
{!! Form::label('password_confirmation', 'Password confirmation:') !!}
{!! Form::password('password_confirmation', ['class' => 'form-control']) !!}
{!! $errors->first('password_confirmation', '<span class="help-block">:message</span>') !!}
</div>
</div>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">Create</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment