rename user/profile route group

This commit is contained in:
flash 2016-12-09 20:46:23 +01:00
parent d9e7c5616b
commit cae6f22d37
2 changed files with 40 additions and 18 deletions

View file

@ -23,12 +23,11 @@ class UserController extends Controller
{
/**
* Display the profile of a user.
* @param int|string $id
* @param int $id
* @return string
*/
public function profile($id = 0): string
public function profile(int $id = 0): string
{
// Get the user's context
$profile = User::construct($id);
// If the user id is zero check if there was a namechange
@ -48,6 +47,24 @@ class UserController extends Controller
return view('user/profile', compact('profile'));
}
/**
* Resolve user id from username and redirect to profile.
* @throws HttpRouteNotFoundException
* @param string $id
*/
public function resolve(string $name): string
{
$id = DB::table('users')
->where('username_clean', clean_string($name, true, true))
->value('user_id');
if (!$id) {
throw new HttpRouteNotFoundException;
}
return redirect(route('user.profile', $id));
}
/**
* Last listened to.
* @param int $id

View file

@ -59,8 +59,8 @@ Router::group(['before' => 'maintenance'], function () {
Router::delete('/logout', 'AuthController@logout', 'auth.logout');
Router::get('/register', 'AuthController@register', 'auth.register');
Router::post('/register', 'AuthController@register', 'auth.register');
Router::get('/resetpassword', 'AuthController@resetPassword', 'auth.resetpassword');
Router::post('/resetpassword', 'AuthController@resetPassword', 'auth.resetpassword');
Router::get('/reset-password', 'AuthController@resetPassword', 'auth.resetpassword');
Router::post('/reset-password', 'AuthController@resetPassword', 'auth.resetpassword');
Router::get('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
Router::post('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
Router::get('/activate', 'AuthController@activate', 'auth.activate');
@ -123,23 +123,28 @@ Router::group(['before' => 'maintenance'], function () {
});
// User
Router::group(['prefix' => 'u'], function () {
Router::get('/{id}', 'UserController@profile', 'user.profile');
Router::get('/{id}/report', 'UserController@report', 'user.report');
Router::group(['prefix' => 'user'], function () {
Router::get('/{id:i}', 'UserController@profile', 'user.profile');
Router::get('/{id}', 'UserController@resolve', 'user.profile');
Router::get('/{id:i}/report', 'UserController@report', 'user.report');
Router::get('/{id}/nowplaying', 'UserController@nowPlaying', 'user.nowplaying');
Router::get('/{id:i}/now-playing', 'UserController@nowPlaying', 'user.nowplaying');
Router::get('/{id}/avatar', 'FileController@avatar', 'user.avatar');
Router::post('/{id}/avatar', 'FileController@avatar', 'user.avatar');
Router::delete('/{id}/avatar', 'FileController@avatar', 'user.avatar');
Router::get('/{id:i}/avatar', 'FileController@avatar', 'user.avatar');
Router::post('/{id:i}/avatar', 'FileController@avatar', 'user.avatar');
Router::delete('/{id:i}/avatar', 'FileController@avatar', 'user.avatar');
Router::get('/{id}/background', 'FileController@background', 'user.background');
Router::post('/{id}/background', 'FileController@background', 'user.background');
Router::delete('/{id}/background', 'FileController@background', 'user.background');
Router::get('/{id:i}/background', 'FileController@background', 'user.background');
Router::post('/{id:i}/background', 'FileController@background', 'user.background');
Router::delete('/{id:i}/background', 'FileController@background', 'user.background');
Router::get('/{id}/header', 'FileController@header', 'user.header');
Router::post('/{id}/header', 'FileController@header', 'user.header');
Router::delete('/{id}/header', 'FileController@header', 'user.header');
Router::get('/{id:i}/header', 'FileController@header', 'user.header');
Router::post('/{id:i}/header', 'FileController@header', 'user.header');
Router::delete('/{id:i}/header', 'FileController@header', 'user.header');
});
Router::get('/u/{id}', function ($id) {
return redirect(route('user.profile', $id));
});
// Notifications