Permalink
Browse files

WIP User registers

  • Loading branch information...
1 parent d5f3d2a commit 1aa10d5c99351d66f94e86cc355774f373039fb2 Lee Smith committed Oct 15, 2011
View
1 .rspec
@@ -0,0 +1 @@
+--colour
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,95 @@
+/* CSS Reset */
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, canvas, details, embed,
+figure, figcaption, footer, header, hgroup,
+menu, nav, output, ruby, section, summary,
+time, mark, audio, video {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font-size: 100%;
+ font: inherit;
+ vertical-align: baseline;
+}
+article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
+body { line-height: 1; }
+ol, ul { list-style: none; }
+blockquote, q { quotes: none; }
+blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
+table { border-collapse: collapse; border-spacing: 0; }
+/* End Reset */
+
+body { color: #555; font: 13px/1.8 "Lucida Grande", Arial, sans-serif; font-size: 80%; background: #fff url('../images/bg_square.png') repeat; }
+
+body:before { content: ""; position: fixed; top: -10px; left: 0; width: 100%; height: 10px; -webkit-box-shadow: 0 0 10px rgba(0,0,0,0.8); -moz-box-shadow: 0 0 10px rgba(0,0,0,0.8); box-shadow: 0 0 10px rgba(0,0,0,0.8); z-index: 100; }
+
+header, section { width: 550px; margin: 10px auto; }
+section { margin-top: 30px; }
+
+h1 { font-size: 28px; margin-bottom: 12px; font-weight: bold; text-align: center; text-shadow: 1px 1px 0 #fff; }
+strong { font-weight: bold; }
+
+nav { text-align: center; }
+nav a, form a { color: #008ce5; text-decoration: none; }
+nav a:hover, form a:hover { border-bottom: 1px solid #008ce5; }
+
+form, article { width: 265px; margin: 0 auto; background: #fff; padding: 12px; border-radius: 4px; box-shadow: 1px 1px 3px rgba(0,0,0,0.3); -moz-border-radius: 4px; -webkit-border-radius: 4px; -moz-box-shadow: 1px 1px 3px rgba(0,0,0,0.3); -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,0.3); }
+article { width: 550px; text-align: center; }
+
+label { display: block; }
+label:hover { cursor: pointer; }
+#remember-me { display: inline; }
+
+#email, #password, #user_email, #user_email_confirmation, #user_password, #user_password_confirmation { font-size: 14px; padding: 3px; width: 80%; }
+
+#flash-notice, #flash-alert {
+ color: #585;
+ font-weight: bold;
+ margin: 0;
+ padding: 3px 0;
+}
+#flash-alert {
+ color: #c00;
+}
+
+.error_messages { color: #c00; padding-bottom: 12px; font-weight: bold; }
+
+.button {
+ border:1px solid #bbb;
+ border-radius:3px;
+ -moz-border-radius:3px;
+ -webkit-border-radius:3px;
+ -khtml-border-radius:3px;
+ background: -moz-linear-gradient(100% 100% 90deg, #d5d5d5, #f4f4f4);
+ background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f4f4f4), to(#d5d5d5));
+ background: -webkit-linear-gradient(#f4f4f4, #d5d5d5);
+ background: -o-linear-gradient(#f4f4f4, #d5d5d5);
+ color:#232d3d;
+ font-size:12px;
+ font-weight:bold;
+ padding:4px 10px;
+ margin:15px 0px 10px 0;
+ text-shadow:0px 1px 0px #fff;
+ cursor:pointer;
+ box-shadow:0px 1px 2px #ccc;
+ -moz-box-shadow:0px 1px 2px #ccc;
+ -webkit-box-shadow:0px 1px 2px #ccc;
+}
+
+.button:active, .button:hover {
+ color: #008ce5;
+}
+
+.button:active {
+ box-shadow:inset 0px 1px 2px #ccc;
+ -moz-box-shadow:inset 0px 1px 2px #ccc;
+ -webkit-box-shadow:inset 0px 1px 2px #ccc;
+}
@@ -1,3 +1,10 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ helper_method :authenticated_user
+
+ private
+
+ def authenticated_user
+ @authenticated_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
end
@@ -0,0 +1,11 @@
+class UsersController < ApplicationController
+ expose(:user)
+
+ def create
+ if user.save
+ redirect_to root_path, notice: t(:registration)
+ else
+ render :new
+ end
+ end
+end
View
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+ has_secure_password
+
+ validates_presence_of :password, on: :create
+ validates_confirmation_of :password
+ validates_presence_of :email, :password_confirmation
+ validates_uniqueness_of :email
+ validates_format_of :email, with: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i, allow_blank: true
+end
@@ -0,0 +1,11 @@
+!!!
+%html{lang: I18n.locale}
+ %head
+ %meta{charset: 'utf-8'}
+ = stylesheet_link_tag 'application'
+ = javascript_include_tag 'application'
+ = csrf_meta_tag
+ %title= t(:decent_authentication)
+ %body
+ %section
+ = yield
@@ -0,0 +1,19 @@
+%h1= t(:register)
+
+= form_for user do |f|
+ - if user.errors.any?
+ .error_messages
+ %ul
+ - for message in user.errors.full_messages
+ %li= message
+ %div
+ = f.label :email
+ = f.text_field :email
+ %div
+ = f.label :password
+ = f.password_field :password
+ %div
+ = f.label :password_confirmation
+ = f.password_field :password_confirmation
+ %div
+ = f.submit t(:register), class: 'button'
View
@@ -2,4 +2,6 @@
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
- hello: "Hello world"
+ decent_authentication: 'Decent Authentication'
+ register: 'Register'
+ registration: 'Registration was successful!'
View
@@ -1,58 +1,7 @@
DecentAuthentication::Application.routes.draw do
- # The priority is based upon order of creation:
- # first created -> highest priority.
+ root to: 'users#new'
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
+ get 'register' => 'users#new', as: 'register'
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ resources :users
end
@@ -0,0 +1,9 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :email
+ t.string :password_digest
+ t.timestamps
+ end
+ end
+end
View
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20111015033732) do
+
+ create_table "users", :force => true do |t|
+ t.string "email"
+ t.string "password_digest"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
Oops, something went wrong.

0 comments on commit 1aa10d5

Please sign in to comment.