Skip to content

Commit 4c22c50

Browse files
committed
User Section Finished
Signed-off-by: David Thorpe <[email protected]>
1 parent 79fdf86 commit 4c22c50

File tree

5 files changed

+85
-15
lines changed

5 files changed

+85
-15
lines changed

src/Davzie/LaravelBootstrap/Accounts/User.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
use Davzie\LaravelBootstrap\Core\EloquentBaseModel;
33
use Illuminate\Auth\UserInterface as LaravelUserInterface;
44
use Illuminate\Auth\Reminders\RemindableInterface;
5+
use Hash;
56

67
class User extends EloquentBaseModel implements LaravelUserInterface, RemindableInterface
78
{
9+
// The Tables
810
protected $table = 'users';
911

1012
/**
@@ -18,12 +20,13 @@ class User extends EloquentBaseModel implements LaravelUserInterface, Remindable
1820
* These are the mass-assignable keys
1921
* @var array
2022
*/
21-
protected $fillable = array('first_name', 'last_name', 'email');
23+
protected $fillable = array('first_name', 'last_name', 'email', 'password');
2224

2325
protected $validationRules = [
2426
'first_name' => 'required',
2527
'last_name' => 'required',
26-
'email' => 'required|email'
28+
'email' => 'required|email',
29+
'password' => 'confirmed|min:5'
2730
];
2831

2932
/**
@@ -64,4 +67,13 @@ public function getReminderEmail()
6467
return $this->email;
6568
}
6669

67-
}
70+
/**
71+
* Set the password, lets automatically hash it
72+
* @param string $value The password (unhashed)
73+
*/
74+
public function setPasswordAttribute($value)
75+
{
76+
$this->attributes['password'] = Hash::make( $value );
77+
}
78+
79+
}

src/controllers/ObjectBaseController.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ abstract class ObjectBaseController extends BaseController {
6464
*/
6565
protected $uploads_model;
6666

67+
/**
68+
* By default a mass assignment is used to validate things on a model
69+
* Sometimes you want to confirm inputs (such as password confirmations)
70+
* that you don't want to be necessarily stored on the model. This will validate
71+
* inputs from Input::all() not from $model->fill();
72+
* @var boolean
73+
*/
74+
protected $validateWithInput = true;
75+
6776
public function __construct()
6877
{
6978
parent::__construct();
@@ -143,7 +152,9 @@ public function postNew()
143152
$record = $this->model->getNew();
144153
$record->fill( Input::all() );
145154

146-
if( !$record->isValid() )
155+
$valid = $this->validateWithInput === true ? $record->isValid( Input::all() ) : $record->isValid();
156+
157+
if( !$valid )
147158
return Redirect::to( $this->new_url )->with( 'errors' , $record->getErrors() );
148159

149160
// Run the hydration method that populates anything else that is required / runs any other
@@ -164,7 +175,9 @@ public function postEdit( $id )
164175
$record = $this->model->requireById( $id );
165176
$record->fill( Input::all() );
166177

167-
if( !$record->isValid() )
178+
$valid = $this->validateWithInput === true ? $record->isValid( Input::all() ) : $record->isValid();
179+
180+
if( !$valid )
168181
return Redirect::to( $this->edit_url.$id )->with( 'errors' , $record->getErrors() );
169182

170183
// Run the hydration method that populates anything else that is required / runs any other

src/controllers/UsersController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace Davzie\LaravelBootstrap\Controllers;
22
use Davzie\LaravelBootstrap\Accounts\UserInterface;
3+
use Illuminate\Support\MessageBag;
4+
use Input, Redirect;
35

46
class UsersController extends ObjectBaseController {
57

@@ -9,6 +11,15 @@ class UsersController extends ObjectBaseController {
911
*/
1012
protected $view_key = 'users';
1113

14+
/**
15+
* By default a mass assignment is used to validate things on a model
16+
* Sometimes you want to confirm inputs (such as password confirmations)
17+
* that you don't want to be necessarily stored on the model. This will validate
18+
* inputs from Input::all() not from $model->fill();
19+
* @var boolean
20+
*/
21+
protected $validateWithInput = true;
22+
1223
/**
1324
* Construct Shit
1425
*/

src/views/users/edit.blade.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,46 @@
1010

1111
@section('form-items')
1212

13+
{{-- The first name form item --}}
1314
<div class="form-group">
1415
{{ Form::label( "first_name" , 'First Name' , array( 'class'=>'col-lg-2 control-label' ) ) }}
1516
<div class="col-lg-10">
1617
{{ Form::text( "first_name" , Input::old( "first_name", $item->first_name ) , array( 'class'=>'form-control' , 'placeholder'=>'First Name' ) ) }}
1718
</div>
1819
</div>
20+
21+
{{-- The last name form item --}}
1922
<div class="form-group">
2023
{{ Form::label( "last_name" , 'Last Name' , array( 'class'=>'col-lg-2 control-label' ) ) }}
2124
<div class="col-lg-10">
2225
{{ Form::text( "last_name" , Input::old( "last_name", $item->last_name ) , array( 'class'=>'form-control' , 'placeholder'=>'Last Name' ) ) }}
2326
</div>
2427
</div>
28+
29+
{{-- The email form item --}}
2530
<div class="form-group">
2631
{{ Form::label( "email" , 'Email' , array( 'class'=>'col-lg-2 control-label' ) ) }}
2732
<div class="col-lg-10">
2833
{{ Form::text( "email" , Input::old( "email", $item->email ) , array( 'class'=>'form-control' , 'placeholder'=>'Email' ) ) }}
2934
</div>
3035
</div>
36+
3137
<h3>Authentication</h3>
38+
39+
{{-- The password form item --}}
3240
<div class="form-group">
3341
{{ Form::label( "password" , 'New Password' , array( 'class'=>'col-lg-2 control-label' ) ) }}
3442
<div class="col-lg-10">
35-
{{ Form::text( "password" , null , array( 'class'=>'form-control' , 'placeholder'=>'Enter New Password' ) ) }}
43+
{{ Form::password( "password" , array( 'class'=>'form-control' , 'placeholder'=>'Enter New Password' ) ) }}
3644
</div>
3745
</div>
46+
47+
{{-- The password confirmation form item --}}
3848
<div class="form-group">
3949
{{ Form::label( "password_confirmation" , 'Confirm' , array( 'class'=>'col-lg-2 control-label' ) ) }}
4050
<div class="col-lg-10">
41-
{{ Form::text( "password_confirmation" , null , array( 'class'=>'form-control' , 'placeholder'=>'Confirm New Password' ) ) }}
51+
{{ Form::password( "password_confirmation" , array( 'class'=>'form-control' , 'placeholder'=>'Confirm New Password' ) ) }}
4252
</div>
4353
</div>
54+
4455
@stop

src/views/users/new.blade.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
11
@extends('laravel-bootstrap::layouts.interface-new')
22

33
@section('title')
4-
Create New Content Blocks
4+
Create New User
55
@stop
66

77
@section('heading')
8-
<h1>Create New Content Block</h1>
8+
<h1>Create New User</h1>
99
@stop
1010

1111
@section('form-items')
1212

13+
{{-- The first name form item --}}
1314
<div class="form-group">
14-
{{ Form::label( "title" , 'Block Title' , array( 'class'=>'col-lg-2 control-label' ) ) }}
15+
{{ Form::label( "first_name" , 'First Name' , array( 'class'=>'col-lg-2 control-label' ) ) }}
1516
<div class="col-lg-10">
16-
{{ Form::text( "title" , Input::old( "title" ) , array( 'class'=>'form-control' , 'placeholder'=>'Block Title' ) ) }}
17+
{{ Form::text( "first_name" , Input::old( "first_name" ) , array( 'class'=>'form-control' , 'placeholder'=>'First Name' ) ) }}
1718
</div>
1819
</div>
20+
21+
{{-- The last name form item --}}
1922
<div class="form-group">
20-
{{ Form::label( "key" , 'Block Key' , array( 'class'=>'col-lg-2 control-label' ) ) }}
23+
{{ Form::label( "last_name" , 'Last Name' , array( 'class'=>'col-lg-2 control-label' ) ) }}
2124
<div class="col-lg-10">
22-
{{ Form::text( "key" , Input::old( "key" ) , array( 'class'=>'form-control' , 'placeholder'=>'Block Key' ) ) }}
25+
{{ Form::text( "last_name" , Input::old( "last_name" ) , array( 'class'=>'form-control' , 'placeholder'=>'Last Name' ) ) }}
2326
</div>
2427
</div>
28+
29+
{{-- The email form item --}}
30+
<div class="form-group">
31+
{{ Form::label( "email" , 'Email' , array( 'class'=>'col-lg-2 control-label' ) ) }}
32+
<div class="col-lg-10">
33+
{{ Form::text( "email" , Input::old( "email" ) , array( 'class'=>'form-control' , 'placeholder'=>'Email' ) ) }}
34+
</div>
35+
</div>
36+
37+
<h3>Authentication</h3>
38+
39+
{{-- The password form item --}}
40+
<div class="form-group">
41+
{{ Form::label( "password" , 'New Password' , array( 'class'=>'col-lg-2 control-label' ) ) }}
42+
<div class="col-lg-10">
43+
{{ Form::password( "password" , array( 'class'=>'form-control' , 'placeholder'=>'Enter New Password' ) ) }}
44+
</div>
45+
</div>
46+
47+
{{-- The password confirmation form item --}}
2548
<div class="form-group">
26-
{{ Form::label( "content" , 'Block Content' , array( 'class'=>'col-lg-2 control-label' ) ) }}
49+
{{ Form::label( "password_confirmation" , 'Confirm' , array( 'class'=>'col-lg-2 control-label' ) ) }}
2750
<div class="col-lg-10">
28-
{{ Form::textarea( "content" , Input::old( "content" ) , array( 'class'=>'form-control rich' , 'placeholder'=>'Block Content' ) ) }}
51+
{{ Form::password( "password_confirmation" , array( 'class'=>'form-control' , 'placeholder'=>'Confirm New Password' ) ) }}
2952
</div>
3053
</div>
3154

0 commit comments

Comments
 (0)