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 { Match, Redirect } from 'react-router'; | |
| type Props = { | |
| component: any, | |
| pattern: string, | |
| exactly?: boolean, | |
| isAuthenticated: boolean, | |
| willAuthenticate: boolean, |
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 { Match, Redirect } from 'react-router'; | |
| type Props = { | |
| component: any, | |
| pattern: string, | |
| exactly?: boolean, | |
| isAuthenticated: boolean, | |
| willAuthenticate: boolean, |
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, Miss } from 'react-router'; | |
| import { connect } from 'react-redux'; | |
| import { authenticate, unauthenticate } from '../../actions/session'; | |
| import Home from '../Home'; | |
| import NotFound from '../../components/NotFound'; | |
| import Login from '../Login'; | |
| import Signup from '../Signup'; | |
| import MatchAuthenticated from '../../components/MatchAuthenticated'; |
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
| export function authenticate() { | |
| return (dispatch) => { | |
| dispatch({ type: 'AUTHENTICATION_REQUEST' }); | |
| return api.post('/sessions/refresh') | |
| .then((response) => { | |
| setCurrentUser(dispatch, response); | |
| }) | |
| .catch(() => { | |
| localStorage.removeItem('token'); | |
| window.location = '/login'; |
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
| const initialState = { | |
| isAuthenticated: false, | |
| willAuthenticate: true, | |
| currentUser: {}, | |
| }; | |
| export default function (state = initialState, action) { | |
| switch (action.type) { | |
| case 'AUTHENTICATION_REQUEST': | |
| return { |
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.Repo.Migrations.CreateRoom do | |
| use Ecto.Migration | |
| def change do | |
| create table(:rooms) do | |
| add :name, :string, null: false | |
| add :topic, :string, default: "" | |
| timestamps() | |
| 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.Repo.Migrations.CreateUserRoom do | |
| use Ecto.Migration | |
| def change do | |
| create table(:user_rooms) do | |
| add :user_id, references(:users, on_delete: :nothing), null: false | |
| add :room_id, references(:rooms, on_delete: :nothing), null: false | |
| timestamps() | |
| 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.UserRoom do | |
| use Sling.Web, :model | |
| schema "user_rooms" do | |
| belongs_to :user, Sling.User | |
| belongs_to :room, Sling.Room | |
| timestamps() | |
| 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.Room do | |
| use Sling.Web, :model | |
| schema "rooms" do | |
| field :name, :string | |
| field :topic, :string | |
| many_to_many :users, Sling.User, join_through: "user_rooms" | |
| timestamps() | |
| 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
| get "/users/:id/rooms", UserController, :rooms | |
| resources "/rooms", RoomController, only: [:index, :create] | |
| post "/rooms/:id/join", RoomController, :join |