Module m_identity

Manage identities of users.

Copyright © 2009-2013 Marc Worrell Date: 2009-04-25

Behaviours: zotonic_model.

Authors: Marc Worrell (marc@worrell.nl).

Description

Manage identities of users. An identity can be an username/password, openid, oauth credentials etc.

Data Types

bcrypt_hash()

bcrypt_hash() = {bcrypt, binary()}

hash()

hash() = bcrypt_hash() | sha1_salted_hash()

password()

password() = iodata()

sha1_salted_hash()

sha1_salted_hash() = {hash, binary(), binary()}

Function Index

check_username_pw/3Return the rsc_id with the given username/password.
check_username_pw/4Return the rsc_id with the given username/password.
delete/2
delete_by_type/3
delete_by_type_and_key/4
delete_username/2Delete an username from a resource.
ensure_username_pw/2Ensure that the user has an associated username and password.
generate_username/2
get/2Fetch a specific identity entry.
get_rsc/2Fetch all credentials belonging to the user "id".
get_rsc/3
get_rsc_by_type/3Fetch all credentials belonging to the user "id" and of a certain type.
get_username/1Return the username of the current user.
get_username/2Return the username of the resource id, undefined if no username.
hash/1Hash a password, using bcrypt.
hash_is_equal/2Compare if a password is the same as a hash.
insert/4Create an identity record.
insert/5
insert_single/4
insert_single/5
insert_unique/4Create an unique identity record.
insert_unique/5
is_email_verified/1Check if the primary email address of the user is verified.
is_email_verified/2
is_peer_allowed/1Check if the tcp/ip peer address is a allowed ip address.
is_reserved_name/1Prevent insert of reserved usernames.
is_user/2Check if the resource has any credentials that will make him/her an user.
is_valid_key/3
is_verified/2Check if there is a verified identity for the user, beyond the username_pw.
lookup_by_type_and_key/3
lookup_by_type_and_key_multi/3
lookup_by_username/2
lookup_by_verify_key/2
lookup_users_by_type_and_key/3
lookup_users_by_verified_type_and_key/3
m_get/3Fetch the value for the key from a model source.
merge/3Move the identities of two resources, the identities are removed from the source id.
needs_rehash/1Check if the password hash needs to be rehashed.
normalize_key/2
set_by_type/4
set_by_type/5
set_expired/3Mark the username_pw identity of an user as 'expired', this forces a prompt for a password reset on the next authentication.
set_username/3Change the username of the resource id, only possible if there is already an username/password set.
set_username_pw/4Set the username/password of a resource.
set_verified/2Set the verified flag on a record by identity id.
set_verified/4Set the verified flag on a record by rescource id, identity type and value (eg an user's email address).
set_verify_key/2

Function Details

check_username_pw/3

check_username_pw(Username::binary() | string(), Password::binary() | string(), Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}

Return the rsc_id with the given username/password. If succesful then updates the 'visited' timestamp of the entry.

check_username_pw/4

check_username_pw(Username::binary() | string(), Password::binary() | string(), QueryArgs::list() | map(), Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}

Return the rsc_id with the given username/password. If succesful then updates the 'visited' timestamp of the entry.

delete/2

delete(IdnId, Context) -> any()

delete_by_type/3

delete_by_type(Rsc::m_rsc:resource(), Type::atom(), Context::#context{}) -> ok

delete_by_type_and_key/4

delete_by_type_and_key(Rsc::m_rsc:resource(), Type::atom(), Key::atom(), Context::#context{}) -> ok

delete_username/2

delete_username(RscId::m_rsc:resource() | undefined, Context::z:context()) -> ok | {error, eacces | enoent}

Delete an username from a resource.

ensure_username_pw/2

ensure_username_pw(Id::m_rsc:resource(), Context::#context{}) -> ok | {error, term()}

Ensure that the user has an associated username and password

generate_username/2

generate_username(Id, Context) -> any()

get/2

get(IdnId, Context) -> any()

Fetch a specific identity entry.

get_rsc/2

get_rsc(Id::m_rsc:resource(), Context::#context{}) -> list()

Fetch all credentials belonging to the user "id"

get_rsc/3

get_rsc(Id::m_rsc:resource_id(), Type::atom() | binary(), Context::z:context()) -> list() | undefined

get_rsc_by_type/3

get_rsc_by_type(Id::m_rsc:resource(), Type::atom(), Context::#context{}) -> list()

Fetch all credentials belonging to the user "id" and of a certain type

get_username/1

get_username(Context::z:context()) -> binary() | undefined

Return the username of the current user

get_username/2

get_username(RscId::m_rsc:resource(), Context::z:context()) -> binary() | undefined

Return the username of the resource id, undefined if no username

hash/1

hash(Pw::password()) -> bcrypt_hash()

Hash a password, using bcrypt

hash_is_equal/2

hash_is_equal(Pw::password(), X2::hash()) -> boolean()

Compare if a password is the same as a hash.

insert/4

insert(Rsc::m_rsc:resource(), Type::atom(), Key::binary(), Context::#context{}) -> {ok, pos_integer()} | {error, invalid_key}

Create an identity record.

insert/5

insert(Rsc, Type, Key, Props, Context) -> any()

insert_single/4

insert_single(Rsc::m_rsc:resource(), Type::atom(), Key::binary(), Context::#context{}) -> {ok, pos_integer()} | {error, invalid_key}

insert_single/5

insert_single(Rsc, Type, Key, Props, Context) -> any()

insert_unique/4

insert_unique(RscId, Type, Key, Context) -> any()

Create an unique identity record.

insert_unique/5

insert_unique(RscId, Type, Key, Props, Context) -> any()

is_email_verified/1

is_email_verified(Context) -> any()

Check if the primary email address of the user is verified.

is_email_verified/2

is_email_verified(UserId, Context) -> any()

is_peer_allowed/1

is_peer_allowed(Context) -> any()

Check if the tcp/ip peer address is a allowed ip address

is_reserved_name/1

is_reserved_name(List) -> any()

Prevent insert of reserved usernames. See: http://tools.ietf.org/html/rfc2142 See: https://arstechnica.com/security/2015/03/bogus-ssl-certificate

is_user/2

is_user(Id::m_rsc:resource(), Context::z:context()) -> boolean()

Check if the resource has any credentials that will make him/her an user

is_valid_key/3

is_valid_key(Type::binary() | atom(), Key::undefined | binary() | string(), Context::z:context()) -> boolean()

is_verified/2

is_verified(RscId::m_rsc:resource_id(), Context::z:context()) -> boolean()

Check if there is a verified identity for the user, beyond the username_pw

lookup_by_type_and_key/3

lookup_by_type_and_key(Type, Key, Context) -> any()

lookup_by_type_and_key_multi/3

lookup_by_type_and_key_multi(Type, Key, Context) -> any()

lookup_by_username/2

lookup_by_username(Key, Context) -> any()

lookup_by_verify_key/2

lookup_by_verify_key(Key, Context) -> any()

lookup_users_by_type_and_key/3

lookup_users_by_type_and_key(Type, Key, Context) -> any()

lookup_users_by_verified_type_and_key/3

lookup_users_by_verified_type_and_key(Type, Key, Context) -> any()

m_get/3

m_get(Rest::list(), Msg::zotonic_model:opt_msg(), Context::z:context()) -> zotonic_model:return()

Fetch the value for the key from a model source

merge/3

merge(WinnerId::m_rsc:resource(), LoserId::m_rsc:resource(), Context::#context{}) -> ok | {error, term()}

Move the identities of two resources, the identities are removed from the source id.

needs_rehash/1

needs_rehash(X1::hash()) -> boolean()

Check if the password hash needs to be rehashed.

normalize_key/2

normalize_key(Type, Key) -> any()

set_by_type/4

set_by_type(RscId::m_rsc:resource_id(), Type::string() | binary(), Key::string() | binary(), Context::z:context()) -> ok

set_by_type/5

set_by_type(RscId::m_rsc:resource_id(), Type::string() | binary(), Key::string() | binary(), Props::term(), Context::z:context()) -> ok

set_expired/3

set_expired(UserId, X2, Context) -> any()

Mark the username_pw identity of an user as 'expired', this forces a prompt for a password reset on the next authentication.

set_username/3

set_username(Id::m_rsc:resource() | undefined, Username::binary() | string(), Context::z:context()) -> ok | {error, eacces | enoent | eexist}

Change the username of the resource id, only possible if there is already an username/password set

set_username_pw/4

set_username_pw(Id::m_rsc:resource() | undefined, Username::binary() | string(), Password::binary() | string(), Context::z:context()) -> ok | {error, Reason::term()}

Set the username/password of a resource. Replaces any existing username/password.

set_verified/2

set_verified(Id::m_rsc:resource_id(), Context::z:context()) -> ok | {error, notfound}

Set the verified flag on a record by identity id.

set_verified/4

set_verified(RscId::m_rsc:resource_id(), Type::string() | binary() | atom(), Key::string() | binary(), Context::z:context()) -> ok | {error, badarg}

Set the verified flag on a record by rescource id, identity type and value (eg an user's email address).

set_verify_key/2

set_verify_key(Id, Context) -> any()


Generated by EDoc