View Source Teiserver.Account.User (Teiserver v0.0.4)

User

The database representation of a person using/playing your game; not to be confused with Teiserver.Connections.Client which represents their logged in and online state.

Attributes

  • :name - The name of the user
  • :email - The email of the user
  • :password - The encrypted password of the user; if you ever want to compare the password please make user of valid_password?/2 (which can be called from Teiserver.Account).
  • :groups - A list of the groups possessed by the user, these are used to inform permissions
  • :permissions - A list of the things the user is allowed to do, typically derived from a combination of groups and restrictions
  • :behaviour_score - Numerical score representing the behaviour of the user, a high score means they are better behaved
  • :trust_score - Numerical score representing the trustworthiness and accuracy of their reporting of other users
  • :social_score - Numerical score representing how much the user is liked or disliked by other players in general
  • :last_login_at - DateTime of the last time they logged in when already logged out (so a user who is already logged in will not get this updated if they login with a 2nd application)
  • :last_played_at - DateTime of the last time they played
  • :last_logout_at - DateTime of the last time they logged out
  • :restrictions - A list of the restrictions applied to the user account
  • :restricted_until - DateTime of when the restrictions to the user may need to be revised (e.g. when a moderation action expires)
  • :shadow_banned? - Boolean flag for spambots and trolls, when set to true the user should be allowed to see things as if fully logged in and be sent "success" type messages. In reality they are not able to effect change.

Summary

Functions

Given a User changeset, calculate what the permissions should be and update the changeset

The default method used to define match types

Provides a secure way to verify a password to prevent timing attacks.

Types

@type id() :: Ecto.UUID.t()
@type t() :: %Teiserver.Account.User{
  __meta__: term(),
  behaviour_score: integer() | nil,
  email: String.t(),
  extra_data: map() | nil,
  groups: [String.t()],
  id: id(),
  inserted_at: DateTime.t(),
  last_login_at: DateTime.t() | nil,
  last_logout_at: DateTime.t() | nil,
  last_played_at: DateTime.t() | nil,
  name: String.t(),
  password: String.t(),
  permissions: [String.t()],
  restricted_until: DateTime.t() | nil,
  restrictions: [String.t()],
  shadow_banned?: boolean(),
  smurf_of: term(),
  smurf_of_id: integer() | nil,
  social_score: integer() | nil,
  trust_score: integer() | nil,
  updated_at: DateTime.t()
}

Functions

Link to this function

calculate_user_permissions(changeset)

View Source
@spec calculate_user_permissions(Ecto.Changeset.t()) :: Ecto.Changeset.t()

Given a User changeset, calculate what the permissions should be and update the changeset

Link to this function

default_calculate_user_permissions(changeset)

View Source
@spec default_calculate_user_permissions(Ecto.Changeset.t()) :: Ecto.Changeset.t()

The default method used to define match types

Can be over-ridden using the config fn_calculate_user_permissions

Link to this function

valid_password?(plain_text_password, encrypted)

View Source
@spec valid_password?(User.t(), String.t()) :: boolean()

Provides a secure way to verify a password to prevent timing attacks.

Examples

iex> valid_password?(plaintext, user.password)
true

iex> valid_password?("bad_password", user.password)
false