Start with a Rails app with authentication via Persona, Foundation CSS

This commit is contained in:
Andreas Haller 2014-11-19 17:07:05 +01:00
parent 9ac52066b4
commit 7cd9f207f5
72 changed files with 2586 additions and 0 deletions

0
app/assets/images/.keep Normal file
View file

View 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
}
}
});
});

View 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/

View 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
*/

File diff suppressed because it is too large Load diff

View 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/

View 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

View file

View file

@ -0,0 +1,4 @@
class SearchController < ApplicationController
def index
end
end

View 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
View file

0
app/models/.keep Normal file
View file

View file

5
app/models/user.rb Normal file
View 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

View 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

View 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

View file

@ -0,0 +1,4 @@
= form_tag(search_path, method: :get)
= label_tag(:q, 'Suche:')
= text_field_tag(:q)
= submit_tag 'Suchen', class: 'button'