Change models, new migrations, fix front and make tests work

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-01-13 23:33:03 +01:00
parent 92d2045735
commit 20cd1bb579
186 changed files with 2982 additions and 3214 deletions

View file

@ -27,5 +27,11 @@ config :logger, :console,
import_config "#{Mix.env}.exs"
config :eventos, EventosWeb.Guardian,
issuer: "Eventos",
issuer: "eventos",
secret_key: "ty0WM7YBE3ojvxoUQxo8AERrNpfbXnIJ82ovkPdqbUFw31T5LcK8wGjaOiReVQjo"
config :guardian, Guardian.DB,
repo: Eventos.Repo,
schema_name: "guardian_tokens", # default
token_types: ["refresh_token"], # store all token types if not set
sweep_interval: 60 # default: 60 minutes

View file

@ -50,6 +50,7 @@ config :phoenix, :stacktrace_depth, 20
# Configure your database
config :eventos, Eventos.Repo,
adapter: Ecto.Adapters.Postgres,
types: Eventos.PostgresTypes,
username: "elixir",
password: "elixir",
database: "eventos_dev",

View file

@ -7,7 +7,10 @@ config :eventos, EventosWeb.Endpoint,
server: false
# Print only warnings and errors during test
config :logger, level: :warn
config :logger,
backends: [:console],
compile_time_purge_level: :debug,
level: :info
# Configure your database
config :eventos, Eventos.Repo,
@ -16,4 +19,5 @@ config :eventos, Eventos.Repo,
password: "elixir",
database: "eventos_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
pool: Ecto.Adapters.SQL.Sandbox,
types: Eventos.PostgresTypes

View file

@ -4,7 +4,7 @@ var path = require('path')
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../../lib/eventos_web/templates/app/index.html.eex'),
index: path.resolve(__dirname, '../../lib/eventos_web/templates/page/index.html.eex'),
assetsRoot: path.resolve(__dirname, '../../priv/static'),
assetsSubDirectory: '',
assetsPublicPath: '/',

View file

@ -4,11 +4,11 @@
<link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBF37pw38j0giICt73TCAPNogc07Upe_Q4&libraries=places"></script>
<meta charset="utf-8">
<title>libre-event</title>
<title>Eventos</title>
</head>
<body>
<noscript>
Mets du JS.
You need to activate your JS doug.
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->

6
js/package-lock.json generated
View file

@ -13648,9 +13648,9 @@
}
},
"vuetify": {
"version": "0.17.6",
"resolved": "https://registry.npmjs.org/vuetify/-/vuetify-0.17.6.tgz",
"integrity": "sha512-geIGnXjYEhUn1dr+g8FCFqvV6xUbALXNJ3UZQ32T0SJdGJh/JLsScINTxV+Pxt1F36s+YRnuFyHLiFOSnuVzjA=="
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmjs.org/vuetify/-/vuetify-1.0.0-beta.2.tgz",
"integrity": "sha512-eM61PPNwM0lXYaUzY0MXA7sp/N4wqxlEMcALsOBneLObVS+OgpX4Zszb7HqAOSVXipNRSP8X5ZV5TgbZscly1Q=="
},
"vuetify-google-autocomplete": {
"version": "1.1.0",

View file

@ -21,7 +21,7 @@
"vue-markdown": "^2.2.4",
"vue-router": "^3.0.1",
"vue2-google-maps": "^0.8.4",
"vuetify": "^0.17.6",
"vuetify": "^1.0.0-beta.2",
"vuetify-google-autocomplete": "^1.1.0",
"vuex": "^2.5.0",
"vuex-i18n": "1.8.0"

View file

@ -76,7 +76,6 @@
<script>
import auth from '@/auth/index';
import NavBar from '@/components/NavBar';
export default {
@ -105,15 +104,7 @@ export default {
show_new_event_button: false,
};
},
created() {
this.checkAuthMethod();
},
methods: {
checkAuthMethod() {
if (auth.checkAuth(this.$store)) {
this.show_new_event_button = true;
}
},
showMenuItem(elem) {
return elem !== null && this.$store.state.user && this.$store.state.user.roles !== undefined ? this.$store.state.user.roles.includes(elem) : true;
},

View file

@ -1,6 +1,6 @@
import { API_HOST, API_PATH } from './_entrypoint';
const jsonLdMimeType = 'application/ld+json';
const jsonLdMimeType = 'application/json';
export default function eventFetch(url, store, optionsarg = {}) {
const options = optionsarg;

View file

@ -1,87 +1,61 @@
import router from '../router/index';
import { API_HOST, API_PATH } from '../api/_entrypoint';
// URL and endpoint constants
const LOGIN_URL = `${API_HOST}${API_PATH}/login`;
const SIGNUP_URL = `${API_HOST}${API_PATH}/users/`;
const CHECK_AUTH = `${API_HOST}${API_PATH}/users/`;
const CHECK_AUTH = `${API_HOST}${API_PATH}/user/`;
const REFRESH_TOKEN = `${API_HOST}${API_PATH}/token/refresh`;
function AuthError(field, message) {
this.field = field;
this.message = message;
}
AuthError.prototype.toString = function AuthErrorToString() {
return `AuthError: ${this.message}`;
};
export default {
// User object will let us check authentication status
user: false,
authenticated: false,
token: false,
// Send a request to the login URL and save the returned JWT
login(creds, $store, redirect, error) {
login(creds, success, error) {
fetch(LOGIN_URL, { method: 'POST', body: creds, headers: { 'Content-Type': 'application/json' } })
.then(response => response.json())
.then((data) => {
if (data.code >= 300) {
throw new AuthError(null, data.message);
.then((response) => {
if (response.status === 200) {
return response.json();
}
$store.commit('LOGIN_USER');
throw response.json();
})
.then((data) => {
localStorage.setItem('token', data.token);
localStorage.setItem('refresh_token', data.refresh_token);
this.getUser(
$store,
() => router.push(redirect)
);
}).catch((err) => {
error(err);
});
// localStorage.setItem('refresh_token', data.refresh_token);
return success(data);
})
.catch(err => error(err));
},
signup(creds, $store, redirect, error) {
signup(creds, success, error) {
fetch(SIGNUP_URL, { method: 'POST', body: creds, headers: { 'Content-Type': 'application/json' } })
.then(response => response.json())
.then((response) => {
if (response.status === 200) {
return response.json();
}
throw response.json();
})
.then((data) => {
if (data.error) {
throw new AuthError(data.error.field, data.error.message);
}
$store.commit('LOGIN_USER');
localStorage.setItem('token', data.token);
localStorage.setItem('refresh_token', data.refresh_token);
// localStorage.setItem('refresh_token', data.refresh_token);
if (redirect) {
router.push(redirect);
}
}).catch((err) => {
error(err);
});
return success(data);
}).catch(err => error(err));
},
refreshToken(store, successHandler, errorHandler) {
const refreshToken = localStorage.getItem('refresh_token');
console.log("We are refreshing the jwt token");
fetch(REFRESH_TOKEN, { method: 'POST', body: JSON.stringify({refresh_token: refreshToken}), headers: { 'Content-Type': 'application/json' }})
console.log('We are refreshing the jwt token');
fetch(REFRESH_TOKEN, { method: 'POST', body: JSON.stringify({ refresh_token: refreshToken }), headers: { 'Content-Type': 'application/json' } })
.then((response) => {
if (response.ok) {
return response.json();
} else {
errorHandler('Error while authenticating');
}
return errorHandler('Error while authenticating');
})
.then((response) => {
console.log("We have a new token");
console.log('We have a new token');
this.authenticated = true;
store.commit('LOGIN_USER', response);
localStorage.setItem('token', response.token);
console.log("Let's try to auth again");
this.getUser(store, successHandler, errorHandler);
successHandler();
});
},
@ -114,19 +88,8 @@ export default {
return expirationDate < new Date();
},
checkAuth(store = null) {
const token = localStorage.getItem('token');
if (store && token) {
this.getUser(store,() => null, () => null);
}
/* if (!!token && store && !this.isTokenExpired(token)) {
this.refreshToken(store, () => null, () => null);
} */
return !!token;
},
getUser(store, successHandler, errorHandler) {
console.log("We are checking the auth");
console.log('We are checking the auth');
this.token = localStorage.getItem('token');
const options = {};
options.headers = new Headers();
@ -135,15 +98,13 @@ export default {
.then((response) => {
if (response.ok) {
return response.json();
} else {
errorHandler('Error while authenticating');
}
})
.then((response) => {
return errorHandler('Error while authenticating');
}).then((response) => {
this.authenticated = true;
console.log(response);
store.commit('SAVE_USER', response);
successHandler();
store.commit('LOAD_USER', response.data);
return successHandler();
});
},

View file

@ -29,11 +29,16 @@
:src="account.avatarRemoteUrl"
>
</v-avatar>
<v-card-title class="pl-5 pt-5">
<div class="display-1 pl-5 pt-5">@{{ account.username }}<span v-if="account.server">@{{ account.server.address }}</span></div>
</v-card-title>
<v-card-text v-if="account.description" v-html="account.description"></v-card-text>
</div>
<v-container fluid grid-list-lg>
<v-layout row>
<v-flex xs7>
<div class="headline">{{ account.display_name }}</div>
<div><span class="subheading">@{{ account.username }}</span><span v-if="account.server">@{{ account.server.address }}</span></div>
<v-card-text v-if="account.description" v-html="account.description"></v-card-text>
</v-flex>
</v-layout>
</v-container>
</v-layout>
<v-list three-line>
<v-list-tile>
@ -69,7 +74,7 @@
</v-list-tile-content>
</v-list-tile>
</v-list>
<v-container fluid grid-list-md v-if="account.participatingEvents.length > 0">
<v-container fluid grid-list-md v-if="account.participatingEvents && account.participatingEvents.length > 0">
<v-subheader>Participated at</v-subheader>
<v-layout row wrap>
<v-flex v-for="event in account.participatingEvents" :key="event.id">
@ -110,7 +115,7 @@
</v-flex>
</v-layout>
</v-container>
<v-container fluid grid-list-md v-if="account.organizingEvents.length > 0">
<v-container fluid grid-list-md v-if="account.organizingEvents && account.organizingEvents.length > 0">
<v-subheader>Organized events</v-subheader>
<v-layout row wrap>
<v-flex v-for="event in account.organizingEvents" :key="event.id">
@ -178,11 +183,12 @@ export default {
},
methods: {
fetchData() {
eventFetch('/accounts/' + this.id, this.$store)
eventFetch(`/accounts/${this.id}`, this.$store)
.then(response => response.json())
.then((response) => {
this.account = response;
this.account = response.data;
this.loading = false;
console.log(this.account);
})
}
}

View file

@ -4,11 +4,10 @@
<v-form>
<v-text-field
label="Name of the category"
v-model="category.name"
v-model="category.title"
:counter="100"
required
></v-text-field>
<input type="file" @change="processFile($event.target)">
</v-form>
<v-btn color="primary" @click="create">Create category</v-btn>
</div>
@ -22,32 +21,20 @@
data() {
return {
category: {
name: '',
imageDataUri: null,
title: '',
},
};
},
methods: {
create() {
const router = this.$router;
eventFetch('/categories', this.$store, { method: 'POST', body: JSON.stringify(this.category) })
eventFetch('/categories', this.$store, { method: 'POST', body: JSON.stringify({ category: this.category }) })
.then(response => response.json())
.then(() => {
this.loading = false;
router.push('/category')
});
},
processFile(target) {
const reader = new FileReader();
const file = target.files[0];
reader.addEventListener('load', () => {
this.category.imageDataUri = reader.result;
});
if (file) {
reader.readAsDataURL(file);
}
}
},
};
</script>

View file

@ -11,7 +11,7 @@
</v-card-media>
<v-card-title primary-title>
<div>
<h3 class="headline mb-0">{{ category.name }}</h3>
<h3 class="headline mb-0">{{ category.title }}</h3>
<div>{{ category.description }}</div>
</div>
</v-card-title>
@ -49,9 +49,9 @@
fetchData() {
eventFetch('/categories', this.$store)
.then(response => response.json())
.then((data) => {
.then((response) => {
this.loading = false;
this.categories = data['hydra:member'];
this.categories = response.data;
});
},
deleteCategory(categoryId) {

View file

@ -36,7 +36,7 @@
<v-select
v-bind:items="categories"
v-model="event.category"
item-text="name"
item-text="title"
item-value="@id"
label="Categories"
single-line
@ -62,7 +62,7 @@
<v-stepper-step step="2" :complete="e1 > 2">Date and place</v-stepper-step>
<v-stepper-content step="2">
Event starts at:
<v-text-field type="datetime-local" v-model="event.startDate"></v-text-field>
<v-text-field type="datetime-local" v-model="event.begins_on"></v-text-field>
<!--<v-layout row wrap>
<v-flex md6>
<v-dialog
@ -113,7 +113,7 @@
</v-flex>
</v-layout>-->
Event ends at:
<v-text-field type="datetime-local" v-model="event.endDate"></v-text-field>
<v-text-field type="datetime-local" v-model="event.ends_on"></v-text-field>
<!--<v-layout row wrap>
<v-flex md6>
<v-dialog
@ -216,8 +216,8 @@
event: {
title: '',
description: '',
startDate: new Date(),
endDate: new Date(),
begins_on: new Date(),
ends_on: new Date(),
seats: 0,
address: {
description: null,
@ -261,12 +261,12 @@
// '@type': 'Tag',
});
});
this.event.organizer = "/accounts/" + this.$store.state.user.account.id;
this.event.participants = ["/accounts/" + this.$store.state.user.account.id];
this.event.organizer_id = this.$store.state.user.account.id;
this.event.participants = [this.$store.state.user.account.id];
this.event.price = parseFloat(this.event.price);
if (this.id === undefined) {
eventFetch('/events', this.$store, {method: 'POST', body: JSON.stringify(this.event)})
eventFetch('/events', this.$store, {method: 'POST', body: JSON.stringify({ event: this.event })})
.then(response => response.json())
.then((data) => {
this.loading = false;
@ -284,17 +284,17 @@
fetchCategories() {
eventFetch('/categories', this.$store)
.then(response => response.json())
.then((data) => {
.then((response) => {
this.loading = false;
this.categories = data['hydra:member'];
this.categories = response.data;
});
},
fetchTags() {
eventFetch('/tags', this.$store)
.then(response => response.json())
.then((data) => {
.then((response) => {
this.loading = false;
data['hydra:member'].forEach((tag) => {
response.data.forEach((tag) => {
this.tagsFetched.push(tag.name);
});
});

View file

@ -26,7 +26,7 @@
<div class="headline">{{ event.title }}</div>
</v-card-title>
<v-container>
<span class="grey--text">{{ event.startDate | formatDate }} à <router-link :to="{name: 'EventList', params: {location: geocode(event.address.geo.latitude, event.address.geo.longitude, 10) }}">{{ event.address.addressLocality }}</router-link></span><br>
<!--<span class="grey&#45;&#45;text">{{ event.startDate | formatDate }} à <router-link :to="{name: 'EventList', params: {location: geocode(event.address.geo.latitude, event.address.geo.longitude, 10) }}">{{ event.address.addressLocality }}</router-link></span><br>-->
<p><vue-markdown>{{ event.description }}</vue-markdown></p>
<p v-if="event.organizer">Organisé par <router-link :to="{name: 'Account', params: {'id': event.organizer.id}}">{{ event.organizer.username }}</router-link></p>
</v-container>
@ -93,9 +93,9 @@
this.locationChip = true;
eventFetch(queryString, this.$store)
.then(response => response.json())
.then((data) => {
.then((response) => {
this.loading = false;
this.events = data['hydra:member'];
this.events = response.data;
});
},
deleteEvent(id) {

View file

@ -98,7 +98,7 @@
.then(response => response.json())
.then((data) => {
this.loading = false;
this.categories = data['hydra:member'];
this.categories = data;
});
},
getAddressData: function (addressData) {

View file

@ -58,7 +58,7 @@
.then(response => response.json())
.then((data) => {
this.loading = false;
this.groups = data['hydra:member'];
this.groups = data;
});
},
deleteEvent(id) {

View file

@ -1,6 +1,6 @@
<template>
<v-container>
<h1 class="welcome" v-if="$store.state.user">{{ $t("home.welcome", { 'username': $store.state.user.username}) }}</h1>
<h1 class="welcome" v-if="$store.state.user">{{ $t("home.welcome", { 'username': this.displayed_name }) }}</h1>
<h1 class="welcome" v-else>{{ $t("home.welcome_off", { 'username': $store.state.user.username}) }}</h1>
<router-link :to="{ name: 'EventList' }">{{ $t('home.events') }}</router-link>
<router-link v-if="$store.state.user === false" :to="{ name: 'Login' }">{{ $t('home.login') }}</router-link>
@ -48,12 +48,17 @@ export default {
mounted() {
// this.fetchLocations();
},
computed: {
displayed_name: function() {
return this.$store.state.user.account.display_name === null ? this.$store.state.user.account.username : this.$store.state.user.account.display_name
},
},
methods: {
fetchLocations() {
eventFetch('/locations', this.$store)
.then((response) => (response.json()))
.then((response) => {
this.locations = response['hydra:member'];
this.locations = response;
});
},
geoLocalize() {

View file

@ -65,10 +65,19 @@
methods: {
loginAction(e) {
e.preventDefault();
auth.login(JSON.stringify(this.credentials), this.$store, '/', (error) => {
auth.login(JSON.stringify(this.credentials), (data) => {
this.$store.commit('LOGIN_USER', data.user);
this.$router.push({ name: 'Home' });
}, (error) => {
Promise.resolve(error).then((errorMsg) => {
console.log(errorMsg);
this.error.show = true;
this.error.text = error.message;
this.error.field[error.field] = true;
this.error.text = this.$t(errorMsg.display_error);
}).catch((e) => {
console.log(e);
this.error.show = true;
this.error.text = e.message;
});
});
},
},

View file

@ -58,7 +58,7 @@
</v-card-actions>
</v-card>
</v-menu>
<v-btn flat @click="$router.push({name: 'Account', params: {'id': getUser().account.id}})" v-if="$store.state.isLogged && getUser()">{{ getUser().username }}</v-btn>
<v-btn flat @click="$router.push({name: 'Account', params: {'id': getUser().account.id}})" v-if="$store.state.user">{{ this.displayed_name }}</v-btn>
</v-toolbar>
</template>
@ -95,6 +95,11 @@
}
}
},
computed: {
displayed_name: function() {
return this.$store.state.user.account.display_name === null ? this.$store.state.user.account.username : this.$store.state.user.account.display_name
},
},
methods: {
getUser() {
return this.$store.state.user === undefined ? false : this.$store.state.user;

View file

@ -72,7 +72,11 @@
methods: {
registerAction(e) {
e.preventDefault();
auth.signup(JSON.stringify(this.credentials), this.$store, {name: 'Home'}, (error) => {
auth.signup(JSON.stringify(this.credentials), (response) => {
console.log(response);
this.$store.commit('LOGIN_USER', response.user);
this.$router.push({ name: 'Home' });
}, (error) => {
this.error.show = true;
this.error.text = error.message;
this.error.field[error.field] = true;

View file

@ -12,4 +12,9 @@ export default {
title: "Votre liste d'événements",
},
},
session: {
error: {
bad_login: 'Erreur lors de la connexion : Votre nom d\'utilisateur ou votre mot de passe est incorrect',
},
},
};

View file

@ -10,8 +10,9 @@ import VuexI18n from 'vuex-i18n';
import 'vuetify/dist/vuetify.min.css';
import App from '@/App';
import router from '@/router';
import storeData from './store/index';
import translations from './i18n/index';
import storeData from '@/store/index';
import translations from '@/i18n/index';
import auth from '@/auth';
Vue.config.productionTip = false;
@ -46,6 +47,19 @@ Object.entries(translations).forEach((key) => {
Vue.i18n.set(language);
Vue.i18n.fallback('en');
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiredAuth) && store.state.user === undefined || store.state.user == null) {
next({
name: 'Login',
query: { redirect: to.fullPath }
});
} else {
next();
}
});
auth.getUser(store, () => {}, () => {});
/* eslint-disable no-new */
new Vue({
el: '#app',

View file

@ -14,7 +14,6 @@ import Account from '@/components/Account/Account';
import CreateGroup from '@/components/Group/Create';
import Group from '@/components/Group/Group';
import GroupList from '@/components/Group/GroupList';
import Auth from '@/auth/index';
Vue.use(Router);
@ -118,16 +117,4 @@ const router = new Router({
],
});
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiredAuth) && !Auth.checkAuth()) {
console.log('needs login');
next({
path: '/',
query: { redirect: to.fullPath }
});
} else {
next();
}
});
export default router;

View file

@ -1,21 +1,26 @@
import { LOGIN_USER, LOGOUT_USER, SAVE_USER } from './mutation-types';
import { LOGIN_USER, LOGOUT_USER, LOAD_USER } from './mutation-types';
const state = {
isLogged: !!localStorage.getItem('token'),
user: false,
};
/* eslint-disable */
const mutations = {
[LOGIN_USER](state) {
[LOGIN_USER](state, user) {
state.isLogged = true;
state.user = user;
},
[LOAD_USER](state, user) {
state.user = user;
},
[LOGOUT_USER](state) {
state.isLogged = false;
},
[SAVE_USER](state, user) {
state.user = user;
state.user = null;
},
};
/* eslint-enable */
export default { state, mutations };

View file

@ -1,3 +1,3 @@
export const LOGIN_USER = 'LOGIN_USER';
export const LOAD_USER = 'LOAD_USER';
export const LOGOUT_USER = 'LOGOUT_USER';
export const SAVE_USER = 'SAVE_USER';

View file

@ -1,22 +1,23 @@
defmodule Eventos.Accounts.Account do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Accounts.{Account, GroupAccount, GroupRequest, Group, User}
alias Eventos.Accounts.{Account, User}
alias Eventos.Groups.{Group, Member, Request}
alias Eventos.Events.Event
schema "accounts" do
field :username, :string
field :description, :string
field :display_name, :string
field :domain, :string, default: nil
field :domain, :string
field :private_key, :string
field :public_key, :string
field :suspended, :boolean, default: false
field :uri, :string
field :url, :string
has_many :organized_events, Event
many_to_many :groups, Group, join_through: GroupAccount
has_many :group_request, GroupRequest
field :username, :string
has_many :organized_events, Event, [foreign_key: :organizer_id]
many_to_many :groups, Group, join_through: Member
has_many :group_request, Request
has_one :user, User
timestamps()
@ -26,7 +27,14 @@ defmodule Eventos.Accounts.Account do
def changeset(%Account{} = account, attrs) do
account
|> cast(attrs, [:username, :domain, :display_name, :description, :private_key, :public_key, :suspended, :uri, :url])
|> validate_required([:username, :display_name, :description, :private_key, :public_key, :suspended])
|> validate_required([:username, :public_key, :suspended, :uri, :url])
|> unique_constraint(:username, name: :accounts_username_domain_index)
end
def registration_changeset(%Account{} = account, attrs) do
account
|> cast(attrs, [:username, :domain, :display_name, :description, :private_key, :public_key, :suspended, :uri, :url])
|> validate_required([:username, :public_key, :suspended, :uri, :url])
|> unique_constraint(:username)
end
end

View file

@ -4,130 +4,8 @@ defmodule Eventos.Accounts do
"""
import Ecto.Query, warn: false
import Logger
alias Eventos.Repo
alias Eventos.Accounts.User
@doc """
Returns the list of users.
## Examples
iex> list_users()
[%User{}, ...]
"""
def list_users do
Repo.all(User)
end
@doc """
Gets a single user.
Raises `Ecto.NoResultsError` if the User does not exist.
## Examples
iex> get_user!(123)
%User{}
iex> get_user!(456)
** (Ecto.NoResultsError)
"""
def get_user!(id), do: Repo.get!(User, id)
@doc """
Get an user by email
"""
def find(email) do
Repo.get_by!(User, email: email)
end
@doc """
Authenticate user
"""
def authenticate(%{user: user, password: password}) do
# Does password match the one stored in the database?
Logger.debug(user.password_hash)
Logger.debug(password)
case Comeonin.Argon2.checkpw(password, user.password_hash) do
true ->
# Yes, create and return the token
EventosWeb.Guardian.encode_and_sign(user)
_ ->
# No, return an error
{:error, :unauthorized}
end
end
@doc """
Creates a user.
## Examples
iex> create_user(%{field: value})
{:ok, %User{}}
iex> create_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_user(attrs \\ %{}) do
%User{}
|> User.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a user.
## Examples
iex> update_user(user, %{field: new_value})
{:ok, %User{}}
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_user(%User{} = user, attrs) do
user
|> User.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a User.
## Examples
iex> delete_user(user)
{:ok, %User{}}
iex> delete_user(user)
{:error, %Ecto.Changeset{}}
"""
def delete_user(%User{} = user) do
Repo.delete(user)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking user changes.
## Examples
iex> change_user(user)
%Ecto.Changeset{source: %User{}}
"""
def change_user(%User{} = user) do
User.changeset(user, %{})
end
import Logger
alias Eventos.Accounts.Account
@ -158,7 +36,14 @@ defmodule Eventos.Accounts do
** (Ecto.NoResultsError)
"""
def get_account!(id), do: Repo.get!(Account, id)
def get_account!(id) do
account = Repo.get!(Account, id)
end
def get_account_with_everything!(id) do
account = Repo.get!(Account, id)
|> Repo.preload :organized_events
end
@doc """
Creates a account.
@ -225,291 +110,177 @@ defmodule Eventos.Accounts do
Account.changeset(account, %{})
end
alias Eventos.Accounts.Group
alias Eventos.Accounts.User
@doc """
Returns the list of groups.
Returns the list of users.
## Examples
iex> list_groups()
[%Group{}, ...]
iex> list_users()
[%User{}, ...]
"""
def list_groups do
Repo.all(Group)
def list_users do
Repo.all(User)
end
def list_users_with_accounts do
Repo.all(User)
|> Repo.preload :account
end
@doc """
Gets a single group.
Gets a single user.
Raises `Ecto.NoResultsError` if the Group does not exist.
Raises `Ecto.NoResultsError` if the User does not exist.
## Examples
iex> get_group!(123)
%Group{}
iex> get_user!(123)
%User{}
iex> get_group!(456)
iex> get_user!(456)
** (Ecto.NoResultsError)
"""
def get_group!(id), do: Repo.get!(Group, id)
def get_user!(id), do: Repo.get!(User, id)
def get_user_with_account!(id) do
Repo.get!(User, id)
|> Repo.preload :account
end
@doc """
Creates a group.
Get an user by email
"""
def find_by_email(email) do
user = Repo.get_by(User, email: email)
|> Repo.preload :account
end
@doc """
Authenticate user
"""
def authenticate(%{user: user, password: password}) do
# Does password match the one stored in the database?
case Comeonin.Argon2.checkpw(password, user.password_hash) do
true ->
# Yes, create and return the token
EventosWeb.Guardian.encode_and_sign(user)
_ ->
# No, return an error
{:error, :unauthorized}
end
end
@doc """
Register user
"""
def register(%{email: email, password: password, username: username}) do
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
account = Eventos.Accounts.Account.registration_changeset(%Eventos.Accounts.Account{}, %{
username: username,
domain: nil,
private_key: privkey,
public_key: pubkey,
uri: "h",
url: "h"
})
user = Eventos.Accounts.User.registration_changeset(%Eventos.Accounts.User{}, %{
email: email,
password: password
})
account_with_user = Ecto.Changeset.put_assoc(account, :user, user)
try do
coucou = Eventos.Repo.insert!(account_with_user)
user = find_by_email(email)
{:ok, user}
rescue
e in Ecto.InvalidChangesetError ->
Logger.debug(inspect e)
{:error, e.changeset.changes.user.errors}
end
# with {:ok, %Account{} = account} <- create_account(%{username: username, suspended: false, domain: nil, private_key: privkey, public_key: pubkey, uri: "h", url: "h"}) do
# case create_user(%{email: email, password: password, account: account}) do
# {:ok, %User{} = user } ->
# {:ok, user}
# {:error, %Ecto.Changeset{} = changeset} ->
# {:error, changeset}
# end
# end
end
@doc """
Creates a user.
## Examples
iex> create_group(%{field: value})
{:ok, %Group{}}
iex> create_user(%{field: value})
{:ok, %User{}}
iex> create_group(%{field: bad_value})
iex> create_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_group(attrs \\ %{}) do
%Group{}
|> Group.changeset(attrs)
def create_user(attrs \\ %{}) do
%User{}
|> User.registration_changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a group.
Updates a user.
## Examples
iex> update_group(group, %{field: new_value})
{:ok, %Group{}}
iex> update_user(user, %{field: new_value})
{:ok, %User{}}
iex> update_group(group, %{field: bad_value})
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_group(%Group{} = group, attrs) do
group
|> Group.changeset(attrs)
def update_user(%User{} = user, attrs) do
user
|> User.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Group.
Deletes a User.
## Examples
iex> delete_group(group)
{:ok, %Group{}}
iex> delete_user(user)
{:ok, %User{}}
iex> delete_group(group)
iex> delete_user(user)
{:error, %Ecto.Changeset{}}
"""
def delete_group(%Group{} = group) do
Repo.delete(group)
def delete_user(%User{} = user) do
Repo.delete(user)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking group changes.
Returns an `%Ecto.Changeset{}` for tracking user changes.
## Examples
iex> change_group(group)
%Ecto.Changeset{source: %Group{}}
iex> change_user(user)
%Ecto.Changeset{source: %User{}}
"""
def change_group(%Group{} = group) do
Group.changeset(group, %{})
end
alias Eventos.Accounts.GroupAccount
@doc """
Returns the list of group_accounts.
## Examples
iex> list_group_accounts()
[%GroupAccount{}, ...]
"""
def list_group_accounts do
Repo.all(GroupAccount)
end
@doc """
Gets a single group_account.
Raises `Ecto.NoResultsError` if the Group account does not exist.
## Examples
iex> get_group_account!(123)
%GroupAccount{}
iex> get_group_account!(456)
** (Ecto.NoResultsError)
"""
def get_group_account!(id), do: Repo.get!(GroupAccount, id)
@doc """
Creates a group_account.
## Examples
iex> create_group_account(%{field: value})
{:ok, %GroupAccount{}}
iex> create_group_account(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_group_account(attrs \\ %{}) do
%GroupAccount{}
|> GroupAccount.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a group_account.
## Examples
iex> update_group_account(group_account, %{field: new_value})
{:ok, %GroupAccount{}}
iex> update_group_account(group_account, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_group_account(%GroupAccount{} = group_account, attrs) do
group_account
|> GroupAccount.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a GroupAccount.
## Examples
iex> delete_group_account(group_account)
{:ok, %GroupAccount{}}
iex> delete_group_account(group_account)
{:error, %Ecto.Changeset{}}
"""
def delete_group_account(%GroupAccount{} = group_account) do
Repo.delete(group_account)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking group_account changes.
## Examples
iex> change_group_account(group_account)
%Ecto.Changeset{source: %GroupAccount{}}
"""
def change_group_account(%GroupAccount{} = group_account) do
GroupAccount.changeset(group_account, %{})
end
alias Eventos.Accounts.GroupRequest
@doc """
Returns the list of group_request.
## Examples
iex> list_group_requests()
[%GroupRequest{}, ...]
"""
def list_group_requests do
Repo.all(GroupRequest)
end
@doc """
Gets a single group_request.
Raises `Ecto.NoResultsError` if the Group request does not exist.
## Examples
iex> get_group_request!(123)
%GroupRequest{}
iex> get_group_request!(456)
** (Ecto.NoResultsError)
"""
def get_group_request!(id), do: Repo.get!(GroupRequest, id)
@doc """
Creates a group_request.
## Examples
iex> create_group_request(%{field: value})
{:ok, %GroupRequest{}}
iex> create_group_request(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_group_request(attrs \\ %{}) do
%GroupRequest{}
|> GroupRequest.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a group_request.
## Examples
iex> update_group_request(group_request, %{field: new_value})
{:ok, %GroupRequest{}}
iex> update_group_request(group_request, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_group_request(%GroupRequest{} = group_request, attrs) do
group_request
|> GroupRequest.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a GroupRequest.
## Examples
iex> delete_group_request(group_request)
{:ok, %GroupRequest{}}
iex> delete_group_request(group_request)
{:error, %Ecto.Changeset{}}
"""
def delete_group_request(%GroupRequest{} = group_request) do
Repo.delete(group_request)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking group_request changes.
## Examples
iex> change_group_request(group_request)
%Ecto.Changeset{source: %GroupRequest{}}
"""
def change_group_request(%GroupRequest{} = group_request) do
GroupRequest.changeset(group_request, %{})
def change_user(%User{} = user) do
User.changeset(user, %{})
end
end

View file

@ -1,25 +0,0 @@
defmodule Eventos.Accounts.Group do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Accounts.{Group, Account, GroupAccount, GroupRequest}
schema "groups" do
field :description, :string
field :suspended, :boolean, default: false
field :title, :string
field :uri, :string
field :url, :string
many_to_many :accounts, Account, join_through: GroupAccount
has_many :requests, GroupRequest
timestamps()
end
@doc false
def changeset(%Group{} = group, attrs) do
group
|> cast(attrs, [:title, :description, :suspended, :url, :uri])
|> validate_required([:title, :description, :suspended, :url, :uri])
end
end

View file

@ -2,24 +2,22 @@ defmodule Eventos.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Accounts.{Account, User}
alias Eventos.Repo
import Logger
schema "users" do
field :email, :string
field :role, :integer, default: 0
field :password, :string, virtual: true
field :password_hash, :string
field :password, :string, virtual: true
field :role, :integer, default: 0
belongs_to :account, Account
timestamps()
end
@doc false
def changeset(%User{} = user, attrs) do
user
|> cast(attrs, [:email, :password_hash])
|> cast(attrs, [:email, :role, :password_hash, :account_id])
|> validate_required([:email])
|> unique_constraint(:email)
|> validate_format(:email, ~r/@/)
@ -44,4 +42,5 @@ defmodule Eventos.Accounts.User do
changeset
end
end
end

View file

@ -14,6 +14,7 @@ defmodule Eventos.Application do
supervisor(EventosWeb.Endpoint, []),
# Start your own worker by calling: Eventos.Worker.start_link(arg1, arg2, arg3)
# worker(Eventos.Worker, [arg1, arg2, arg3]),
worker(Guardian.DB.Token.SweeperServer, [])
]
# See https://hexdocs.pm/elixir/Supervisor.html

View file

@ -5,8 +5,9 @@ defmodule Eventos.Events.Category do
schema "categories" do
field :description, :string
field :picture, :string
field :title, :string
field :title, :string, null: false
timestamps()
end
@ -14,8 +15,8 @@ defmodule Eventos.Events.Category do
@doc false
def changeset(%Category{} = category, attrs) do
category
|> cast(attrs, [:title, :picture])
|> validate_required([:title, :picture])
|> cast(attrs, [:title, :description, :picture])
|> validate_required([:title])
|> unique_constraint(:title)
end
end

View file

@ -1,18 +1,65 @@
defmodule Eventos.Events.Event.TitleSlug do
alias Eventos.Events.Event
import Ecto.Query
alias Eventos.Repo
use EctoAutoslugField.Slug, from: :title, to: :slug
def build_slug(sources, changeset) do
slug = super(sources, changeset)
build_unique_slug(slug, changeset)
end
defp build_unique_slug(slug, changeset) do
query = from e in Event,
where: e.slug == ^slug
case Repo.one(query) do
nil -> slug
_event ->
slug
|> increment_slug
|> build_unique_slug(changeset)
end
end
defp increment_slug(slug) do
case List.pop_at(String.split(slug, "-"), -1) do
{nil, _} ->
slug
{suffix, slug_parts} ->
case Integer.parse(suffix) do
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
:error -> slug <> "-1"
end
end
end
end
defmodule Eventos.Events.Event do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.{Event, EventAccount, EventRequest}
alias Eventos.Events.{Event, Participant, Request, Tag, Session, Track}
alias Eventos.Events.Event.TitleSlug
alias Eventos.Accounts.Account
schema "events" do
field :begin_on, :utc_datetime
field :begins_on, Timex.Ecto.DateTimeWithTimezone
field :description, :string
field :ends_on, :utc_datetime
field :ends_on, Timex.Ecto.DateTimeWithTimezone
field :title, :string
has_one :organizer_id, Account
many_to_many :participants, Account, join_through: EventAccount
has_many :event_request, EventRequest
field :geom, Geo.Geometry
field :slug, TitleSlug.Type
field :state, :integer, default: 0
field :public, :boolean, default: true
field :thumbnail, :string
field :large_image, :string
field :publish_at, Timex.Ecto.DateTimeWithTimezone
belongs_to :organizer, Account, [foreign_key: :organizer_id]
has_many :tags, Tag
many_to_many :participants, Account, join_through: Participant
has_many :event_request, Request
has_many :tracks, Track
has_many :sessions, Session
timestamps()
end
@ -20,7 +67,9 @@ defmodule Eventos.Events.Event do
@doc false
def changeset(%Event{} = event, attrs) do
event
|> cast(attrs, [:title, :description, :begin_on, :ends_on])
|> validate_required([:title, :description, :begin_on, :ends_on, :organizer_id])
|> cast(attrs, [:title, :description, :begins_on, :ends_on, :organizer_id])
|> validate_required([:title, :description, :begins_on, :ends_on, :organizer_id])
|> TitleSlug.maybe_generate_slug()
|> TitleSlug.unique_constraint()
end
end

View file

@ -1,22 +0,0 @@
defmodule Eventos.Events.EventAccounts do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.{EventAccounts, Event}
alias Eventos.Accounts.Account
@primary_key false
schema "event_accounts" do
field :roles, :integer
belongs_to :event, Event
belongs_to :account, Account
timestamps()
end
@doc false
def changeset(%EventAccounts{} = event_accounts, attrs) do
event_accounts
|> cast(attrs, [:roles])
|> validate_required([:roles])
end
end

View file

@ -7,6 +7,7 @@ defmodule Eventos.Events do
alias Eventos.Repo
alias Eventos.Events.Event
alias Eventos.Accounts.Account
@doc """
Returns the list of events.
@ -294,195 +295,389 @@ defmodule Eventos.Events do
Tag.changeset(tag, %{})
end
alias Eventos.Events.EventAccounts
alias Eventos.Events.Participant
@doc """
Returns the list of event_accounts.
Returns the list of participants.
## Examples
iex> list_event_accounts()
[%EventAccounts{}, ...]
iex> list_participants()
[%Participant{}, ...]
"""
def list_event_accounts do
Repo.all(EventAccounts)
def list_participants do
Repo.all(Participant)
end
@doc """
Gets a single event_accounts.
Gets a single participant.
Raises `Ecto.NoResultsError` if the Event accounts does not exist.
Raises `Ecto.NoResultsError` if the Participant does not exist.
## Examples
iex> get_event_accounts!(123)
%EventAccounts{}
iex> get_participant!(123)
%Participant{}
iex> get_event_accounts!(456)
iex> get_participant!(456)
** (Ecto.NoResultsError)
"""
def get_event_accounts!(id), do: Repo.get!(EventAccounts, id)
def get_participant!(event_id, account_id) do
Repo.get_by!(Participant, [event_id: event_id, account_id: account_id])
end
@doc """
Creates a event_accounts.
Creates a participant.
## Examples
iex> create_event_accounts(%{field: value})
{:ok, %EventAccounts{}}
iex> create_participant(%{field: value})
{:ok, %Participant{}}
iex> create_event_accounts(%{field: bad_value})
iex> create_participant(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_event_accounts(attrs \\ %{}) do
%EventAccounts{}
|> EventAccounts.changeset(attrs)
def create_participant(attrs \\ %{}) do
%Participant{}
|> Participant.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a event_accounts.
Updates a participant.
## Examples
iex> update_event_accounts(event_accounts, %{field: new_value})
{:ok, %EventAccounts{}}
iex> update_participant(participant, %{field: new_value})
{:ok, %Participant{}}
iex> update_event_accounts(event_accounts, %{field: bad_value})
iex> update_participant(participant, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_event_accounts(%EventAccounts{} = event_accounts, attrs) do
event_accounts
|> EventAccounts.changeset(attrs)
def update_participant(%Participant{} = participant, attrs) do
participant
|> Participant.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a EventAccounts.
Deletes a Participant.
## Examples
iex> delete_event_accounts(event_accounts)
{:ok, %EventAccounts{}}
iex> delete_participant(participant)
{:ok, %Participant{}}
iex> delete_event_accounts(event_accounts)
iex> delete_participant(participant)
{:error, %Ecto.Changeset{}}
"""
def delete_event_accounts(%EventAccounts{} = event_accounts) do
Repo.delete(event_accounts)
def delete_participant(%Participant{} = participant) do
Repo.delete(participant)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking event_accounts changes.
Returns an `%Ecto.Changeset{}` for tracking participant changes.
## Examples
iex> change_event_accounts(event_accounts)
%Ecto.Changeset{source: %EventAccounts{}}
iex> change_participant(participant)
%Ecto.Changeset{source: %Participant{}}
"""
def change_event_accounts(%EventAccounts{} = event_accounts) do
EventAccounts.changeset(event_accounts, %{})
def change_participant(%Participant{} = participant) do
Participant.changeset(participant, %{})
end
alias Eventos.Events.EventRequest
alias Eventos.Events.Request
@doc """
Returns the list of event_requests.
Returns the list of requests.
## Examples
iex> list_event_requests()
[%EventRequest{}, ...]
iex> list_requests()
[%Request{}, ...]
"""
def list_event_requests do
Repo.all(EventRequest)
def list_requests do
Repo.all(Request)
end
@doc """
Gets a single event_request.
Gets a single request.
Raises `Ecto.NoResultsError` if the Event request does not exist.
Raises `Ecto.NoResultsError` if the Request does not exist.
## Examples
iex> get_event_request!(123)
%EventRequest{}
iex> get_request!(123)
%Request{}
iex> get_event_request!(456)
iex> get_request!(456)
** (Ecto.NoResultsError)
"""
def get_event_request!(id), do: Repo.get!(EventRequest, id)
def get_request!(id), do: Repo.get!(Request, id)
@doc """
Creates a event_request.
Creates a request.
## Examples
iex> create_event_request(%{field: value})
{:ok, %EventRequest{}}
iex> create_request(%{field: value})
{:ok, %Request{}}
iex> create_event_request(%{field: bad_value})
iex> create_request(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_event_request(attrs \\ %{}) do
%EventRequest{}
|> EventRequest.changeset(attrs)
def create_request(attrs \\ %{}) do
%Request{}
|> Request.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a event_request.
Updates a request.
## Examples
iex> update_event_request(event_request, %{field: new_value})
{:ok, %EventRequest{}}
iex> update_request(request, %{field: new_value})
{:ok, %Request{}}
iex> update_event_request(event_request, %{field: bad_value})
iex> update_request(request, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_event_request(%EventRequest{} = event_request, attrs) do
event_request
|> EventRequest.changeset(attrs)
def update_request(%Request{} = request, attrs) do
request
|> Request.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a EventRequest.
Deletes a Request.
## Examples
iex> delete_event_request(event_request)
{:ok, %EventRequest{}}
iex> delete_request(request)
{:ok, %Request{}}
iex> delete_event_request(event_request)
iex> delete_request(request)
{:error, %Ecto.Changeset{}}
"""
def delete_event_request(%EventRequest{} = event_request) do
Repo.delete(event_request)
def delete_request(%Request{} = request) do
Repo.delete(request)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking event_request changes.
Returns an `%Ecto.Changeset{}` for tracking request changes.
## Examples
iex> change_event_request(event_request)
%Ecto.Changeset{source: %EventRequest{}}
iex> change_request(request)
%Ecto.Changeset{source: %Request{}}
"""
def change_event_request(%EventRequest{} = event_request) do
EventRequest.changeset(event_request, %{})
def change_request(%Request{} = request) do
Request.changeset(request, %{})
end
alias Eventos.Events.Session
@doc """
Returns the list of sessions.
## Examples
iex> list_sessions()
[%Session{}, ...]
"""
def list_sessions do
Repo.all(Session)
end
@doc """
Gets a single session.
Raises `Ecto.NoResultsError` if the Session does not exist.
## Examples
iex> get_session!(123)
%Session{}
iex> get_session!(456)
** (Ecto.NoResultsError)
"""
def get_session!(id), do: Repo.get!(Session, id)
@doc """
Creates a session.
## Examples
iex> create_session(%{field: value})
{:ok, %Session{}}
iex> create_session(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_session(attrs \\ %{}) do
%Session{}
|> Session.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a session.
## Examples
iex> update_session(session, %{field: new_value})
{:ok, %Session{}}
iex> update_session(session, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_session(%Session{} = session, attrs) do
session
|> Session.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Session.
## Examples
iex> delete_session(session)
{:ok, %Session{}}
iex> delete_session(session)
{:error, %Ecto.Changeset{}}
"""
def delete_session(%Session{} = session) do
Repo.delete(session)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking session changes.
## Examples
iex> change_session(session)
%Ecto.Changeset{source: %Session{}}
"""
def change_session(%Session{} = session) do
Session.changeset(session, %{})
end
alias Eventos.Events.Track
@doc """
Returns the list of tracks.
## Examples
iex> list_tracks()
[%Track{}, ...]
"""
def list_tracks do
Repo.all(Track)
end
@doc """
Gets a single track.
Raises `Ecto.NoResultsError` if the Track does not exist.
## Examples
iex> get_track!(123)
%Track{}
iex> get_track!(456)
** (Ecto.NoResultsError)
"""
def get_track!(id), do: Repo.get!(Track, id)
@doc """
Creates a track.
## Examples
iex> create_track(%{field: value})
{:ok, %Track{}}
iex> create_track(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_track(attrs \\ %{}) do
%Track{}
|> Track.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a track.
## Examples
iex> update_track(track, %{field: new_value})
{:ok, %Track{}}
iex> update_track(track, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_track(%Track{} = track, attrs) do
track
|> Track.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Track.
## Examples
iex> delete_track(track)
{:ok, %Track{}}
iex> delete_track(track)
{:error, %Ecto.Changeset{}}
"""
def delete_track(%Track{} = track) do
Repo.delete(track)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking track changes.
## Examples
iex> change_track(track)
%Ecto.Changeset{source: %Track{}}
"""
def change_track(%Track{} = track) do
Track.changeset(track, %{})
end
end

View file

@ -0,0 +1,22 @@
defmodule Eventos.Events.Participant do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.{Participant, Event}
alias Eventos.Accounts.Account
@primary_key false
schema "participants" do
field :role, :integer
belongs_to :event, Event, primary_key: true
belongs_to :account, Account, primary_key: true
timestamps()
end
@doc false
def changeset(%Participant{} = participant, attrs) do
participant
|> cast(attrs, [:role, :event_id, :account_id])
|> validate_required([:role, :event_id, :account_id])
end
end

View file

@ -1,21 +1,20 @@
defmodule Eventos.Events.EventRequest do
defmodule Eventos.Events.Request do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.{EventRequest, Event}
alias Eventos.Events.{Request, Event}
alias Eventos.Accounts.Account
schema "event_requests" do
field :state, :integer
has_one :event_id, Event
has_one :account_id, Account
belongs_to :event, Event
belongs_to :account, Account
timestamps()
end
@doc false
def changeset(%EventRequest{} = event_request, attrs) do
event_request
def changeset(%Request{} = request, attrs) do
request
|> cast(attrs, [:state])
|> validate_required([:state])
end

View file

@ -0,0 +1,30 @@
defmodule Eventos.Events.Session do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.{Session, Event, Track}
schema "sessions" do
field :audios_urls, :string
field :language, :string
field :long_abstract, :string
field :short_abstract, :string
field :slides_url, :string
field :subtitle, :string
field :title, :string
field :videos_urls, :string
field :begins_on, Timex.Ecto.DateTimeWithTimezone
field :ends_on, Timex.Ecto.DateTimeWithTimezone
belongs_to :event, Event
belongs_to :track, Track
timestamps()
end
@doc false
def changeset(%Session{} = session, attrs) do
session
|> cast(attrs, [:title, :subtitle, :short_abstract, :long_abstract, :language, :slides_url, :videos_urls, :audios_urls, :event_id, :track_id])
|> validate_required([:title, :subtitle, :short_abstract, :long_abstract, :language, :slides_url, :videos_urls, :audios_urls])
end
end

View file

@ -1,12 +1,49 @@
defmodule Eventos.Events.Tag.TitleSlug do
alias Eventos.Events.Tag
import Ecto.Query
alias Eventos.Repo
use EctoAutoslugField.Slug, from: :title, to: :slug
def build_slug(sources, changeset) do
slug = super(sources, changeset)
build_unique_slug(slug, changeset)
end
defp build_unique_slug(slug, changeset) do
query = from t in Tag,
where: t.slug == ^slug
case Repo.one(query) do
nil -> slug
_story ->
slug
|> increment_slug
|> build_unique_slug(changeset)
end
end
defp increment_slug(slug) do
case List.pop_at(String.split(slug, "-"), -1) do
{nil, _} ->
slug
{suffix, slug_parts} ->
case Integer.parse(suffix) do
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
:error -> slug <> "-1"
end
end
end
end
defmodule Eventos.Events.Tag do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.Tag
alias Eventos.Events.Tag.TitleSlug
schema "tags" do
field :slug, :string
field :title, :string
field :slug, TitleSlug.Type
timestamps()
end
@ -14,8 +51,9 @@ defmodule Eventos.Events.Tag do
@doc false
def changeset(%Tag{} = tag, attrs) do
tag
|> cast(attrs, [:title, :slug])
|> validate_required([:title, :slug])
|> unique_constraint(:slug)
|> cast(attrs, [:title])
|> validate_required([:title])
|> TitleSlug.maybe_generate_slug()
|> TitleSlug.unique_constraint()
end
end

View file

@ -0,0 +1,23 @@
defmodule Eventos.Events.Track do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.{Track, Event, Session}
schema "tracks" do
field :color, :string
field :description, :string
field :name, :string
belongs_to :event, Event
has_many :sessions, Session
timestamps()
end
@doc false
def changeset(%Track{} = track, attrs) do
track
|> cast(attrs, [:name, :description, :color, :event_id])
|> validate_required([:name, :description, :color])
end
end

View file

@ -0,0 +1,66 @@
defmodule Eventos.Groups.Group.TitleSlug do
alias Eventos.Groups.Group
import Ecto.Query
alias Eventos.Repo
use EctoAutoslugField.Slug, from: :title, to: :slug
def build_slug(sources, changeset) do
slug = super(sources, changeset)
build_unique_slug(slug, changeset)
end
defp build_unique_slug(slug, changeset) do
query = from g in Group,
where: g.slug == ^slug
case Repo.one(query) do
nil -> slug
_story ->
slug
|> increment_slug
|> build_unique_slug(changeset)
end
end
defp increment_slug(slug) do
case List.pop_at(String.split(slug, "-"), -1) do
{nil, _} ->
slug
{suffix, slug_parts} ->
case Integer.parse(suffix) do
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
:error -> slug <> "-1"
end
end
end
end
defmodule Eventos.Groups.Group do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Groups.{Group, Member, Request}
alias Eventos.Accounts.Account
alias Eventos.Groups.Group.TitleSlug
schema "groups" do
field :description, :string
field :suspended, :boolean, default: false
field :title, :string
field :slug, TitleSlug.Type
field :uri, :string
field :url, :string
many_to_many :accounts, Account, join_through: Member
has_many :requests, Request
timestamps()
end
@doc false
def changeset(%Group{} = group, attrs) do
group
|> cast(attrs, [:title, :description, :suspended, :url, :uri])
|> validate_required([:title, :description, :suspended, :url, :uri])
|> TitleSlug.maybe_generate_slug()
|> TitleSlug.unique_constraint()
end
end

View file

@ -0,0 +1,296 @@
defmodule Eventos.Groups do
@moduledoc """
The Groups context.
"""
import Ecto.Query, warn: false
alias Eventos.Repo
alias Eventos.Groups.Group
@doc """
Returns the list of groups.
## Examples
iex> list_groups()
[%Group{}, ...]
"""
def list_groups do
Repo.all(Group)
end
@doc """
Gets a single group.
Raises `Ecto.NoResultsError` if the Group does not exist.
## Examples
iex> get_group!(123)
%Group{}
iex> get_group!(456)
** (Ecto.NoResultsError)
"""
def get_group!(id), do: Repo.get!(Group, id)
@doc """
Creates a group.
## Examples
iex> create_group(%{field: value})
{:ok, %Group{}}
iex> create_group(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_group(attrs \\ %{}) do
%Group{}
|> Group.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a group.
## Examples
iex> update_group(group, %{field: new_value})
{:ok, %Group{}}
iex> update_group(group, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_group(%Group{} = group, attrs) do
group
|> Group.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Group.
## Examples
iex> delete_group(group)
{:ok, %Group{}}
iex> delete_group(group)
{:error, %Ecto.Changeset{}}
"""
def delete_group(%Group{} = group) do
Repo.delete(group)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking group changes.
## Examples
iex> change_group(group)
%Ecto.Changeset{source: %Group{}}
"""
def change_group(%Group{} = group) do
Group.changeset(group, %{})
end
alias Eventos.Groups.Member
@doc """
Returns the list of members.
## Examples
iex> list_members()
[%Member{}, ...]
"""
def list_members do
Repo.all(Member)
end
@doc """
Gets a single member.
Raises `Ecto.NoResultsError` if the Member does not exist.
## Examples
iex> get_member!(123)
%Member{}
iex> get_member!(456)
** (Ecto.NoResultsError)
"""
def get_member!(id), do: Repo.get!(Member, id)
@doc """
Creates a member.
## Examples
iex> create_member(%{field: value})
{:ok, %Member{}}
iex> create_member(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_member(attrs \\ %{}) do
%Member{}
|> Member.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a member.
## Examples
iex> update_member(member, %{field: new_value})
{:ok, %Member{}}
iex> update_member(member, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_member(%Member{} = member, attrs) do
member
|> Member.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Member.
## Examples
iex> delete_member(member)
{:ok, %Member{}}
iex> delete_member(member)
{:error, %Ecto.Changeset{}}
"""
def delete_member(%Member{} = member) do
Repo.delete(member)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking member changes.
## Examples
iex> change_member(member)
%Ecto.Changeset{source: %Member{}}
"""
def change_member(%Member{} = member) do
Member.changeset(member, %{})
end
alias Eventos.Groups.Request
@doc """
Returns the list of requests.
## Examples
iex> list_requests()
[%Request{}, ...]
"""
def list_requests do
Repo.all(Request)
end
@doc """
Gets a single request.
Raises `Ecto.NoResultsError` if the Request does not exist.
## Examples
iex> get_request!(123)
%Request{}
iex> get_request!(456)
** (Ecto.NoResultsError)
"""
def get_request!(id), do: Repo.get!(Request, id)
@doc """
Creates a request.
## Examples
iex> create_request(%{field: value})
{:ok, %Request{}}
iex> create_request(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_request(attrs \\ %{}) do
%Request{}
|> Request.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a request.
## Examples
iex> update_request(request, %{field: new_value})
{:ok, %Request{}}
iex> update_request(request, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_request(%Request{} = request, attrs) do
request
|> Request.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Request.
## Examples
iex> delete_request(request)
{:ok, %Request{}}
iex> delete_request(request)
{:error, %Ecto.Changeset{}}
"""
def delete_request(%Request{} = request) do
Repo.delete(request)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking request changes.
## Examples
iex> change_request(request)
%Ecto.Changeset{source: %Request{}}
"""
def change_request(%Request{} = request) do
Request.changeset(request, %{})
end
end

View file

@ -1,10 +1,11 @@
defmodule Eventos.Accounts.GroupAccount do
defmodule Eventos.Groups.Member do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Accounts.{GroupAccount, Account, Group}
alias Eventos.Groups.{Member, Group}
alias Eventos.Accounts.Account
@primary_key false
schema "group_accounts" do
schema "members" do
field :role, :integer
belongs_to :group, Group
belongs_to :account, Account
@ -13,8 +14,8 @@ defmodule Eventos.Accounts.GroupAccount do
end
@doc false
def changeset(%GroupAccount{} = group_account, attrs) do
group_account
def changeset(%Member{} = member, attrs) do
member
|> cast(attrs, [:role])
|> validate_required([:role])
end

View file

@ -1,7 +1,8 @@
defmodule Eventos.Accounts.GroupRequest do
defmodule Eventos.Groups.Request do
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Accounts.{GroupRequest}
alias Eventos.Groups.Request
schema "group_requests" do
field :state, :integer
@ -12,8 +13,8 @@ defmodule Eventos.Accounts.GroupRequest do
end
@doc false
def changeset(%GroupRequest{} = group_request, attrs) do
group_request
def changeset(%Request{} = request, attrs) do
request
|> cast(attrs, [:state])
|> validate_required([:state])
end

View file

@ -0,0 +1,3 @@
Postgrex.Types.define(Eventos.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Poison)

View file

@ -1,10 +1,10 @@
defmodule EventosWeb.AuthPipeline do
use Guardian.Plug.Pipeline, otp_app: :eventos,
module: EventosWeb.Guradian,
module: EventosWeb.Guardian,
error_handler: EventosWeb.AuthErrorHandler
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}, realm: :none
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}
plug Guardian.Plug.EnsureAuthenticated
plug Guardian.Plug.LoadResource, ensure: true

View file

@ -3,58 +3,37 @@ defmodule EventosWeb.AccountController do
alias Eventos.Accounts
alias Eventos.Accounts.Account
import Logger
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
accounts = Accounts.list_accounts()
render(conn, "index.html", accounts: accounts)
end
def new(conn, _params) do
changeset = Accounts.change_account(%Account{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"account" => account_params}) do
case Accounts.create_account(account_params) do
{:ok, account} ->
conn
|> put_flash(:info, "Account created successfully.")
|> redirect(to: account_path(conn, :show, account))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
render(conn, "index.json", accounts: accounts)
end
def show(conn, %{"id" => id}) do
account = Accounts.get_account!(id)
render(conn, "show.html", account: account)
end
def edit(conn, %{"id" => id}) do
account = Accounts.get_account!(id)
changeset = Accounts.change_account(account)
render(conn, "edit.html", account: account, changeset: changeset)
account = Accounts.get_account_with_everything!(id)
render(conn, "show.json", account: account)
end
def update(conn, %{"id" => id, "account" => account_params}) do
account = Accounts.get_account!(id)
case Accounts.update_account(account, account_params) do
{:ok, account} ->
conn
|> put_flash(:info, "Account updated successfully.")
|> redirect(to: account_path(conn, :show, account))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", account: account, changeset: changeset)
with {:ok, %Account{} = account} <- Accounts.update_account(account, account_params) do
render(conn, "show.json", account: account)
end
end
def delete(conn, %{"id" => id}) do
def delete(conn, %{"id" => id_str}) do
{id, _} = Integer.parse(id_str)
if Guardian.Plug.current_resource(conn).account.id == id do
account = Accounts.get_account!(id)
{:ok, _account} = Accounts.delete_account(account)
conn
|> put_flash(:info, "Account deleted successfully.")
|> redirect(to: account_path(conn, :index))
with {:ok, %Account{}} <- Accounts.delete_account(account) do
send_resp(conn, :no_content, "")
end
else
send_resp(conn, 401, "")
end
end
end

View file

@ -1,9 +0,0 @@
defmodule EventosWeb.AppController do
use EventosWeb, :controller
plug :put_layout, false
def app(conn, _params) do
render conn, "index.html"
end
end

View file

@ -4,57 +4,39 @@ defmodule EventosWeb.CategoryController do
alias Eventos.Events
alias Eventos.Events.Category
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
categories = Events.list_categories()
render(conn, "index.html", categories: categories)
end
def new(conn, _params) do
changeset = Events.change_category(%Category{})
render(conn, "new.html", changeset: changeset)
render(conn, "index.json", categories: categories)
end
def create(conn, %{"category" => category_params}) do
case Events.create_category(category_params) do
{:ok, category} ->
with {:ok, %Category{} = category} <- Events.create_category(category_params) do
conn
|> put_flash(:info, "Category created successfully.")
|> redirect(to: category_path(conn, :show, category))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
|> put_status(:created)
|> put_resp_header("location", category_path(conn, :show, category))
|> render("show.json", category: category)
end
end
def show(conn, %{"id" => id}) do
category = Events.get_category!(id)
render(conn, "show.html", category: category)
end
def edit(conn, %{"id" => id}) do
category = Events.get_category!(id)
changeset = Events.change_category(category)
render(conn, "edit.html", category: category, changeset: changeset)
render(conn, "show.json", category: category)
end
def update(conn, %{"id" => id, "category" => category_params}) do
category = Events.get_category!(id)
case Events.update_category(category, category_params) do
{:ok, category} ->
conn
|> put_flash(:info, "Category updated successfully.")
|> redirect(to: category_path(conn, :show, category))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", category: category, changeset: changeset)
with {:ok, %Category{} = category} <- Events.update_category(category, category_params) do
render(conn, "show.json", category: category)
end
end
def delete(conn, %{"id" => id}) do
category = Events.get_category!(id)
{:ok, _category} = Events.delete_category(category)
conn
|> put_flash(:info, "Category deleted successfully.")
|> redirect(to: category_path(conn, :index))
with {:ok, %Category{}} <- Events.delete_category(category) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -1,60 +0,0 @@
defmodule EventosWeb.EventAccountsController do
use EventosWeb, :controller
alias Eventos.Events
alias Eventos.Events.EventAccounts
def index(conn, _params) do
event_accounts = Events.list_event_accounts()
render(conn, "index.html", event_accounts: event_accounts)
end
def new(conn, _params) do
changeset = Events.change_event_accounts(%EventAccounts{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"event_accounts" => event_accounts_params}) do
case Events.create_event_accounts(event_accounts_params) do
{:ok, event_accounts} ->
conn
|> put_flash(:info, "Event accounts created successfully.")
|> redirect(to: event_accounts_path(conn, :show, event_accounts))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
event_accounts = Events.get_event_accounts!(id)
render(conn, "show.html", event_accounts: event_accounts)
end
def edit(conn, %{"id" => id}) do
event_accounts = Events.get_event_accounts!(id)
changeset = Events.change_event_accounts(event_accounts)
render(conn, "edit.html", event_accounts: event_accounts, changeset: changeset)
end
def update(conn, %{"id" => id, "event_accounts" => event_accounts_params}) do
event_accounts = Events.get_event_accounts!(id)
case Events.update_event_accounts(event_accounts, event_accounts_params) do
{:ok, event_accounts} ->
conn
|> put_flash(:info, "Event accounts updated successfully.")
|> redirect(to: event_accounts_path(conn, :show, event_accounts))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", event_accounts: event_accounts, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
event_accounts = Events.get_event_accounts!(id)
{:ok, _event_accounts} = Events.delete_event_accounts(event_accounts)
conn
|> put_flash(:info, "Event accounts deleted successfully.")
|> redirect(to: event_accounts_path(conn, :index))
end
end

View file

@ -4,57 +4,39 @@ defmodule EventosWeb.EventController do
alias Eventos.Events
alias Eventos.Events.Event
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
events = Events.list_events()
render(conn, "index.html", events: events)
end
def new(conn, _params) do
changeset = Events.change_event(%Event{})
render(conn, "new.html", changeset: changeset)
render(conn, "index.json", events: events)
end
def create(conn, %{"event" => event_params}) do
case Events.create_event(event_params) do
{:ok, event} ->
with {:ok, %Event{} = event} <- Events.create_event(event_params) do
conn
|> put_flash(:info, "Event created successfully.")
|> redirect(to: event_path(conn, :show, event))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
|> put_status(:created)
|> put_resp_header("location", event_path(conn, :show, event))
|> render("show.json", event: event)
end
end
def show(conn, %{"id" => id}) do
event = Events.get_event!(id)
render(conn, "show.html", event: event)
end
def edit(conn, %{"id" => id}) do
event = Events.get_event!(id)
changeset = Events.change_event(event)
render(conn, "edit.html", event: event, changeset: changeset)
render(conn, "show.json", event: event)
end
def update(conn, %{"id" => id, "event" => event_params}) do
event = Events.get_event!(id)
case Events.update_event(event, event_params) do
{:ok, event} ->
conn
|> put_flash(:info, "Event updated successfully.")
|> redirect(to: event_path(conn, :show, event))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", event: event, changeset: changeset)
with {:ok, %Event{} = event} <- Events.update_event(event, event_params) do
render(conn, "show.json", event: event)
end
end
def delete(conn, %{"id" => id}) do
event = Events.get_event!(id)
{:ok, _event} = Events.delete_event(event)
conn
|> put_flash(:info, "Event deleted successfully.")
|> redirect(to: event_path(conn, :index))
with {:ok, %Event{}} <- Events.delete_event(event) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -1,60 +0,0 @@
defmodule EventosWeb.EventRequestController do
use EventosWeb, :controller
alias Eventos.Events
alias Eventos.Events.EventRequest
def index(conn, _params) do
event_requests = Events.list_event_requests()
render(conn, "index.html", event_requests: event_requests)
end
def new(conn, _params) do
changeset = Events.change_event_request(%EventRequest{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"event_request" => event_request_params}) do
case Events.create_event_request(event_request_params) do
{:ok, event_request} ->
conn
|> put_flash(:info, "Event request created successfully.")
|> redirect(to: event_request_path(conn, :show, event_request))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
event_request = Events.get_event_request!(id)
render(conn, "show.html", event_request: event_request)
end
def edit(conn, %{"id" => id}) do
event_request = Events.get_event_request!(id)
changeset = Events.change_event_request(event_request)
render(conn, "edit.html", event_request: event_request, changeset: changeset)
end
def update(conn, %{"id" => id, "event_request" => event_request_params}) do
event_request = Events.get_event_request!(id)
case Events.update_event_request(event_request, event_request_params) do
{:ok, event_request} ->
conn
|> put_flash(:info, "Event request updated successfully.")
|> redirect(to: event_request_path(conn, :show, event_request))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", event_request: event_request, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
event_request = Events.get_event_request!(id)
{:ok, _event_request} = Events.delete_event_request(event_request)
conn
|> put_flash(:info, "Event request deleted successfully.")
|> redirect(to: event_request_path(conn, :index))
end
end

View file

@ -0,0 +1,20 @@
defmodule EventosWeb.FallbackController do
@moduledoc """
Translates controller action results into valid `Plug.Conn` responses.
See `Phoenix.Controller.action_fallback/1` for more details.
"""
use EventosWeb, :controller
def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
conn
|> put_status(:unprocessable_entity)
|> render(EventosWeb.ChangesetView, "error.json", changeset: changeset)
end
def call(conn, {:error, :not_found}) do
conn
|> put_status(:not_found)
|> render(EventosWeb.ErrorView, :"404")
end
end

View file

@ -1,60 +0,0 @@
defmodule EventosWeb.GroupAccountController do
use EventosWeb, :controller
alias Eventos.Accounts
alias Eventos.Accounts.GroupAccount
def index(conn, _params) do
group_accounts = Accounts.list_group_accounts()
render(conn, "index.html", group_accounts: group_accounts)
end
def new(conn, _params) do
changeset = Accounts.change_group_account(%GroupAccount{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"group_account" => group_account_params}) do
case Accounts.create_group_account(group_account_params) do
{:ok, group_account} ->
conn
|> put_flash(:info, "Group account created successfully.")
|> redirect(to: group_account_path(conn, :show, group_account))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
group_account = Accounts.get_group_account!(id)
render(conn, "show.html", group_account: group_account)
end
def edit(conn, %{"id" => id}) do
group_account = Accounts.get_group_account!(id)
changeset = Accounts.change_group_account(group_account)
render(conn, "edit.html", group_account: group_account, changeset: changeset)
end
def update(conn, %{"id" => id, "group_account" => group_account_params}) do
group_account = Accounts.get_group_account!(id)
case Accounts.update_group_account(group_account, group_account_params) do
{:ok, group_account} ->
conn
|> put_flash(:info, "Group account updated successfully.")
|> redirect(to: group_account_path(conn, :show, group_account))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", group_account: group_account, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
group_account = Accounts.get_group_account!(id)
{:ok, _group_account} = Accounts.delete_group_account(group_account)
conn
|> put_flash(:info, "Group account deleted successfully.")
|> redirect(to: group_account_path(conn, :index))
end
end

View file

@ -1,60 +1,42 @@
defmodule EventosWeb.GroupController do
use EventosWeb, :controller
alias Eventos.Accounts
alias Eventos.Accounts.Group
alias Eventos.Groups
alias Eventos.Groups.Group
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
groups = Accounts.list_groups()
render(conn, "index.html", groups: groups)
end
def new(conn, _params) do
changeset = Accounts.change_group(%Group{})
render(conn, "new.html", changeset: changeset)
groups = Groups.list_groups()
render(conn, "index.json", groups: groups)
end
def create(conn, %{"group" => group_params}) do
case Accounts.create_group(group_params) do
{:ok, group} ->
with {:ok, %Group{} = group} <- Groups.create_group(group_params) do
conn
|> put_flash(:info, "Group created successfully.")
|> redirect(to: group_path(conn, :show, group))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
|> put_status(:created)
|> put_resp_header("location", group_path(conn, :show, group))
|> render("show.json", group: group)
end
end
def show(conn, %{"id" => id}) do
group = Accounts.get_group!(id)
render(conn, "show.html", group: group)
end
def edit(conn, %{"id" => id}) do
group = Accounts.get_group!(id)
changeset = Accounts.change_group(group)
render(conn, "edit.html", group: group, changeset: changeset)
group = Groups.get_group!(id)
render(conn, "show.json", group: group)
end
def update(conn, %{"id" => id, "group" => group_params}) do
group = Accounts.get_group!(id)
group = Groups.get_group!(id)
case Accounts.update_group(group, group_params) do
{:ok, group} ->
conn
|> put_flash(:info, "Group updated successfully.")
|> redirect(to: group_path(conn, :show, group))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", group: group, changeset: changeset)
with {:ok, %Group{} = group} <- Groups.update_group(group, group_params) do
render(conn, "show.json", group: group)
end
end
def delete(conn, %{"id" => id}) do
group = Accounts.get_group!(id)
{:ok, _group} = Accounts.delete_group(group)
conn
|> put_flash(:info, "Group deleted successfully.")
|> redirect(to: group_path(conn, :index))
group = Groups.get_group!(id)
with {:ok, %Group{}} <- Groups.delete_group(group) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -1,60 +0,0 @@
defmodule EventosWeb.GroupRequestController do
use EventosWeb, :controller
alias Eventos.Accounts
alias Eventos.Accounts.GroupRequest
def index(conn, _params) do
group_request = Accounts.list_group_requests()
render(conn, "index.html", group_request: group_request)
end
def new(conn, _params) do
changeset = Accounts.change_group_request(%GroupRequest{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"group_request" => group_request_params}) do
case Accounts.create_group_request(group_request_params) do
{:ok, group_request} ->
conn
|> put_flash(:info, "Group request created successfully.")
|> redirect(to: group_request_path(conn, :show, group_request))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
group_request = Accounts.get_group_request!(id)
render(conn, "show.html", group_request: group_request)
end
def edit(conn, %{"id" => id}) do
group_request = Accounts.get_group_request!(id)
changeset = Accounts.change_group_request(group_request)
render(conn, "edit.html", group_request: group_request, changeset: changeset)
end
def update(conn, %{"id" => id, "group_request" => group_request_params}) do
group_request = Accounts.get_group_request!(id)
case Accounts.update_group_request(group_request, group_request_params) do
{:ok, group_request} ->
conn
|> put_flash(:info, "Group request updated successfully.")
|> redirect(to: group_request_path(conn, :show, group_request))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", group_request: group_request, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
group_request = Accounts.get_group_request!(id)
{:ok, _group_request} = Accounts.delete_group_request(group_request)
conn
|> put_flash(:info, "Group request deleted successfully.")
|> redirect(to: group_request_path(conn, :index))
end
end

View file

@ -1,6 +1,7 @@
defmodule EventosWeb.PageController do
use EventosWeb, :controller
import Logger
plug :put_layout, false
def index(conn, _params) do
render conn, "index.html"

View file

@ -1,30 +1,42 @@
defmodule EventosWeb.SessionController do
use EventosWeb, :controller
alias Eventos.Accounts.User
alias Eventos.Accounts
def sign_in(conn, %{"email" => email, "password" => password}) do
with %User{} = user <- Accounts.find(email) do
# Attempt to authenticate the user
with {:ok, token, _claims} <- Accounts.authenticate(%{user: user, password: password}) do
# Render the token
user = Eventos.Repo.preload user, :account
render conn, "token.json", %{token: token, user: user}
end
send_resp(conn, 400, "Bad login")
end
send_resp(conn, 400, "No such user")
alias Eventos.Events
alias Eventos.Events.Session
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
sessions = Events.list_sessions()
render(conn, "index.json", sessions: sessions)
end
def sign_out(conn, _params) do
def create(conn, %{"session" => session_params}) do
with {:ok, %Session{} = session} <- Events.create_session(session_params) do
conn
|> Eventos.Guardian.Plug.sign_out()
|> send_resp(204, "")
|> put_status(:created)
|> put_resp_header("location", session_path(conn, :show, session))
|> render("show.json", session: session)
end
end
def show(conn, _params) do
user = Eventos.Guardian.Plug.current_resource(conn)
def show(conn, %{"id" => id}) do
session = Events.get_session!(id)
render(conn, "show.json", session: session)
end
send_resp(conn, 200, Poison.encode!(%{user: user}))
def update(conn, %{"id" => id, "session" => session_params}) do
session = Events.get_session!(id)
with {:ok, %Session{} = session} <- Events.update_session(session, session_params) do
render(conn, "show.json", session: session)
end
end
def delete(conn, %{"id" => id}) do
session = Events.get_session!(id)
with {:ok, %Session{}} <- Events.delete_session(session) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -4,57 +4,39 @@ defmodule EventosWeb.TagController do
alias Eventos.Events
alias Eventos.Events.Tag
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
tags = Events.list_tags()
render(conn, "index.html", tags: tags)
end
def new(conn, _params) do
changeset = Events.change_tag(%Tag{})
render(conn, "new.html", changeset: changeset)
render(conn, "index.json", tags: tags)
end
def create(conn, %{"tag" => tag_params}) do
case Events.create_tag(tag_params) do
{:ok, tag} ->
with {:ok, %Tag{} = tag} <- Events.create_tag(tag_params) do
conn
|> put_flash(:info, "Tag created successfully.")
|> redirect(to: tag_path(conn, :show, tag))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
|> put_status(:created)
|> put_resp_header("location", tag_path(conn, :show, tag))
|> render("show.json", tag: tag)
end
end
def show(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
render(conn, "show.html", tag: tag)
end
def edit(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
changeset = Events.change_tag(tag)
render(conn, "edit.html", tag: tag, changeset: changeset)
render(conn, "show.json", tag: tag)
end
def update(conn, %{"id" => id, "tag" => tag_params}) do
tag = Events.get_tag!(id)
case Events.update_tag(tag, tag_params) do
{:ok, tag} ->
conn
|> put_flash(:info, "Tag updated successfully.")
|> redirect(to: tag_path(conn, :show, tag))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", tag: tag, changeset: changeset)
with {:ok, %Tag{} = tag} <- Events.update_tag(tag, tag_params) do
render(conn, "show.json", tag: tag)
end
end
def delete(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
{:ok, _tag} = Events.delete_tag(tag)
conn
|> put_flash(:info, "Tag deleted successfully.")
|> redirect(to: tag_path(conn, :index))
with {:ok, %Tag{}} <- Events.delete_tag(tag) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -0,0 +1,42 @@
defmodule EventosWeb.TrackController do
use EventosWeb, :controller
alias Eventos.Events
alias Eventos.Events.Track
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
tracks = Events.list_tracks()
render(conn, "index.json", tracks: tracks)
end
def create(conn, %{"track" => track_params}) do
with {:ok, %Track{} = track} <- Events.create_track(track_params) do
conn
|> put_status(:created)
|> put_resp_header("location", track_path(conn, :show, track))
|> render("show.json", track: track)
end
end
def show(conn, %{"id" => id}) do
track = Events.get_track!(id)
render(conn, "show.json", track: track)
end
def update(conn, %{"id" => id, "track" => track_params}) do
track = Events.get_track!(id)
with {:ok, %Track{} = track} <- Events.update_track(track, track_params) do
render(conn, "show.json", track: track)
end
end
def delete(conn, %{"id" => id}) do
track = Events.get_track!(id)
with {:ok, %Track{}} <- Events.delete_track(track) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -4,88 +4,66 @@ defmodule EventosWeb.UserController do
alias Eventos.Accounts
alias Eventos.Accounts.User
alias Eventos.Repo
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
users = Accounts.list_users()
render(conn, "index.html", users: users)
users = Accounts.list_users_with_accounts()
render(conn, "index.json", users: users)
end
def new(conn, _params) do
changeset = Accounts.change_user(%User{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"user" => user_params}) do
case Accounts.create_user(user_params) do
{:ok, user} ->
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
case Accounts.register(%{email: email, password: password, username: username}) do
{:ok, %User{} = user} ->
Logger.debug(inspect user)
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
conn
|> put_flash(:info, "User created successfully.")
|> redirect(to: user_path(conn, :show, user))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
|> put_status(:created)
|> render "show_with_token.json", %{token: token, user: user}
{:error, error} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(400, Poison.encode!(%{"msg" => handle_changeset_errors(error)}))
end
end
def show(conn, %{"id" => id}) do
user = Accounts.get_user!(id)
render(conn, "show.html", user: user)
def show_current_account(conn, _params) do
user = Guardian.Plug.current_resource(conn)
|> Repo.preload :account
render(conn, "show_simple.json", user: user)
end
def edit(conn, %{"id" => id}) do
user = Accounts.get_user!(id)
changeset = Accounts.change_user(user)
render(conn, "edit.html", user: user, changeset: changeset)
defp handle_changeset_errors(errors) do
Enum.map(errors, fn {field, detail} ->
"#{field} " <> render_detail(detail)
end)
|> Enum.join
end
defp render_detail({message, values}) do
Enum.reduce values, message, fn {k, v}, acc ->
String.replace(acc, "%{#{k}}", to_string(v))
end
end
defp render_detail(message) do
message
end
def update(conn, %{"id" => id, "user" => user_params}) do
user = Accounts.get_user!(id)
case Accounts.update_user(user, user_params) do
{:ok, user} ->
conn
|> put_flash(:info, "User updated successfully.")
|> redirect(to: user_path(conn, :show, user))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", user: user, changeset: changeset)
with {:ok, %User{} = user} <- Accounts.update_user(user, user_params) do
render(conn, "show.json", user: user)
end
end
def delete(conn, %{"id" => id}) do
user = Accounts.get_user!(id)
{:ok, _user} = Accounts.delete_user(user)
conn
|> put_flash(:info, "User deleted successfully.")
|> redirect(to: user_path(conn, :index))
with {:ok, %User{}} <- Accounts.delete_user(user) do
send_resp(conn, :no_content, "")
end
def register(conn, %{"email" => email, "password" => password, "username" => username}) do
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
account_change = Ecto.Changeset.change(%Eventos.Accounts.Account{}, %{
username: username,
description: "tata",
display_name: "toto",
domain: nil,
private_key: privkey,
public_key: pubkey,
uri: "",
url: ""
})
user_change = Eventos.Accounts.User.registration_changeset(%Eventos.Accounts.User{}, %{
email: email,
password: password,
password_confirmation: password
})
account_with_user = Ecto.Changeset.put_assoc(account_change, :user, user_change)
Eventos.Repo.insert!(account_with_user)
user = Eventos.Accounts.find(email)
user = Eventos.Repo.preload user, :account
render conn, "user.json", %{user: user}
end
end

View file

@ -0,0 +1,28 @@
defmodule EventosWeb.UserSessionController do
use EventosWeb, :controller
alias Eventos.Accounts.User
alias Eventos.Accounts
import Logger
def sign_in(conn, %{"email" => email, "password" => password}) do
case Accounts.find_by_email(email) do
%User{} = user ->
# Attempt to authenticate the user
case Accounts.authenticate(%{user: user, password: password}) do
{:ok, token, _claims} ->
# Render the token
render conn, "token.json", %{token: token, user: user}
_ ->
send_resp(conn, 400, Poison.encode!(%{"error_msg" => "Bad login", "display_error" => "session.error.bad_login", "error_code" => 400}))
end
_ ->
send_resp(conn, 400, Poison.encode!(%{"error_msg" => "No such user", "display_error" => "session.error.bad_login", "error_code" => 400}))
end
end
def sign_out(conn, _params) do
conn
|> Guardian.Plug.sign_out()
|> send_resp(204, "")
end
end

View file

@ -4,8 +4,10 @@ defmodule EventosWeb.Guardian do
user: [:base]
}
import Logger
alias Eventos.Accounts
alias Eventos.Accounts.User
alias Eventos.Accounts.{Account, User}
def subject_for_token(user = %User{}, _claims) do
{:ok, "User:" <> to_string(user.id)}
@ -17,9 +19,11 @@ defmodule EventosWeb.Guardian do
def resource_from_claims(%{"sub" => "User:" <> uid_str}) do
try do
Logger.debug("Inspecting resource token")
Logger.debug(inspect uid_str)
case Integer.parse(uid_str) do
{uid, ""} ->
{:ok, Accounts.get_user!(uid)}
{:ok, Accounts.get_user_with_account!(uid)}
_ ->
{:error, :invalid_id}
end
@ -28,13 +32,34 @@ defmodule EventosWeb.Guardian do
end
end
def resource_from_claims(_claims) do
def resource_from_claims(claims) do
Logger.debug("Check bad resource")
Logger.debug(inspect claims)
{:error, :reason_for_error}
end
# def build_claims(claims, _resource, opts) do
# claims = claims
# |> encode_permissions_into_claims!(Keyword.get(opts, :permissions))
# {:ok, claims}
# end
def after_encode_and_sign(resource, claims, token, _options) do
with {:ok, _} <- Guardian.DB.after_encode_and_sign(resource, claims["typ"], claims, token) do
{:ok, token}
end
end
def on_verify(claims, token, _options) do
Logger.debug(inspect claims)
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
{:ok, claims}
end
end
def on_revoke(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_revoke(claims, token) do
{:ok, claims}
end
end
# def build_claims(claims, _resource, opts) do
# claims = claims
# |> encode_permissions_into_claims!(Keyword.get(opts, :permissions))
# {:ok, claims}
# end
end

View file

@ -6,6 +6,7 @@ defmodule EventosWeb.Router do
end
pipeline :api_auth do
plug :accepts, ["json"]
plug EventosWeb.AuthPipeline
end
@ -21,17 +22,24 @@ defmodule EventosWeb.Router do
pipe_through :api
post "/users", UserController, :register
post "/login", SessionController, :sign_in
resources "/groups", GroupController, only: [:index]
post "/login", UserSessionController, :sign_in
resources "/groups", GroupController, only: [:index, :show]
resources "/events", EventController, only: [:index, :show]
resources "/accounts", AccountController, only: [:index, :show]
resources "/tags", TagController, only: [:index, :show]
resources "/categories", CategoryController, only: [:index, :show]
resources "/sessions", SessionController, only: [:index, :show]
resources "/tracks", TrackController, only: [:index, :show]
end
# Other scopes may use custom stacks.
scope "/api", EventosWeb do
pipe_through :api_auth
post "/sign-out", SessionController, :sign_out
resources "/users", UserController
resources "/accounts", AccountController
get "/user", UserController, :show_current_account
post "/sign-out", UserSessionController, :sign_out
resources "/users", UserController, except: [:new, :edit, :show]
resources "/accounts", AccountController, except: [:new, :edit]
resources "/events", EventController
resources "/categories", CategoryController
resources "/tags", TagController
@ -40,11 +48,13 @@ defmodule EventosWeb.Router do
resources "/groups", GroupController, except: [:index]
resources "/group_accounts", GroupAccountController
resources "/group_requests", GroupRequestController
resources "/sessions", SessionController, except: [:new, :edit]
resources "/tracks", TrackController, except: [:new, :edit]
end
scope "/", EventosWeb do
pipe_through :browser
get "/*path", AppController, :app
get "/*path", PageController, :index
end
end

View file

@ -1,5 +0,0 @@
<h2>Edit Account</h2>
<%= render "form.html", Map.put(assigns, :action, account_path(@conn, :update, @account)) %>
<span><%= link "Back", to: account_path(@conn, :index) %></span>

View file

@ -1,65 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :username, class: "control-label" %>
<%= text_input f, :username, class: "form-control" %>
<%= error_tag f, :username %>
</div>
<div class="form-group">
<%= label f, :domain, class: "control-label" %>
<%= text_input f, :domain, class: "form-control" %>
<%= error_tag f, :domain %>
</div>
<div class="form-group">
<%= label f, :display_name, class: "control-label" %>
<%= text_input f, :display_name, class: "form-control" %>
<%= error_tag f, :display_name %>
</div>
<div class="form-group">
<%= label f, :description, class: "control-label" %>
<%= text_input f, :description, class: "form-control" %>
<%= error_tag f, :description %>
</div>
<div class="form-group">
<%= label f, :private_key, class: "control-label" %>
<%= text_input f, :private_key, class: "form-control" %>
<%= error_tag f, :private_key %>
</div>
<div class="form-group">
<%= label f, :public_key, class: "control-label" %>
<%= text_input f, :public_key, class: "form-control" %>
<%= error_tag f, :public_key %>
</div>
<div class="form-group">
<%= label f, :suspended, class: "control-label" %>
<%= checkbox f, :suspended, class: "checkbox" %>
<%= error_tag f, :suspended %>
</div>
<div class="form-group">
<%= label f, :uri, class: "control-label" %>
<%= text_input f, :uri, class: "form-control" %>
<%= error_tag f, :uri %>
</div>
<div class="form-group">
<%= label f, :url, class: "control-label" %>
<%= text_input f, :url, class: "form-control" %>
<%= error_tag f, :url %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,42 +0,0 @@
<h2>Listing Accounts</h2>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Domain</th>
<th>Display name</th>
<th>Description</th>
<th>Private key</th>
<th>Public key</th>
<th>Suspended</th>
<th>Uri</th>
<th>Url</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for account <- @accounts do %>
<tr>
<td><%= account.username %></td>
<td><%= account.domain %></td>
<td><%= account.display_name %></td>
<td><%= account.description %></td>
<td><%= account.private_key %></td>
<td><%= account.public_key %></td>
<td><%= account.suspended %></td>
<td><%= account.uri %></td>
<td><%= account.url %></td>
<td class="text-right">
<span><%= link "Show", to: account_path(@conn, :show, account), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: account_path(@conn, :edit, account), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: account_path(@conn, :delete, account), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Account", to: account_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Account</h2>
<%= render "form.html", Map.put(assigns, :action, account_path(@conn, :create)) %>
<span><%= link "Back", to: account_path(@conn, :index) %></span>

View file

@ -1,53 +0,0 @@
<h2>Show Account</h2>
<ul>
<li>
<strong>Username:</strong>
<%= @account.username %>
</li>
<li>
<strong>Domain:</strong>
<%= @account.domain %>
</li>
<li>
<strong>Display name:</strong>
<%= @account.display_name %>
</li>
<li>
<strong>Description:</strong>
<%= @account.description %>
</li>
<li>
<strong>Private key:</strong>
<%= @account.private_key %>
</li>
<li>
<strong>Public key:</strong>
<%= @account.public_key %>
</li>
<li>
<strong>Suspended:</strong>
<%= @account.suspended %>
</li>
<li>
<strong>Uri:</strong>
<%= @account.uri %>
</li>
<li>
<strong>Url:</strong>
<%= @account.url %>
</li>
</ul>
<span><%= link "Edit", to: account_path(@conn, :edit, @account) %></span>
<span><%= link "Back", to: account_path(@conn, :index) %></span>

View file

@ -1 +0,0 @@
<!DOCTYPE html><html><head><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons" rel=stylesheet><script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBF37pw38j0giICt73TCAPNogc07Upe_Q4&libraries=places"></script><meta charset=utf-8><title>libre-event</title><link href=/css/app.c6f4f0637b07f4b32d59e43e26ada6c7.css rel=stylesheet></head><body><noscript>Mets du JS.</noscript><div id=app></div><script type=text/javascript src=/js/manifest.79c2975577a8222315fd.js></script><script type=text/javascript src=/js/vendor.94561603df84d1708ae1.js></script><script type=text/javascript src=/js/app.dc4c839388191b886181.js></script></body></html>

View file

@ -1,5 +0,0 @@
<h2>Edit Category</h2>
<%= render "form.html", Map.put(assigns, :action, category_path(@conn, :update, @category)) %>
<span><%= link "Back", to: category_path(@conn, :index) %></span>

View file

@ -1,23 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :title, class: "control-label" %>
<%= text_input f, :title, class: "form-control" %>
<%= error_tag f, :title %>
</div>
<div class="form-group">
<%= label f, :picture, class: "control-label" %>
<%= text_input f, :picture, class: "form-control" %>
<%= error_tag f, :picture %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,28 +0,0 @@
<h2>Listing Categories</h2>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Picture</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for category <- @categories do %>
<tr>
<td><%= category.title %></td>
<td><%= category.picture %></td>
<td class="text-right">
<span><%= link "Show", to: category_path(@conn, :show, category), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: category_path(@conn, :edit, category), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: category_path(@conn, :delete, category), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Category", to: category_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Category</h2>
<%= render "form.html", Map.put(assigns, :action, category_path(@conn, :create)) %>
<span><%= link "Back", to: category_path(@conn, :index) %></span>

View file

@ -1,18 +0,0 @@
<h2>Show Category</h2>
<ul>
<li>
<strong>Title:</strong>
<%= @category.title %>
</li>
<li>
<strong>Picture:</strong>
<%= @category.picture %>
</li>
</ul>
<span><%= link "Edit", to: category_path(@conn, :edit, @category) %></span>
<span><%= link "Back", to: category_path(@conn, :index) %></span>

View file

@ -1,5 +0,0 @@
<h2>Edit Event</h2>
<%= render "form.html", Map.put(assigns, :action, event_path(@conn, :update, @event)) %>
<span><%= link "Back", to: event_path(@conn, :index) %></span>

View file

@ -1,35 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :title, class: "control-label" %>
<%= text_input f, :title, class: "form-control" %>
<%= error_tag f, :title %>
</div>
<div class="form-group">
<%= label f, :description, class: "control-label" %>
<%= text_input f, :description, class: "form-control" %>
<%= error_tag f, :description %>
</div>
<div class="form-group">
<%= label f, :begin_on, class: "control-label" %>
<%= datetime_select f, :begin_on, class: "form-control" %>
<%= error_tag f, :begin_on %>
</div>
<div class="form-group">
<%= label f, :ends_on, class: "control-label" %>
<%= datetime_select f, :ends_on, class: "form-control" %>
<%= error_tag f, :ends_on %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,32 +0,0 @@
<h2>Listing Events</h2>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Begin on</th>
<th>Ends on</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for event <- @events do %>
<tr>
<td><%= event.title %></td>
<td><%= event.description %></td>
<td><%= event.begin_on %></td>
<td><%= event.ends_on %></td>
<td class="text-right">
<span><%= link "Show", to: event_path(@conn, :show, event), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: event_path(@conn, :edit, event), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: event_path(@conn, :delete, event), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Event", to: event_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Event</h2>
<%= render "form.html", Map.put(assigns, :action, event_path(@conn, :create)) %>
<span><%= link "Back", to: event_path(@conn, :index) %></span>

View file

@ -1,28 +0,0 @@
<h2>Show Event</h2>
<ul>
<li>
<strong>Title:</strong>
<%= @event.title %>
</li>
<li>
<strong>Description:</strong>
<%= @event.description %>
</li>
<li>
<strong>Begin on:</strong>
<%= @event.begin_on %>
</li>
<li>
<strong>Ends on:</strong>
<%= @event.ends_on %>
</li>
</ul>
<span><%= link "Edit", to: event_path(@conn, :edit, @event) %></span>
<span><%= link "Back", to: event_path(@conn, :index) %></span>

View file

@ -1,5 +0,0 @@
<h2>Edit Event accounts</h2>
<%= render "form.html", Map.put(assigns, :action, event_accounts_path(@conn, :update, @event_accounts)) %>
<span><%= link "Back", to: event_accounts_path(@conn, :index) %></span>

View file

@ -1,17 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :roles, class: "control-label" %>
<%= number_input f, :roles, class: "form-control" %>
<%= error_tag f, :roles %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,26 +0,0 @@
<h2>Listing Event accounts</h2>
<table class="table">
<thead>
<tr>
<th>Roles</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for event_accounts <- @event_accounts do %>
<tr>
<td><%= event_accounts.roles %></td>
<td class="text-right">
<span><%= link "Show", to: event_accounts_path(@conn, :show, event_accounts), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: event_accounts_path(@conn, :edit, event_accounts), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: event_accounts_path(@conn, :delete, event_accounts), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Event accounts", to: event_accounts_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Event accounts</h2>
<%= render "form.html", Map.put(assigns, :action, event_accounts_path(@conn, :create)) %>
<span><%= link "Back", to: event_accounts_path(@conn, :index) %></span>

View file

@ -1,13 +0,0 @@
<h2>Show Event accounts</h2>
<ul>
<li>
<strong>Roles:</strong>
<%= @event_accounts.roles %>
</li>
</ul>
<span><%= link "Edit", to: event_accounts_path(@conn, :edit, @event_accounts) %></span>
<span><%= link "Back", to: event_accounts_path(@conn, :index) %></span>

View file

@ -1,5 +0,0 @@
<h2>Edit Event request</h2>
<%= render "form.html", Map.put(assigns, :action, event_request_path(@conn, :update, @event_request)) %>
<span><%= link "Back", to: event_request_path(@conn, :index) %></span>

View file

@ -1,17 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :state, class: "control-label" %>
<%= number_input f, :state, class: "form-control" %>
<%= error_tag f, :state %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,26 +0,0 @@
<h2>Listing Event requests</h2>
<table class="table">
<thead>
<tr>
<th>State</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for event_request <- @event_requests do %>
<tr>
<td><%= event_request.state %></td>
<td class="text-right">
<span><%= link "Show", to: event_request_path(@conn, :show, event_request), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: event_request_path(@conn, :edit, event_request), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: event_request_path(@conn, :delete, event_request), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Event request", to: event_request_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Event request</h2>
<%= render "form.html", Map.put(assigns, :action, event_request_path(@conn, :create)) %>
<span><%= link "Back", to: event_request_path(@conn, :index) %></span>

View file

@ -1,13 +0,0 @@
<h2>Show Event request</h2>
<ul>
<li>
<strong>State:</strong>
<%= @event_request.state %>
</li>
</ul>
<span><%= link "Edit", to: event_request_path(@conn, :edit, @event_request) %></span>
<span><%= link "Back", to: event_request_path(@conn, :index) %></span>

View file

@ -1,5 +0,0 @@
<h2>Edit Group</h2>
<%= render "form.html", Map.put(assigns, :action, group_path(@conn, :update, @group)) %>
<span><%= link "Back", to: group_path(@conn, :index) %></span>

View file

@ -1,41 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :title, class: "control-label" %>
<%= text_input f, :title, class: "form-control" %>
<%= error_tag f, :title %>
</div>
<div class="form-group">
<%= label f, :description, class: "control-label" %>
<%= text_input f, :description, class: "form-control" %>
<%= error_tag f, :description %>
</div>
<div class="form-group">
<%= label f, :suspended, class: "control-label" %>
<%= checkbox f, :suspended, class: "checkbox" %>
<%= error_tag f, :suspended %>
</div>
<div class="form-group">
<%= label f, :url, class: "control-label" %>
<%= text_input f, :url, class: "form-control" %>
<%= error_tag f, :url %>
</div>
<div class="form-group">
<%= label f, :uri, class: "control-label" %>
<%= text_input f, :uri, class: "form-control" %>
<%= error_tag f, :uri %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,34 +0,0 @@
<h2>Listing Groups</h2>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Suspended</th>
<th>Url</th>
<th>Uri</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for group <- @groups do %>
<tr>
<td><%= group.title %></td>
<td><%= group.description %></td>
<td><%= group.suspended %></td>
<td><%= group.url %></td>
<td><%= group.uri %></td>
<td class="text-right">
<span><%= link "Show", to: group_path(@conn, :show, group), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: group_path(@conn, :edit, group), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: group_path(@conn, :delete, group), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Group", to: group_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Group</h2>
<%= render "form.html", Map.put(assigns, :action, group_path(@conn, :create)) %>
<span><%= link "Back", to: group_path(@conn, :index) %></span>

View file

@ -1,33 +0,0 @@
<h2>Show Group</h2>
<ul>
<li>
<strong>Title:</strong>
<%= @group.title %>
</li>
<li>
<strong>Description:</strong>
<%= @group.description %>
</li>
<li>
<strong>Suspended:</strong>
<%= @group.suspended %>
</li>
<li>
<strong>Url:</strong>
<%= @group.url %>
</li>
<li>
<strong>Uri:</strong>
<%= @group.uri %>
</li>
</ul>
<span><%= link "Edit", to: group_path(@conn, :edit, @group) %></span>
<span><%= link "Back", to: group_path(@conn, :index) %></span>

View file

@ -1,5 +0,0 @@
<h2>Edit Group account</h2>
<%= render "form.html", Map.put(assigns, :action, group_account_path(@conn, :update, @group_account)) %>
<span><%= link "Back", to: group_account_path(@conn, :index) %></span>

View file

@ -1,17 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<div class="form-group">
<%= label f, :role, class: "control-label" %>
<%= number_input f, :role, class: "form-control" %>
<%= error_tag f, :role %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>

View file

@ -1,26 +0,0 @@
<h2>Listing Group accounts</h2>
<table class="table">
<thead>
<tr>
<th>Role</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for group_account <- @group_accounts do %>
<tr>
<td><%= group_account.role %></td>
<td class="text-right">
<span><%= link "Show", to: group_account_path(@conn, :show, group_account), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: group_account_path(@conn, :edit, group_account), class: "btn btn-default btn-xs" %></span>
<span><%= link "Delete", to: group_account_path(@conn, :delete, group_account), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Group account", to: group_account_path(@conn, :new) %></span>

View file

@ -1,5 +0,0 @@
<h2>New Group account</h2>
<%= render "form.html", Map.put(assigns, :action, group_account_path(@conn, :create)) %>
<span><%= link "Back", to: group_account_path(@conn, :index) %></span>

View file

@ -1,13 +0,0 @@
<h2>Show Group account</h2>
<ul>
<li>
<strong>Role:</strong>
<%= @group_account.role %>
</li>
</ul>
<span><%= link "Edit", to: group_account_path(@conn, :edit, @group_account) %></span>
<span><%= link "Back", to: group_account_path(@conn, :index) %></span>

Some files were not shown because too many files have changed in this diff Show more