Entrance v0.4.1 Entrance.Login.Session
Link to this section Summary
Functions
Returns the current user or nil based on :user_id
in the session.
Logs in given user by setting :user_id
on the session of passed in conn
. The user struct must have an :session_secret
field.
Logs out current user.
Link to this section Functions
Link to this function
get_current_user(conn)
Returns the current user or nil based on :user_id
in the session.
import Entrance.Login.Session
# ... your controller
login(conn, Repo.get(User, 1))
user = get_current_user(conn)
Link to this function
login(conn, user)
Logs in given user by setting :user_id
on the session of passed in conn
. The user struct must have an :session_secret
field.
import Entrance.Login.Session
# ... your controller
user = Repo.get(User, 1)
conn
|> login(user)
|> put_flash(:notice, "Successfully logged in")
|> redirect(to: "/")
Link to this function
logout(conn)
Logs out current user.
import Entrance.Login.Session
# ... your controller
conn
|> logout
|> put_flash(:notice, "Successfully logged out")
|> redirect(to: "/")