Merge pull request #6571 from pixelfed/staging

Staging
pull/6605/head
dansup 2 months ago committed by GitHub
commit e734b19f77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1974,9 +1974,11 @@ class ApiV1Controller extends Controller
abort(403, 'Invalid or unsupported mime type.');
}
$hash = \hash_file('sha256', $photo->getRealPath());
abort_if(MediaBlocklistService::exists($hash) == true, 451);
$storagePath = MediaPathService::get($user, 2);
$path = $photo->storePublicly($storagePath);
$hash = \hash_file('sha256', $photo);
$license = null;
$mime = $photo->getMimeType();
@ -2000,8 +2002,6 @@ class ApiV1Controller extends Controller
}
}
abort_if(MediaBlocklistService::exists($hash) == true, 451);
$media = new Media;
$media->status_id = null;
$media->profile_id = $profile->id;
@ -2201,9 +2201,11 @@ class ApiV1Controller extends Controller
abort(403, 'Invalid or unsupported mime type.');
}
$hash = \hash_file('sha256', $photo->getRealPath());
abort_if(MediaBlocklistService::exists($hash) == true, 451);
$storagePath = MediaPathService::get($user, 2);
$path = $photo->storePublicly($storagePath);
$hash = \hash_file('sha256', $photo);
$license = null;
$mime = $photo->getMimeType();
@ -2217,8 +2219,6 @@ class ApiV1Controller extends Controller
}
}
abort_if(MediaBlocklistService::exists($hash) == true, 451);
if ($request->has('replace_id')) {
$rpid = $request->input('replace_id');
$removeMedia = Media::whereNull('status_id')

@ -1266,9 +1266,15 @@ class ApiV1Dot1Controller extends Controller
abort(403, 'Invalid or unsupported mime type.');
}
if ($user->last_active_at == null) {
return [];
}
$hash = \hash_file('sha256', $photo->getRealPath());
abort_if(MediaBlocklistService::exists($hash) == true, 451);
$storagePath = MediaPathService::get($user, 2);
$path = $photo->storePublicly($storagePath);
$hash = \hash_file('sha256', $photo);
$license = null;
$mime = $photo->getMimeType();
@ -1282,17 +1288,11 @@ class ApiV1Dot1Controller extends Controller
}
}
abort_if(MediaBlocklistService::exists($hash) == true, 451);
$visibility = $profile->is_private ? 'private' : (
$profile->unlisted == true &&
$request->input('visibility', 'public') == 'public' ?
'unlisted' :
$request->input('visibility', 'public'));
if ($user->last_active_at == null) {
return [];
}
$defaultCaption = '';
$cleanedStatus = app(SanitizeService::class)->html($request->input('status', ''));
$content = $request->filled('status') ? strip_tags($cleanedStatus) : $defaultCaption;

@ -10,10 +10,10 @@ use App\Services\AccountService;
use App\Services\PronounService;
use App\Util\Lexer\Autolink;
use App\Util\Lexer\PrettyNumber;
use Auth;
use Cache;
use Illuminate\Http\Request;
use Mail;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Purify;
trait HomeSettings
@ -118,38 +118,48 @@ trait HomeSettings
{
$this->validate($request, [
'current' => 'required|string',
'password' => 'required|string',
'password_confirmation' => 'required|string',
'password' => 'required|string|confirmed|min:8|different:current',
'revoke_sessions' => 'nullable|boolean',
]);
$current = $request->input('current');
$new = $request->input('password');
$confirm = $request->input('password_confirmation');
$revokeSessions = $request->boolean('revoke_sessions');
$user = Auth::user();
if (password_verify($current, $user->password) && $new === $confirm) {
$user->password = bcrypt($new);
$user->save();
$log = new AccountLog;
$log->user_id = $user->id;
$log->item_id = $user->id;
$log->item_type = 'App\User';
$log->action = 'account.edit.password';
$log->message = 'Password changed';
$log->link = null;
$log->ip_address = $request->ip();
$log->user_agent = $request->userAgent();
$log->save();
$user = $request->user();
Mail::to($request->user())->send(new PasswordChange($user));
return redirect('/settings/home')->with('status', 'Password successfully updated!');
} else {
if (!password_verify($current, $user->password)) {
return redirect()->back()->with('error', 'There was an error with your request! Please try again.');
}
$user->password = bcrypt($new);
$user->save();
$log = new AccountLog;
$log->user_id = $user->id;
$log->item_id = $user->id;
$log->item_type = 'App\User';
$log->action = 'account.edit.password';
$log->message = $revokeSessions
? 'Password changed and all sessions revoked'
: 'Password changed';
$log->link = null;
$log->ip_address = $request->ip();
$log->user_agent = $request->userAgent();
$log->save();
Mail::to($request->user())->send(new PasswordChange($user));
if ($revokeSessions) {
$user->tokens->each(function ($token) {
$token->revoke();
$token->refreshToken?->revoke();
});
Auth::logoutOtherDevices($new);
}
return redirect('/settings/home')->with('status', 'Password successfully updated!');
}
public function email()

@ -50,6 +50,14 @@
<input type="password" class="form-control" name="password_confirmation" placeholder="{{__('settings.password.confirm_new_password')}}">
</div>
</div>
<div class="form-group row">
<div class="col-sm-9 offset-sm-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="revokeSessions" name="revoke_sessions" value="1">
<label class="form-check-label font-weight-bold" for="revokeSessions">Revoke all log-out all existing sessions</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12 text-right">
<button type="submit" class="btn btn-primary font-weight-bold py-0 px-5">{{__('settings.submit')}}</button>

Loading…
Cancel
Save