EpochtalkServer.Models.User (epochtalk_server v0.1.0)
User model, for performing actions relating a user
Link to this section Summary
Functions
Gets a User from the database by id
Gets a User by username, from the database, with all of it's associations preloaded.
Appends the user Role to user.roles if no roles present. Strips all roles but
banned from user.roles if user is banned.
Clears the malicious score of a User by id, from the database
Creates a new User in the database, used for registration
Creates a new User in the database and assigns the superAdministrator Role, used for seeding
Checks if the provided User is malicious using the provided ip. If the User
is found to be malicious after checking BannedAddress records, the user's
malicious_score is updated and is assigned the banned Role, in the database
and in place. Otherwise the user is just returned with no change.
Creates a registration changeset for User model, returns an error changeset
if validation of username, email and password do not pass.
Validates with Argon2 that a User passhash matches the supplied password
Checks if User with email exists in the database
Checks if User with username exists in the database
Link to this section Types
@type t() :: %EpochtalkServer.Models.User{ __meta__: term(), ban_info: EpochtalkServer.Models.Ban.t() | term(), confirmation_token: String.t() | nil, created_at: NaiveDateTime.t() | nil, deleted: boolean() | nil, email: String.t() | nil, id: non_neg_integer() | nil, imported_at: NaiveDateTime.t() | nil, malicious_score: float() | nil, moderating: [EpochtalkServer.Models.BoardModerator.t()] | term(), passhash: String.t() | nil, password: String.t() | nil, password_confirmation: String.t() | nil, preferences: EpochtalkServer.Models.Preference.t() | term(), profile: EpochtalkServer.Models.Profile.t() | term(), reset_expiration: String.t() | nil, reset_token: String.t() | nil, roles: [EpochtalkServer.Models.Role.t()] | term(), smf_member: term(), updated_at: NaiveDateTime.t() | nil, username: String.t() | nil }
Link to this section Functions
by_id(id)
Gets a User from the database by id
by_username(username)
Gets a User by username, from the database, with all of it's associations preloaded.
Appends the user Role to user.roles if no roles present. Strips all roles but
banned from user.roles if user is banned.
clear_malicious_score_by_id(id)
@spec clear_malicious_score_by_id(id :: integer()) :: {non_neg_integer(), nil}
Clears the malicious score of a User by id, from the database
create(attrs)
@spec create(attrs :: map()) :: {:ok, user :: t()} | {:error, Ecto.Changeset.t()}
Creates a new User in the database, used for registration
create(attrs, admin)
@spec create(attrs :: map(), admin :: boolean()) :: {:ok, user :: t()} | {:error, Ecto.Changeset.t()}
Creates a new User in the database and assigns the superAdministrator Role, used for seeding
handle_malicious_user(user, ip)
@spec handle_malicious_user(user :: t(), ip :: tuple()) :: {:ok, user :: t()} | {:error, :ban_error}
Checks if the provided User is malicious using the provided ip. If the User
is found to be malicious after checking BannedAddress records, the user's
malicious_score is updated and is assigned the banned Role, in the database
and in place. Otherwise the user is just returned with no change.
registration_changeset(user, attrs)
@spec registration_changeset(user :: t(), attrs :: map() | nil) :: Ecto.Changeset.t()
Creates a registration changeset for User model, returns an error changeset
if validation of username, email and password do not pass.
valid_password?(user, password)
Validates with Argon2 that a User passhash matches the supplied password
with_email_exists?(email)
@spec with_email_exists?(email :: String.t()) :: true | false
Checks if User with email exists in the database
with_username_exists?(username)
@spec with_username_exists?(username :: String.t()) :: true | false
Checks if User with username exists in the database