This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.Router do | |
| use Sling.Web, :router | |
| pipeline :browser do | |
| plug :accepts, ["html"] | |
| plug :fetch_session | |
| plug :fetch_flash | |
| plug :protect_from_forgery | |
| plug :put_secure_browser_headers | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.UserController do | |
| use Sling.Web, :controller | |
| alias Sling.User | |
| def create(conn, params) do | |
| changeset = User.registration_changeset(%User{}, params) | |
| case Repo.insert(changeset) do | |
| {:ok, user} -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.UserView do | |
| use Sling.Web, :view | |
| def render("user.json", %{user: user}) do | |
| %{ | |
| id: user.id, | |
| username: user.username, | |
| email: user.email, | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.SessionView do | |
| use Sling.Web, :view | |
| def render("show.json", %{user: user, jwt: jwt}) do | |
| %{ | |
| data: render_one(user, Sling.UserView, "user.json"), | |
| meta: %{token: jwt} | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.SessionController do | |
| use Sling.Web, :controller | |
| def create(conn, params) do | |
| case authenticate(params) do | |
| {:ok, user} -> | |
| new_conn = Guardian.Plug.api_sign_in(conn, user, :access) | |
| jwt = Guardian.Plug.current_token(new_conn) | |
| new_conn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| import React, { Component } from 'react'; | |
| import { BrowserRouter, Match, Miss } from 'react-router'; | |
| import Home from '../Home'; | |
| import NotFound from '../../components/NotFound'; | |
| import Login from '../Login'; | |
| import Signup from '../Signup'; | |
| class App extends Component { | |
| render() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| import React, { Component, PropTypes } from 'react'; | |
| import { connect } from 'react-redux'; | |
| import { signup } from '../../actions/session'; | |
| import SignupForm from '../../components/SignupForm'; | |
| import Navbar from '../../components/Navbar'; | |
| type Props = { | |
| signup: () => void, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| import React, { Component, PropTypes } from 'react'; | |
| import { connect } from 'react-redux'; | |
| import { login } from '../../actions/session'; | |
| import LoginForm from '../../components/LoginForm'; | |
| import Navbar from '../../components/Navbar'; | |
| type Props = { | |
| login: () => void, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| import React from 'react'; | |
| import { Link } from 'react-router'; | |
| import { css, StyleSheet } from 'aphrodite'; | |
| const styles = StyleSheet.create({ | |
| navbar: { | |
| display: 'flex', | |
| alignItems: 'center', | |
| padding: '0 1rem', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| import React, { Component } from 'react'; | |
| import { Field, reduxForm } from 'redux-form'; | |
| import { Link } from 'react-router'; | |
| import { css, StyleSheet } from 'aphrodite'; | |
| import Input from '../Input'; | |
| const styles = StyleSheet.create({ | |
| card: { | |
| maxWidth: '500px', |