Entrance v0.4.3 Entrance
Provides authentication helpers that take advantage of the options configured in your config files.
Link to this section Summary
Functions
Authenticates an user by the default authenticable field (defined in your configurations) and password. Returns the user if the
user is found and the password is correct, otherwise nil. For example, if the default authenticable field configured is :email, it will try match with the :email field of user schema.
Authenticates an user by checking more than one field. Returns the user if the user is found and the password is correct, otherwise nil.
Receives an atom list as fields list, a value and a password. Authenticates a user by at least one field in the fields list. Returns the user if the user is found and the password is correct, otherwise nil.
Receives a tuple with an atom list and a value, a keyword list and a password.
Authenticates a user. Returns true if the user's password and the given
password match based on the security_module strategy configured, otherwise false.
Returns true if passed in conns assigns has a non-nil :current_user,
otherwise returns false.
Link to this section Functions
auth(user_module \\ nil, field_value, password)
Authenticates an user by the default authenticable field (defined in your configurations) and password. Returns the user if the
user is found and the password is correct, otherwise nil. For example, if the default authenticable field configured is :email, it will try match with the :email field of user schema.
Requires user_module, security_module, repo and default_authenticable_field to be configured via
Mix.Config.
Entrance.auth("joe@dirt.com", "brandyr00lz")
If you want to authenticate other modules, you can pass in the module directly.
Entrance.auth(Customer, "brandy@dirt.com", "super-password")
auth_by(user_module \\ nil, fields_values, password)
Authenticates an user by checking more than one field. Returns the user if the user is found and the password is correct, otherwise nil.
Requires user_module, security_module, and repo to be configured via
Mix.Config.
Entrance.auth_by([email: "joe@dirt.com", admin: true], "brandyr00lz")
If you want to authenticate other modules, you can pass in the module directly.
Entrance.auth_by(Customer, [nickname: "truehenrique", admin: true], "super-password")
auth_one(user_module \\ nil, list, value, password)
Receives an atom list as fields list, a value and a password. Authenticates a user by at least one field in the fields list. Returns the user if the user is found and the password is correct, otherwise nil.
Requires user_module, security_module, and repo to be configured via
Mix.Config.
Entrance.auth_one([:email, :nickname], "my-nickname", "my-password")
If you want to authenticate other modules, you can pass in the module directly.
Entrance.auth_one(Customer, [:nickname, :email], "my@email.com", "my-password")
auth_one_by(user_module \\ nil, arg, extra_fields_values, password)
Receives a tuple with an atom list and a value, a keyword list and a password.
First verify if there is a user with one of the atom list fields matching the value. If the user is found, verify if the user schema fields match with the keyword list values. If a user is found, the fields match, and the password is correct, returns the user, otherwise nil.
Requires user_module, security_module, and repo to be configured via
Mix.Config.
Entrance.auth_one_by({[:email, :nickname], "value"}, [admin: true] , "my-password")
If you want to authenticate other modules, you can pass in the module directly.
Entrance.auth_one_by(Customer, {[:email, :nickname], "value"}, [admin: true], "my-password")
auth_user(user, password)
Authenticates a user. Returns true if the user's password and the given
password match based on the security_module strategy configured, otherwise false.
Requires user_module, security_module, and repo to be configured via
Mix.Config.
user = Myapp.Repo.get(Myapp.User, 1)
Entrance.auth_user(user, "brandyr00lz")
logged_in?(conn)
Returns true if passed in conns assigns has a non-nil :current_user,
otherwise returns false.
Make sure your pipeline uses a login plug to fetch the current user for this function to work correctly..
user = Myapp.Repo.get(Myapp.User, 1)
Entrance.auth_user(user, "brandyr00lz")