Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Sanders committed Dec 11, 2015
1 parent 28cab43 commit c0d355a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
80 changes: 75 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,78 @@
ExDjango
========
# ExDjango [![Build Status](https://travis-ci.org/nicksanders/exdjango.svg?branch=master)](https://travis-ci.org/nicksanders/exdjango)

[![Build Status](https://travis-ci.org/nicksanders/exdjango.svg?branch=master)](https://travis-ci.org/nicksanders/exdjango)
A few elixir libraries for working with django

#### A few elixir libraries for working with django
## Features

eg. Using Phoenix as a websocket server which needs to decrypt django's signed cookie to authenticate users
* Django cookie-based sessions
* Django redis cache sessions
* Django pbkdf2_sha256 passwords

## Installation

Add ex_django to your `mix.exs` dependencies other dependencies are optional depending on what features you want to use.

```elixir
defp deps do
[ {:ex_django, "~> 0.1.0"} ]
end
```

If you need cookie-based sessions you need to add poison

```elixir
{:poison, "~> 1.5.0"},
```

If you need redis sessions you need to add poison and exredis

```elixir
{:poison, "~> 1.5.0"},
{:exredis, "~> 0.2.0"},
```

If you need to read/write django passwords you need to add comeonin

```elixir
{:comeonin, "~> 1.6"},
```

## Django sessions

```elixir
# endpoint.ex
plug Plug.Session,
store: ExDjango.Session.Cookie,
key: "sessionid",
secret_key: "django-secret-key"
```

or

```elixir
# endpoint.ex
plug Plug.Session,
store: ExDjango.Session.Redis,
key: "sessionid"
```

get/set user id ("_auth_user_id" from django session)

```elixir
conn
|> ExDjango.Session.put_user(99)

conn
|> ExDjango.Session.get_user()
```


## Django passwords

```elixir
ExDjango.Pbkdf2.checkpw(password, user.password)

changeset
|> put_change(:password, ExDjango.Pbkdf2.hashpwsalt(changeset.params["plaintext_password"]))
|> repo.insert()
```
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ExDjango.Mixfile do

def project do
[app: :exdjango,
version: "0.0.1",
version: "0.1.0",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down

0 comments on commit c0d355a

Please sign in to comment.