Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c79165f

Browse files
Add EditProfileCept and LoginCept
1 parent f70dfd3 commit c79165f

File tree

8 files changed

+174
-0
lines changed

8 files changed

+174
-0
lines changed

‎app/Http/Controllers/Auth/AuthController.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class AuthController extends Controller
2323

2424
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
2525

26+
/**
27+
* @var string
28+
*/
29+
protected $redirectPath = '';
30+
2631
/**
2732
* Create a new authentication controller instance.
2833
*
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php namespace App\Http\Controllers;
2+
3+
use App\User;
4+
use Illuminate\Http\Request;
5+
6+
class UsersController extends Controller {
7+
8+
/**
9+
* User Repository
10+
*
11+
* @var User
12+
*/
13+
protected $user;
14+
15+
/**
16+
* Constructor.
17+
* @param User $user
18+
*/
19+
public function __construct(User $user)
20+
{
21+
$this->user = $user;
22+
}
23+
24+
/**
25+
* Display the specified resource.
26+
*
27+
* @param int $id
28+
* @return Response
29+
*/
30+
public function show($id)
31+
{
32+
$user = $this->user->findOrFail($id);
33+
34+
return view('users.show', compact('user'));
35+
}
36+
37+
/**
38+
* Show the form for editing the specified resource.
39+
*
40+
* @param int $id
41+
* @return Response
42+
*/
43+
public function edit($id)
44+
{
45+
$user = $this->user->findOrFail($id);
46+
47+
return view('users.edit', compact('user'));
48+
}
49+
50+
/**
51+
* Update the specified resource in storage.
52+
*
53+
* @param Request $request
54+
* @param int $id
55+
* @return Response
56+
*/
57+
public function update(Request $request, $id)
58+
{
59+
$this->validate($request, ['email' => 'required|email']);
60+
61+
$user = $this->user->findOrFail($id);
62+
$user->update($request->all());
63+
$user->save();
64+
65+
return redirect()->route('users.show', $id);
66+
}
67+
68+
}

‎app/Http/routes.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
Route::resource('posts', 'PostsController');
2323
Route::resource('api/posts', 'Api\PostsController');
24+
Route::resource('users', 'UsersController');
2425

2526
Route::controllers([
2627
'auth' => 'Auth\AuthController',

‎resources/views/layouts/scaffold.blade.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
@endif
2121

2222
@yield('main')
23+
24+
<div class="well">
25+
@if (Auth::user())
26+
Logged in as {{{ Auth::user()->email }}}.
27+
<a href="/auth/logout">Logout</a>
28+
@else
29+
Not logged in
30+
@endif
31+
</div>
2332
</div>
2433

2534
</body>

‎resources/views/users/edit.blade.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@extends('layouts.scaffold')
2+
3+
@section('main')
4+
5+
<h1>Edit User</h1>
6+
{!! Form::model($user, array('method' => 'PATCH', 'route' => array('users.update', $user->id))) !!}
7+
<ul>
8+
<li>
9+
{!! Form::label('email', 'Email') !!}
10+
{!! Form::text('email') !!}
11+
</li>
12+
<li>
13+
{!! Form::submit('Update', array('class' => 'btn btn-info')) !!}
14+
{!! link_to_route('users.show', 'Cancel', $user->id, array('class' => 'btn')) !!}
15+
</li>
16+
</ul>
17+
{!! Form::close() !!}
18+
19+
@if ($errors->any())
20+
<ul>
21+
{!! implode('', $errors->all('<li class="error">:message</li>')) !!}
22+
</ul>
23+
@endif
24+
25+
@stop

‎resources/views/users/show.blade.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@extends('layouts.scaffold')
2+
3+
@section('main')
4+
5+
<h1>Show User</h1>
6+
7+
<table class="table table-striped table-bordered">
8+
<thead>
9+
<tr>
10+
<th>ID</th>
11+
<th>Email</th>
12+
<th>Actions</th>
13+
</tr>
14+
</thead>
15+
16+
<tbody>
17+
<tr>
18+
<td>{{ $user->id }}</td>
19+
<td>{{ $user->email }}</td>
20+
<td>{!! link_to_route('users.edit', 'Edit', array($user->id), array('class' => 'btn btn-info')) !!}</td>
21+
</tr>
22+
</tbody>
23+
</table>
24+
25+
@stop

‎tests/functional/EditProfileCept.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
use App\User;
3+
4+
$I = new FunctionalTester($scenario);
5+
$I->wantTo('edit a profile');
6+
7+
$user = User::create(['email' => 'johndoe@example.com', 'password' => bcrypt('password')]);
8+
$I->amOnPage('/auth/login');
9+
$I->fillField('email', 'johndoe@example.com');
10+
$I->fillField('password', 'password');
11+
$I->click('button[type=submit]');
12+
13+
$I->amOnPage('/users/1');
14+
$I->see('Logged in as johndoe@example.com');
15+
16+
$I->click('Edit');
17+
$I->fillField('Email', 'john@doe.com');
18+
$I->click('Update');
19+
20+
$I->seeCurrentUrlEquals('/users/1');
21+
$I->see('Logged in as john@doe.com');

‎tests/functional/LoginCept.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
$I = new FunctionalTester($scenario);
3+
$I->wantTo('login as a user');
4+
5+
$I->haveRecord('users', [
6+
'email' => 'john@doe.com',
7+
'password' => bcrypt('password'),
8+
'created_at' => new DateTime(),
9+
'updated_at' => new DateTime(),
10+
]);
11+
12+
$I->amOnPage('/auth/login');
13+
$I->fillField('email', 'john@doe.com');
14+
$I->fillField('password', 'password');
15+
$I->click('button[type=submit]');
16+
17+
$I->seeCurrentUrlEquals('');
18+
$I->amOnPage('/posts');
19+
$I->seeAuthentication();
20+
$I->see('Logged in as john@doe.com');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /