Skip to content

Commit

Permalink
fix(authentication): Correctly checks settings before letting a user …
Browse files Browse the repository at this point in the history
…change name or image. (serverpod#2771)
  • Loading branch information
vlidholt authored Sep 24, 2024
1 parent 0133c99 commit aeba3a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,31 @@ class UserEndpoint extends Endpoint {
/// Removes the users uploaded image, replacing it with the default user
/// image.
Future<bool> removeUserImage(Session session) async {
if (!AuthConfig.current.userCanEditUserImage) {
return false;
}

var userId = (await session.authenticated)?.userId;
return await UserImages.setDefaultUserImage(session, userId!);
}

/// Sets a new user image for the signed in user.
Future<bool> setUserImage(Session session, ByteData image) async {
if (!AuthConfig.current.userCanEditUserImage) {
return false;
}

var userId = (await session.authenticated)?.userId;
return await UserImages.setUserImageFromBytes(
session, userId!, image.buffer.asUint8List());
}

/// Changes the name of a user.
Future<bool> changeUserName(Session session, String userName) async {
if (!AuthConfig.current.userCanEditUserName) {
return false;
}

userName = userName.trim();
if (userName == '') return false;

Expand All @@ -41,6 +53,10 @@ class UserEndpoint extends Endpoint {

/// Changes the full name of a user.
Future<bool> changeFullName(Session session, String fullName) async {
if (!AuthConfig.current.userCanEditFullName) {
return false;
}

fullName = fullName.trim();
if (fullName == '') return false;

Expand Down
1 change: 1 addition & 0 deletions tests/serverpod_test_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void run(List<String> args) async {
print('Sending reset email to ${userInfo.email} with code $resetCode');
return true;
},
userCanEditFullName: true,
));

// Add route to web server
Expand Down

0 comments on commit aeba3a8

Please sign in to comment.