Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User account #43

Merged
merged 6 commits into from
Apr 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
wip
Jovert Lota Palonpon committed Apr 20, 2019
commit 002262ea1622d395442aa7380c4cbb19c6faa993
44 changes: 39 additions & 5 deletions app/Http/Controllers/Api/V1/Settings/AccountController.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,42 @@

class AccountController extends Controller
{
/**
* @var App\User
*/
protected $user;

/**
* Create a new AccountController
*/
public function __construct()
{
$this->user = auth()->guard('api')->user();
}

/**
* Update User's login credentials
*
* @param Illuminate\Http\Request $request
*
* @return Illuminate\Http\JsonResponse
*/
public function updateCredentials(Request $request) : JsonResponse
{
$request->validate([
'username' =>
"required|string|unique:users,username,{$this->user->id},id,deleted_at,NULL",
'email' =>
"required|email|unique:users,email,{$this->user->id},id,deleted_at,NULL"
]);

$this->user->username = $request->input('username');
$this->user->email = $request->input('email');
$this->user->update();

return response()->json($this->user);
}

/**
* Update User's password
*
@@ -24,18 +60,16 @@ public function updatePassword(Request $request) : JsonResponse
'password' => 'required|string|confirmed|min:8|pwned:100'
]);

$user = auth()->guard('api')->user();

if (! Hash::check($request->input('old_password'), $user->password)) {
if (! Hash::check($request->input('old_password'), $this->user->password)) {
throw ValidationException::withMessages([
'old_password' => [trans('auth.password_mismatch')]
]);

return response()->json('Password was not Changed!', 422);
}

$user->password = bcrypt($request->input('password'));
$user->update();
$this->user->password = bcrypt($request->input('password'));
$this->user->update();

return response()->json('Password Changed!');
}
594 changes: 367 additions & 227 deletions resources/js/views/__backoffice/settings/Account.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions resources/lang/en/settings.php
Original file line number Diff line number Diff line change
@@ -6,13 +6,15 @@
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used in the frontend of the application,
| specifically in actions, links in different kind of settings.
| The following language lines are used in specifically in actions,
| links in different kind of settings.
|
*/

'profile_updated' => 'Profile successfully updated!',
'profile_not_updated' => 'Profile was not updated!',
'account_password_updated' => 'Account Password successfully updated!',
'account_password_not_updated' => 'Account Password was not updated!',
'account_credentials_updated' => 'Account Credentials successfully updated!',
'account_credentials_not_updated' => 'Account Credentials was not updated!',
];
7 changes: 5 additions & 2 deletions resources/lang/fil/settings.php
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used in the frontend of the application,
| specifically in actions, links in different kind of settings.
| The following language lines are used in specifically in actions,
| links in different kind of settings.
|
*/

@@ -16,4 +16,7 @@
'account_password_updated' => 'Ang Password ng iyong Account ay nabago!',
'account_password_not_updated' =>
'Ang Password ng iyong Account ay hindi nabago!',
'account_credentials_updated' => 'Ang Credentials ng iyong Account ay nabago!',
'account_credentials_not_updated' =>
'Ang Credentials ng iyong Account ay hindi nabago!',
];
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@

Route::prefix('account')->name('account.')->group(function () {
Route::patch('password', 'AccountController@updatePassword')->name('password');
Route::patch('credentials', 'AccountController@updateCredentials')->name('credentials');
});
});

19 changes: 19 additions & 0 deletions tests/Feature/Api/V1/Settings/AccountTest.php
Original file line number Diff line number Diff line change
@@ -26,4 +26,23 @@ public function a_user_can_change_its_password()
->assertStatus(200)
->assertSee('Password Changed!');
}

/** @test */
public function a_user_can_update_its_login_credentials()
{
$attributes = [
'username' => $this->faker->userName,
'email' => $this->faker->email,
];

// The response body that should be sent alongside the request.
$body = array_merge($this->getDefaultPayload(), $attributes);

// Assuming that the user's login credentials has been updated,
// It must return a 200 response status and then,
// It must return a response body containing the updated user's credentials.
$this->patch(route('api.v1.settings.account.credentials'), $body)
->assertStatus(200)
->assertJsonFragment($attributes);
}
}