Skip to content

Commit

Permalink
Require username to match email user at signup
Browse files Browse the repository at this point in the history
  • Loading branch information
almonds0166 committed May 7, 2024
1 parent ccf4da9 commit 453fb65
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions server/public/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ func (u *User) IsValid() *AppError {
return InvalidUserError("email", u.Id, u.Email)
}

if u.Username != strings.Split(u.Email, "@")[0] {
return InvalidUserError("username", u.Id, u.Username)
}

if utf8.RuneCountInString(u.Nickname) > UserNicknameMaxRunes {
return InvalidUserError("nickname", u.Id, u.Nickname)
}
Expand Down
6 changes: 6 additions & 0 deletions webapp/channels/src/components/signup/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ const Signup = ({onCustomizeHeader}: SignupProps) => {
telemetryEvents.errors.push({field: 'username', rule: 'not_provided'});
isValid = false;
}
if (providedUsername != providedEmail.split('@')[0]) {
//const errorMessage = formatMessage({id: 'signup_user_completed.mismatch', defaultMessage: 'Your username must match your email (before the "@")'});
const errorMessage = 'Your username must match your email (before the "@")';
setNameError(errorMessage);
isValid = false;
}

const providedPassword = passwordInput.current?.value ?? '';
const {error, telemetryErrorIds} = isValidPassword(providedPassword, getPasswordConfig(config), intl);
Expand Down
7 changes: 5 additions & 2 deletions webapp/channels/src/utils/post_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function isFromWebhook(post: Post): boolean {
}

export function isFromBot(post: Post): boolean {
return post.props && post.props.from_bot === 'true';
return post.props && post.props.from_bot === 'true' && post.props.from_zephyr != 'true';
}

export function isPostOwner(state: GlobalState, post: Post): boolean {
Expand Down Expand Up @@ -632,7 +632,10 @@ export function areConsecutivePostsBySameUser(post: Post, previousPost: Post): b
}
return post.user_id === previousPost.user_id && // The post is by the same user
post.create_at - previousPost.create_at <= Posts.POST_COLLAPSE_TIMEOUT && // And was within a short time period
!(post.props && post.props.from_webhook) && !(previousPost.props && previousPost.props.from_webhook) && // And neither is from a webhook
(
(!(post.props && post.props.from_webhook) && !(previousPost.props && previousPost.props.from_webhook)) || // And neither is from a webhook
(post.props && previousPost.props && post.props.override_username == previousPost.props.override_username) // or they're from the same overridden user
) &&
!isSystemMessage(post) && !isSystemMessage(previousPost); // And neither is a system message
}

Expand Down

0 comments on commit 453fb65

Please sign in to comment.