Skip to content

Commit

Permalink
UsersController works
Browse files Browse the repository at this point in the history
  • Loading branch information
Halim authored and Halim committed Nov 7, 2016
1 parent 93f722f commit 1676fae
Show file tree
Hide file tree
Showing 5,551 changed files with 635,785 additions and 46 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
32 changes: 32 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
APP_ENV=local
APP_KEY=base64:EpAGTCQXbXyJ5HkVMgRPowbixAg/41UpSzFTSAbP96U=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel-crud
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/node_modules
/public/storage
/vendor
/.idea
Homestead.json
Homestead.yaml
.env

122 changes: 86 additions & 36 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

//use Illuminate\Http\Request;
use App\User;
use Request;
use Request;
use App\Http\Requests;

//use Illuminate\Support\Facades\Redirect;
//use Illuminate\Support\Facades\Input;
//use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Validator;

class UsersController extends Controller {
/*
Expand Down Expand Up @@ -43,65 +44,56 @@ public function create() {
* @return Response
*/
public function store(Requests\UsersRequest $request) {



//$input = Request::all();
//User::create($input);

$request['password'] = bcrypt($request['password']);
User::create($request->all());




return redirect('users');
}

public function store_old() {

//Validation rules
$rules = $this->rules();
$messages = $this->messages();

//Validate
//$validator = Validator::make(Input::all(), $rules, $messages);
$validator = Validator::make(Input::all(), $rules);

//$validator->passes()
if ($validator->fails()) {
return back()->withErrors($validator)->withInput();
}
else { //Ok to save
} else { //Ok to save
$post = Input::all();

$insertData = array(
'username' => $post['username'],
//'phone' => empty($post['phone']) ? null : $post['phone'],
'email' => $post['email'],
//'password' => Hash::make(Hash::make(Input::get('password'))) // Class 'App\Http\Controllers\Hash' not found
'password' => bcrypt($post['password'])
);

try {
$result = User::create($insertData);
$insert_id = $result->contact_id; //get last inserted id
if ($result) {
return Redirect::back()->with('message', 'Record Inserted Successfully : insert_id = ' . $insert_id);
}
else {
} else {
return Redirect::back()->with('message', 'Something was wrong !');
}
}
catch (\Exception $e) {
} catch (\Exception $e) {
//var_dump($e->errorInfo);
return Redirect::back()->with('message', 'Sorry something went worng. Please try again.')->withInput();
}

}
//return redirect('users');

}


/**
* Get the validation rules that apply to the request.
*
Expand All @@ -114,7 +106,7 @@ public function rules() {
'password' => 'required|min:6|confirmed'
];
}

/*
*
*/
Expand All @@ -126,38 +118,34 @@ public function messages() {
'password.alpha' => 'The Last Name may only contain letters.'
];
}


/**

/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
*/
public function show($id) {

$user = User::findOrFail($id);
return view('users.show', compact('user'));

}



/**
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id) {
$user = User::findOrFail($id);

//dd($user);

$user->delete();
return redirect('users');
}

/**
* Show the form for editing the specified resource.
*
Expand All @@ -168,17 +156,79 @@ public function edit($id) {
$user = User::findOrFail($id);
return view('users.edit', compact('user'));
}

public function update($id) {
//dd($id);
$user = User::findOrFail($id);

//dd($user->users_id);

$rules = $this->rules_update($user->users_id);
//$messages = $this->messages_update();

//$validator = Validator::make(Input::all(), $rules, $messages);
$validator = Validator::make(Request::all(), $rules);

//$validator->passes()
if ($validator->fails()) {
//return Redirect::to("/users/$id/edit")->withInput()->withErrors($validator);
return back()->withErrors($validator)->withInput();
}
else {
$user->update(Request::all());
//return Redirect::to('users');
return redirect('users');
}

}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules_update($users_id) {
return [
'username' => 'required|min:3|max:15',
'email' => 'required|email|max:45|unique:users,email, '.$users_id.',users_id'
];
}

/*
*
*/

public function reset_password($id) {

$user = User::findOrFail($id);
//dd($user);

return view('users.reset_password', compact('user'));
}
/*
*
*/
public function update_password($id) {
$user = User::findOrFail($id);

$rules = array(
'password' => 'required|min:6|confirmed',
'password_confirmation' => 'required|min:6',
);

$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
//return Redirect::to("/users/$id/edit")->withInput()->withErrors($validator);
return back()->withErrors($validator)->withInput();
}
else {

$password = bcrypt(Request::get('password'));
$user->update(['password' => $password]);
//return Redirect::to('users');
//return redirect('users');
return view('users.reset_password', compact('user'));
}
}


}
4 changes: 1 addition & 3 deletions resources/views/articles/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

@include('articles.errors')

{!! Form::open(['url' => 'articles']) !!}
{!! Form::open(['url' => 'articles']) !!}



@include('articles.form', ['submitButtonName' => 'Add the Article'])

{!! Form::close() !!}
Expand Down
6 changes: 4 additions & 2 deletions resources/views/users/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
@endif


<form class="form-horizontal" role="form" method="PATCH" action="{{ url('/users', $user->id) }}">
<!--<form class="form-horizontal" role="form" method="PATCH" action="{{ url('/users', $user->users_id) }}">-->
{!! Form::model($user, ['method' => 'PATCH', 'url' => url('/users', $user->users_id), 'class' => 'form-horizontal']) !!}

{{ csrf_field() }}

Expand Down Expand Up @@ -63,7 +64,8 @@
</div>
</div>

</form>
<!--</form>-->
{!! Form::close() !!}

</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions resources/views/users/reset_password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
@endif


<form class="form-horizontal" role="form" method="PATCH" action="{{ url('/users', $user->id) }}">
<!--<form class="form-horizontal" role="form" method="PATCH" action="{{ url('/users', $user->id) }}">-->
{!! Form::open(['method' => 'PATCH', 'url' => url('/users/'.$user->users_id.'/reset_password'), 'class' => 'form-horizontal']) !!}

{{ csrf_field() }}

Expand Down Expand Up @@ -56,7 +57,8 @@
</div>
</div>

</form>
<!--</form>-->
{!! Form::close() !!}

</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
Route::get('users/{id}', 'UsersController@show');
Route::post('users', 'UsersController@store');
Route::get('users/{id}/edit', 'UsersController@edit');

Route::patch('users/{id}', 'UsersController@update');

Route::delete('users/{id}', 'UsersController@destroy');

Route::get('users/{id}/reset_password', 'UsersController@reset_password');

Route::get('users/{id}/reset_password', 'UsersController@reset_password');
Route::patch('users/{id}/reset_password', 'UsersController@update_password');
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInita204dc84e12a110d387420359dd2eee9::getLoader();
17 changes: 17 additions & 0 deletions vendor/bin/php-parse
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../nikic/php-parser/bin" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m "$dir");
fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/php-parse" "$@"
4 changes: 4 additions & 0 deletions vendor/bin/php-parse.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/../nikic/php-parser/bin/php-parse
php "%BIN_TARGET%" %*
17 changes: 17 additions & 0 deletions vendor/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m "$dir");
fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"
4 changes: 4 additions & 0 deletions vendor/bin/phpunit.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/../phpunit/phpunit/phpunit
php "%BIN_TARGET%" %*
Loading

0 comments on commit 1676fae

Please sign in to comment.