mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
Start with a Rails app with authentication via Persona, Foundation CSS
This commit is contained in:
parent
9ac52066b4
commit
7cd9f207f5
72 changed files with 2586 additions and 0 deletions
0
app/assets/images/.keep
Normal file
0
app/assets/images/.keep
Normal file
34
app/assets/javascripts/application.js
Normal file
34
app/assets/javascripts/application.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
||||
// compiled file.
|
||||
//
|
||||
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
||||
// about supported directives.
|
||||
//
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require foundation
|
||||
//= require turbolinks
|
||||
//= require_tree .
|
||||
|
||||
$(function(){ $(document).foundation(); });
|
||||
|
||||
$('[data-persona-login]').click(function(e) {
|
||||
e.preventDefault();
|
||||
navigator.id.get(function(assertion) {
|
||||
if (assertion) {
|
||||
if (assertion) {
|
||||
var form = $('#browser-id-form');
|
||||
form.find('input[name=assertion]').val(assertion);
|
||||
form.submit();
|
||||
} else {
|
||||
// TODO: Handle failure
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
3
app/assets/javascripts/sessions.js.coffee
Normal file
3
app/assets/javascripts/sessions.js.coffee
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
17
app/assets/stylesheets/application.css
Normal file
17
app/assets/stylesheets/application.css
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
||||
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
||||
*
|
||||
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
||||
* compiled file so the styles you add here take precedence over styles defined in any styles
|
||||
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
||||
* file per style scope.
|
||||
*
|
||||
*= require_tree .
|
||||
*= require_self
|
||||
*= require foundation_and_overrides
|
||||
|
||||
*/
|
1443
app/assets/stylesheets/foundation_and_overrides.scss
Normal file
1443
app/assets/stylesheets/foundation_and_overrides.scss
Normal file
File diff suppressed because it is too large
Load diff
3
app/assets/stylesheets/sessions.css.scss
Normal file
3
app/assets/stylesheets/sessions.css.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the sessions controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
15
app/controllers/application_controller.rb
Normal file
15
app/controllers/application_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
def current_user
|
||||
User.find(session[:user_id]) if session[:user_id].present?
|
||||
end
|
||||
|
||||
def signed_in?
|
||||
!!current_user
|
||||
end
|
||||
|
||||
helper_method :current_user, :signed_in?
|
||||
end
|
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
4
app/controllers/search_controller.rb
Normal file
4
app/controllers/search_controller.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class SearchController < ApplicationController
|
||||
def index
|
||||
end
|
||||
end
|
19
app/controllers/sessions_controller.rb
Normal file
19
app/controllers/sessions_controller.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class SessionsController < ApplicationController
|
||||
def create
|
||||
if user = User.find_or_create_from_auth_hash(auth_hash)
|
||||
session[:user_id] = user.id
|
||||
end
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
reset_session
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def auth_hash
|
||||
request.env['omniauth.auth']
|
||||
end
|
||||
end
|
0
app/mailers/.keep
Normal file
0
app/mailers/.keep
Normal file
0
app/models/.keep
Normal file
0
app/models/.keep
Normal file
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
5
app/models/user.rb
Normal file
5
app/models/user.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class User < ActiveRecord::Base
|
||||
def self.find_or_create_from_auth_hash(hash)
|
||||
User.find_or_create_by(email: hash['info']['email'])
|
||||
end
|
||||
end
|
9
app/views/application/_login_button.html.slim
Normal file
9
app/views/application/_login_button.html.slim
Normal file
|
@ -0,0 +1,9 @@
|
|||
= form_tag '/auth/browser_id/callback', id: 'browser-id-form'
|
||||
= hidden_field_tag(:assertion)
|
||||
|
||||
- if signed_in?
|
||||
= link_to session_path, data: { method: :delete, logout: true }
|
||||
| Abmelden
|
||||
- else
|
||||
= link_to session_path, data: { 'persona-login' => true }
|
||||
| Anmelden
|
24
app/views/layouts/application.html.slim
Normal file
24
app/views/layouts/application.html.slim
Normal file
|
@ -0,0 +1,24 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
title Stadtratmonitor Leipzig
|
||||
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
|
||||
= javascript_include_tag 'vendor/modernizr'
|
||||
= csrf_meta_tags
|
||||
|
||||
body
|
||||
.row
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :div, msg, class: name
|
||||
.row
|
||||
.large-8.columns
|
||||
h2#title
|
||||
= link_to 'Willkommen in Leipzig', root_path
|
||||
.large-4.columns
|
||||
ul.inline-list.right
|
||||
li = render 'login_button'
|
||||
.row
|
||||
= yield
|
||||
|
||||
script src="https://login.persona.org/include.js"
|
||||
= javascript_include_tag 'application', 'data-turbolinks-track' => true
|
4
app/views/search/index.html.slim
Normal file
4
app/views/search/index.html.slim
Normal file
|
@ -0,0 +1,4 @@
|
|||
= form_tag(search_path, method: :get)
|
||||
= label_tag(:q, 'Suche:')
|
||||
= text_field_tag(:q)
|
||||
= submit_tag 'Suchen', class: 'button'
|
Loading…
Add table
Add a link
Reference in a new issue