honey-auth 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ class AccountsController < ApplicationController
2
+ before_filter :signed_in?, only: [:edit, :update]
3
+
4
+ def new
5
+ @user = User.new
6
+ end
7
+
8
+ def create
9
+ @user = User.new(params[:user])
10
+
11
+ if @user.save
12
+ sign_in @user
13
+ redirect_to signed_in_path(:created)
14
+ else
15
+ render 'accounts/new'
16
+ end
17
+ end
18
+
19
+ def update
20
+ params[:user].delete(:password) unless params[:user][:password].present?
21
+ @user = current_user
22
+ @user.attributes = params[:user]
23
+
24
+ if @user.save
25
+ redirect_to updated_account_path
26
+ else
27
+ render 'accounts/edit'
28
+ end
29
+ end
30
+
31
+ def edit
32
+ @user = current_user
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ class SessionsController < ApplicationController
2
+ before_filter :signed_in?, only: [:destroy]
3
+
4
+ def create
5
+ if @user = User.find_by_email(params[:user][:email]).try(:authenticate, params[:user][:password])
6
+ sign_in @user
7
+ redirect_to signed_in_path
8
+ else
9
+ @user = User.new
10
+ flash[:error] = 'bad email/password combination'
11
+ render :new
12
+ end
13
+ end
14
+
15
+ def destroy
16
+ sign_out
17
+ redirect_to signed_out_path, notice: 'Logged Out'
18
+ end
19
+
20
+ def new
21
+ @user = User.new
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ %article.edit-account-page
2
+ %h4 Edit your account
3
+
4
+ = form_for @user, url: account_path do |f|
5
+ = f.string :name
6
+ = f.email :email
7
+ = f.password :password
8
+ = f.password :password_confirmation
9
+ = f.actions save: 'Save'
@@ -0,0 +1,9 @@
1
+ %article.new-account-page
2
+ %h4 Create your account
3
+
4
+ = form_for @user, url: account_path do |f|
5
+ = f.string :name
6
+ = f.email :email
7
+ = f.password :password
8
+ = f.password :password_confirmation
9
+ = f.actions save: 'Save'
@@ -0,0 +1,7 @@
1
+ %article.new-session-page
2
+ %h4 Sign in to your account
3
+
4
+ = form_for @signing_in, url: session_path do |f|
5
+ = f.email :email, placeholder: 'Email'
6
+ = f.password :password, placeholder: 'Password', class: 'password'
7
+ = f.actions save: 'Sign in'
@@ -0,0 +1,71 @@
1
+ module Authentication
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ helper_method :current_user, :signed_in?, :sign_out?, :admin?
6
+ end
7
+
8
+ def require_user
9
+ if signed_in? then true else redirect_to(root_path) end
10
+ end
11
+
12
+ def current_user
13
+ if session[:user_id]
14
+ @current_user ||= User.find(session[:user_id])
15
+ end
16
+
17
+ @current_user
18
+ rescue ActiveRecord::RecordNotFound
19
+ sign_out
20
+ nil
21
+ end
22
+
23
+ def sign_in user
24
+ session[:user_id] = user.id
25
+ @current_user = user
26
+ end
27
+
28
+ def sign_out
29
+ reset_session
30
+ remove_instance_variable :@current_user if defined?(@current_user)
31
+ end
32
+
33
+ def signed_in?
34
+ !!current_user
35
+ end
36
+
37
+ def signed_out?
38
+ !signed_in?
39
+ end
40
+
41
+ def signed_in!
42
+ return if signed_in?
43
+ auth_failed
44
+ end
45
+
46
+ def auth_failed
47
+ sign_out
48
+ session[:attempted_path] = request.fullpath
49
+ redirect_to new_session_path, status: :see_other
50
+ end
51
+
52
+ def signed_out!
53
+
54
+ end
55
+
56
+ def admin?
57
+ signed_in? && current_user.role.admin?
58
+ end
59
+
60
+ def signed_in_path source
61
+ session[:attempted_path] || current_user.role.admin? ? cms_path : root_path
62
+ end
63
+
64
+ def updated_account_path
65
+ root_path
66
+ end
67
+
68
+ def signed_out_path
69
+ root_path
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ require 'honey_auth'
2
+ require 'authentication'
3
+ require 'honey_auth/engine'
@@ -0,0 +1,3 @@
1
+ module HoneyAuth
2
+ autoload :Routes, 'honey_auth/routes'
3
+ end
@@ -0,0 +1,5 @@
1
+ module HoneyAuth
2
+ class Engine < ::Rails::Engine
3
+ # stubbed for assets.. ?
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class HoneyAuth::Routes < SimpleDelegator
2
+ def draw
3
+ resource :session, :account
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honey-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Quinn Shanahan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: haml
16
+ requirement: &70319699519580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70319699519580
25
+ description: Very basic auth generator
26
+ email: q.shanahan@gmail.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - lib/authentication.rb
32
+ - lib/honey-auth.rb
33
+ - lib/honey_auth/engine.rb
34
+ - lib/honey_auth/routes.rb
35
+ - lib/honey_auth.rb
36
+ - app/controllers/accounts_controller.rb
37
+ - app/controllers/sessions_controller.rb
38
+ - app/views/accounts/edit.html.haml
39
+ - app/views/accounts/new.html.haml
40
+ - app/views/sessions/new.html.haml
41
+ homepage: https://github.com/honeyco/honey-auth
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.11
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Auth
65
+ test_files: []