Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
User authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
ukatama committed Apr 4, 2016
1 parent d26747f commit 1377168
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 83 deletions.
9 changes: 8 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
guest: false
database:
client: sqlite3
connection:
filename: tmp/db.sqlite
listen:
host: localhost
port: 8000
redis:
host: localhost
session:
resave: true
saveUninitialized: true
store: database
types:
sw2_character_ja: ソード・ワールド2.0/キャラクター
sw2_monster_ja: ソード・ワールド2.0/魔物
sw2_monster_ja: ソード・ワールド2.0/魔物
3 changes: 3 additions & 0 deletions config/development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
guest: true
session:
secret: hoge
1 change: 1 addition & 0 deletions config/production.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
guest: false
listen:
host: '0.0.0.0'
port: 80
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"body-parser": "^1.15.0",
"config": "^1.19.0",
"connect-livereload": "^0.5.4",
"connect-redis": "^3.0.2",
"connect-session-knex": "^1.0.22",
"express": "^4.13.4",
"express-session": "^1.13.0",
"jade": "^1.11.0",
"knex": "^0.10.0",
"lodash": "^4.6.1",
Expand Down
11 changes: 10 additions & 1 deletion src/components/character-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ import {Character} from '../shapes/character';
export const CharacterListItem = (props) => {
const {
id,
user_id,
name,
created,
modified,
} = props;

return (
<ListItem href={`/${id}`} primaryText={name} />
<ListItem
href={`/${id}`}
primaryText={name}
secondaryText={
`@${user_id} created:${created} modified:${modified}`
}
/>
);
};
CharacterListItem.propTypes = Character;
Expand Down
14 changes: 13 additions & 1 deletion src/components/character.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import AppBar from 'material-ui/lib/app-bar';
import IconButton from 'material-ui/lib/icon-button';
import Paper from 'material-ui/lib/paper';
import ChevronLeft from 'material-ui/lib/svg-icons/navigation/chevron-left';
import React, {PropTypes} from 'react';
import {Character as CharacterShape} from '../shapes/character';
import {SheetField} from './sheet-field';
Expand All @@ -10,6 +12,7 @@ export const Character = (props) => {
id,
data,
name,
readOnly,
type,
types,
user_id,
Expand All @@ -24,6 +27,7 @@ export const Character = (props) => {
<Sheet
data={data || {}}
id={id}
readOnly={readOnly}
onChange={onChange}
onDelete={onDelete}
onPush={onPush}
Expand All @@ -34,7 +38,14 @@ export const Character = (props) => {

return (
<div>
<AppBar title={name} />
<AppBar
iconElementLeft={
<IconButton onTouchTap={() => (location.href = '/')}>
<ChevronLeft />
</IconButton>
}
title={name}
/>
<Paper style={{margin: 16, padding: 16}}>
<SheetField
fullWidth
Expand All @@ -55,6 +66,7 @@ export const Character = (props) => {
);
};
Character.propTypes = Object.assign({
readOnly: PropTypes.bool.isRequired,
types: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
Expand Down
1 change: 1 addition & 0 deletions src/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const Home = (props) => {
iconElementRight={
<IconButton onTouchTap={onCreate}><Add /></IconButton>
}
showMenuIconButton={false}
title="Nekosheet"
/>
<CharacterList />
Expand Down
43 changes: 25 additions & 18 deletions src/components/item-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,37 @@ export const ItemList = (props) => {
);
});

const deleteElement = readOnly ? null : (
<Td>
<IconButton
onTouchTap={(e) => onDelete && onDelete(e, ikey)}
>
<Delete />
</IconButton>
</Td>
);

return (
<Tr key={ikey}>
{columnElements}
<Td>
<IconButton
disabled={readOnly}
onTouchTap={(e) => onDelete && onDelete(e, ikey)}
>
<Delete />
</IconButton>
</Td>
{deleteElement}
</Tr>
);
});

const appendElements = readOnly ? null : (
<Tr>
<Td colSpan={fields.length + 1}>
<FlatButton
style={{width: '100%'}}
onTouchTap={onAppend}
>
<Add />
</FlatButton>
</Td>
</Tr>
);

return (
<Table>
<Thead>
Expand All @@ -82,16 +98,7 @@ export const ItemList = (props) => {
{itemElements}
</Tbody>
<Tfoot>
<Tr>
<Td colSpan={fields.length + 1}>
<FlatButton
style={{width: '100%'}}
onTouchTap={onAppend}
>
<Add />
</FlatButton>
</Td>
</Tr>
{appendElements}
{children}
</Tfoot>
</Table>
Expand Down
2 changes: 1 addition & 1 deletion src/components/sheets/sw2_character_ja/ability.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {PropTypes} from 'react';
import {SheetField} from '../../sheet-field';
import {Table, Thead, Tbody, Tfoot, Tr, Td, Th} from '../../sheet-table';
import {Table, Thead, Tbody, Tr, Td, Th} from '../../sheet-table';

export const AbilityTable = ({data, readOnly, changeHandler}) => {
const lineElements = [
Expand Down
45 changes: 23 additions & 22 deletions src/components/sheets/sw2_character_ja/weapon.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import Add from 'material-ui/lib/svg-icons/content/add';
import Card from 'material-ui/lib/card/card';
import CardActions from 'material-ui/lib/card/card-actions';
import CardHeader from 'material-ui/lib/card/card-header';
import CardTitle from 'material-ui/lib/card/card-title';
import CardText from 'material-ui/lib/card/card-text';
import Delete from 'material-ui/lib/svg-icons/action/delete';
import FlatButton from 'material-ui/lib/flat-button';
import IconButton from 'material-ui/lib/icon-button';
import React, {PropTypes} from 'react';
import {SheetField} from '../../sheet-field';
import {Table, Thead, Tbody, Tfoot, Tr, Td, Th} from '../../sheet-table';
import {Table, Thead, Tbody, Tr, Td, Th} from '../../sheet-table';

export const WeaponTable = (props) => {
const {
Expand Down Expand Up @@ -45,6 +41,13 @@ export const WeaponTable = (props) => {
</Td>
);
});
const deleteElement = readOnly ? null : (
<FlatButton
label={<Delete />}
style={{width: '100%'}}
onTouchTap={removeHandler('weapons', i)}
/>
);

return (
<Card key={i} style={{margin: 16}}>
Expand Down Expand Up @@ -150,31 +153,29 @@ export const WeaponTable = (props) => {
<Thead><Tr><Th>2</Th>{impactHeaders}</Tr></Thead>
<Tbody><Tr><Th>*</Th>{impactElements}</Tr></Tbody>
</Table>
<div style={{diaplay: readOnly ? 'none' : null}}>
<FlatButton
label={<Delete />}
style={{width: '100%'}}
onTouchTap={removeHandler('weapons', i)}
/>
</div>
{deleteElement}
</CardText>
</Card>
);
});

const appendElement = readOnly ? null : (
<div style={{margin: '0 16px'}}>
<FlatButton
label="武器追加"
style={{width: '100%'}}
onTouchTap={pushHandler('weapons', {
weapon: '(新しい武器)',
critical: 10,
})}
/>
</div>
);

return (
<div>
{itemElements}
<div style={{display: readOnly ? 'none' : null, margin: '0 16px'}}>
<FlatButton
label="武器追加"
style={{width: '100%'}}
onTouchTap={pushHandler('weapons', {
weapon: '(新しい武器)',
critical: 10,
})}
/>
</div>
{appendElement}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/containers/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Character = connect(
(state) => ({
...state.character,
types: state.types,
readOnly: state.user.id !== state.character.user_id,
}),
(dispatch) => ({
onChange: (id, key, value) => put(`/${id}/${key}`, {id, key, value})
Expand Down
1 change: 1 addition & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const reducers = combineReducers({
characters: immutable([]),
dialogs,
types: immutable({}),
user: immutable({}),
});
3 changes: 3 additions & 0 deletions src/server/__tests__/test-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
describe('Server', () => {
jest.setMock('redis', {});

jest.setMock('express', jest.fn());
const express = require('express');
const app = jest.fn();
app.use = jest.fn();

jest.mock('http');
const http = require('http');
Expand Down
Loading

0 comments on commit 1377168

Please sign in to comment.