mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 04:58:01 +01:00
Made avatars optional. Useful for archived profiles!
Also took the opportunity to refactor SaveAccountSettingsCommand somewhat.
This commit is contained in:
parent
f5f58760e1
commit
64a44fff4f
5 changed files with 22 additions and 53 deletions
|
@ -29,18 +29,14 @@ use Validator;
|
||||||
class SaveAccountSettingsCommand extends CommandBase
|
class SaveAccountSettingsCommand extends CommandBase
|
||||||
{
|
{
|
||||||
private $_input;
|
private $_input;
|
||||||
private $_slug;
|
|
||||||
private $_user;
|
|
||||||
private $_current;
|
|
||||||
|
|
||||||
public function __construct($input, $slug)
|
/** @var User */
|
||||||
|
private $_user;
|
||||||
|
|
||||||
|
public function __construct($input, User $user)
|
||||||
{
|
{
|
||||||
$this->_input = $input;
|
$this->_input = $input;
|
||||||
$this->_slug = $slug;
|
$this->_user = $user;
|
||||||
|
|
||||||
/** @var User _user */
|
|
||||||
$this->_user = null;
|
|
||||||
$this->_current = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,25 +44,7 @@ class SaveAccountSettingsCommand extends CommandBase
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
if (Auth::user() != null) {
|
return Gate::allows('edit', $this->_user);
|
||||||
$this->_current = Auth::user();
|
|
||||||
|
|
||||||
if ($this->_slug == $this->_current->slug) {
|
|
||||||
$this->_user = $this->_current;
|
|
||||||
} else {
|
|
||||||
$this->_user = User::where('slug', $this->_slug)->whereNull('disabled_at')->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_user == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Gate::allows('edit', $this->_user)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,14 +53,6 @@ class SaveAccountSettingsCommand extends CommandBase
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
if ($this->_user == null) {
|
|
||||||
if ($_current->hasRole('admin')) {
|
|
||||||
return CommandResponse::fail(['Not found']);
|
|
||||||
} else {
|
|
||||||
return CommandResponse::fail(['Permission denied']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'display_name' => 'required|min:3|max:26',
|
'display_name' => 'required|min:3|max:26',
|
||||||
'bio' => 'textarea_length:250',
|
'bio' => 'textarea_length:250',
|
||||||
|
@ -110,31 +80,26 @@ class SaveAccountSettingsCommand extends CommandBase
|
||||||
return CommandResponse::fail($validator);
|
return CommandResponse::fail($validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->_input['uses_gravatar'] != 'true') {
|
|
||||||
if ($this->_user->avatar_id == null && !isset($this->_input['avatar']) && !isset($this->_input['avatar_id'])) {
|
|
||||||
$validator->messages()->add('avatar',
|
|
||||||
'You must upload or select an avatar if you are not using gravatar!');
|
|
||||||
|
|
||||||
return CommandResponse::fail($validator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_user->bio = $this->_input['bio'];
|
$this->_user->bio = $this->_input['bio'];
|
||||||
$this->_user->display_name = $this->_input['display_name'];
|
$this->_user->display_name = $this->_input['display_name'];
|
||||||
$this->_user->slug = $this->_input['slug'];
|
$this->_user->slug = $this->_input['slug'];
|
||||||
$this->_user->can_see_explicit_content = $this->_input['can_see_explicit_content'] == 'true';
|
$this->_user->can_see_explicit_content = $this->_input['can_see_explicit_content'] == 'true';
|
||||||
$this->_user->uses_gravatar = $this->_input['uses_gravatar'] == 'true';
|
$this->_user->uses_gravatar = $this->_input['uses_gravatar'] == 'true';
|
||||||
|
|
||||||
if ($this->_user->uses_gravatar) {
|
if ($this->_user->uses_gravatar && !empty($this->_input['gravatar'])) {
|
||||||
$this->_user->avatar_id = null;
|
$this->_user->avatar_id = null;
|
||||||
$this->_user->gravatar = $this->_input['gravatar'];
|
$this->_user->gravatar = $this->_input['gravatar'];
|
||||||
} else {
|
} else {
|
||||||
|
$this->_user->uses_gravatar = false;
|
||||||
|
|
||||||
if (isset($this->_input['avatar_id'])) {
|
if (isset($this->_input['avatar_id'])) {
|
||||||
$this->_user->avatar_id = $this->_input['avatar_id'];
|
$this->_user->avatar_id = $this->_input['avatar_id'];
|
||||||
|
|
||||||
|
} elseif (isset($this->_input['avatar'])) {
|
||||||
|
$this->_user->avatar_id = Image::upload($this->_input['avatar'], $this->_user)->id;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isset($this->_input['avatar'])) {
|
$this->_user->avatar_id = null;
|
||||||
$this->_user->avatar_id = Image::upload($this->_input['avatar'], $this->_user)->id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,8 @@ class AccountController extends ApiControllerBase
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postSave($slug)
|
public function postSave(User $user)
|
||||||
{
|
{
|
||||||
return $this->execute(new SaveAccountSettingsCommand(Input::all(), $slug));
|
return $this->execute(new SaveAccountSettingsCommand(Input::all(), $user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ Route::group(['prefix' => 'api/web'], function() {
|
||||||
|
|
||||||
Route::post('/comments/{type}/{id}', 'Api\Web\CommentsController@postCreate')->where('id', '\d+');
|
Route::post('/comments/{type}/{id}', 'Api\Web\CommentsController@postCreate')->where('id', '\d+');
|
||||||
|
|
||||||
Route::post('/account/settings/save/{slug}', 'Api\Web\AccountController@postSave');
|
Route::post('/account/settings/save/{userSlug}', 'Api\Web\AccountController@postSave');
|
||||||
|
|
||||||
Route::post('/favourites/toggle', 'Api\Web\FavouritesController@postToggle');
|
Route::post('/favourites/toggle', 'Api\Web\FavouritesController@postToggle');
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
|
|
||||||
public function getAvatarUrl($type = Image::NORMAL)
|
public function getAvatarUrl($type = Image::NORMAL)
|
||||||
{
|
{
|
||||||
if (!$this->uses_gravatar) {
|
if (!$this->uses_gravatar && $this->avatar !== null) {
|
||||||
return $this->avatar->getUrl($type);
|
return $this->avatar->getUrl($type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,10 @@ module.exports = angular.module('ponyfm').directive 'pfmImageUpload', () ->
|
||||||
else if $scope.imageUrl
|
else if $scope.imageUrl
|
||||||
lightbox.openImageUrl $scope.imageUrl
|
lightbox.openImageUrl $scope.imageUrl
|
||||||
|
|
||||||
|
# An explicit return value is needed here to avoid this issue:
|
||||||
|
# https://docs.angularjs.org/error/$parse/isecdom
|
||||||
|
return null
|
||||||
|
|
||||||
$scope.uploadImage = () ->
|
$scope.uploadImage = () ->
|
||||||
$uploader.trigger 'click'
|
$uploader.trigger 'click'
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue