adva-user 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,5 @@
1
+ require 'admin/base_controller'
2
+
3
+ Admin::BaseController.class_eval do
4
+ before_filter :authenticate_user!
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'installations_controller'
2
+
3
+ InstallationsController.class_eval do
4
+ before_filter :set_admin_params, :only => :create
5
+
6
+ def set_admin_params
7
+ params[:site][:account_attributes][:users_attributes] ||= [{ :email => 'admin@admin.org', :password => 'admin!' }]
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ class User::ConfirmationsController < Devise::ConfirmationsController
2
+ layout 'user'
3
+ end
@@ -0,0 +1,3 @@
1
+ class User::PasswordsController < Devise::PasswordsController
2
+ layout 'user'
3
+ end
@@ -0,0 +1,3 @@
1
+ class User::RegistrationsController < Devise::RegistrationsController
2
+ layout 'user'
3
+ end
@@ -0,0 +1,7 @@
1
+ class User::SessionsController < Devise::SessionsController
2
+ layout 'user'
3
+
4
+ def after_sign_in_path_for(resource)
5
+ params[:return_to] || '/'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class User::UnlocksController < Devise::UnlocksController
2
+ layout 'user'
3
+ end
@@ -0,0 +1,4 @@
1
+ Account.class_eval do
2
+ has_many :users, :dependent => :destroy
3
+ accepts_nested_attributes_for :users
4
+ end
@@ -0,0 +1,12 @@
1
+ require 'devise'
2
+
3
+ class User < ActiveRecord::Base
4
+ devise :database_authenticatable, :registerable, :rememberable, :confirmable,
5
+ :recoverable, :validatable, :trackable
6
+
7
+ serialize :roles, Array
8
+
9
+ def roles
10
+ read_attribute(:roles) || []
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require_dependency 'layouts/admin'
2
+ require_dependency 'layouts/admin/_header'
3
+
4
+ module Layouts::Admin::Header::User
5
+ def right
6
+ login_status
7
+ super
8
+ end
9
+
10
+ def login_status
11
+ link_to t('.sign_out', :user => current_user.email), destroy_user_session_path
12
+ self << '&middot;'.html_safe
13
+ end
14
+
15
+ Layouts::Admin::Header.send(:include, self)
16
+ end
@@ -0,0 +1,2 @@
1
+ class Layouts::User < Layouts::Simple
2
+ end
@@ -0,0 +1,5 @@
1
+ <p>Welcome <%= @resource.email %>!</p>
2
+
3
+ <p>You can confirm your account through the link below:</p>
4
+
5
+ <p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Someone has requested a link to change your password, and you can do this through the link below.</p>
4
+
5
+ <p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
6
+
7
+ <p>If you didn't request this, please ignore this email.</p>
8
+ <p>Your password won't change until you access the link above and create a new one.</p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
@@ -0,0 +1,16 @@
1
+ class User::Confirmations::New < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ form.input :email
10
+ end
11
+
12
+ def form_arguments
13
+ [resource, { :as => resource_name, :url => confirmation_path(resource_name) }]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,67 @@
1
+ class User::Form < Adva::View::Form
2
+ include do
3
+ def fields
4
+ devise_error_messages!
5
+ super
6
+ end
7
+
8
+ def button_group
9
+ super
10
+ links
11
+ end
12
+
13
+ def buttons
14
+ form.submit t(:'.submit')
15
+ end
16
+
17
+ def links
18
+ ul :class => 'links user' do
19
+ li { sign_in_link } if sign_in?
20
+ li { sign_up_link } if sign_up?
21
+ li { forgot_password_link } if forgot_password?
22
+ li { resend_confirmation_link } if resend_confirmation?
23
+ li { resend_unlock_link } if resend_unlock?
24
+ end
25
+ end
26
+
27
+ def sign_in?
28
+ controller_name != 'sessions'
29
+ end
30
+
31
+ def sign_up?
32
+ devise_mapping.registerable? && controller_name != 'registrations'
33
+ end
34
+
35
+ def forgot_password?
36
+ devise_mapping.recoverable? && controller_name != 'passwords'
37
+ end
38
+
39
+ def resend_confirmation?
40
+ devise_mapping.confirmable? && controller_name != 'confirmations'
41
+ end
42
+
43
+ def resend_unlock?
44
+ devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
45
+ end
46
+
47
+ def sign_in_link
48
+ capture { link_to(:'user.links.sign_in', new_session_path(resource_name), :class => :sign_in) }
49
+ end
50
+
51
+ def sign_up_link
52
+ capture { link_to(:'user.links.sign_up', new_registration_path(resource_name), :class => :sign_up) }
53
+ end
54
+
55
+ def forgot_password_link
56
+ capture { link_to(:'user.links.forgot_password', new_password_path(resource_name), :class => :forgot_password) }
57
+ end
58
+
59
+ def resend_confirmation_link
60
+ capture { link_to(:'user.links.resend_confirmation', new_confirmation_path(resource_name), :class => :resend_confirmation) }
61
+ end
62
+
63
+ def resend_unlock_link
64
+ capture { link_to(:'user.links.resend_unlock', new_unlock_path(resource_name), :class => :resend_unlock) }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,18 @@
1
+ class User::Passwords::Edit < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ form.hidden_field :reset_password_token
10
+ form.input :password
11
+ form.input :password_confirmation
12
+ end
13
+
14
+ def form_arguments
15
+ [resource, { :as => resource_name, :url => password_path(resource_name), :html => { :method => :put } }]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ class User::Passwords::New < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ form.input :email
10
+ end
11
+
12
+ def form_arguments
13
+ [resource, { :as => resource_name, :url => password_path(resource_name) }]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ class User::Registrations::Edit < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ form.input :email
10
+ form.input :password
11
+ form.input :password_confirmation
12
+ end
13
+
14
+ def form_arguments
15
+ [resource, { :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put } }]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ class User::Registrations::New < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ form.input :email
10
+ form.input :password
11
+ form.input :password_confirmation
12
+ end
13
+
14
+ def form_arguments
15
+ [resource, { :as => resource_name, :url => registration_path(resource_name) }]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ class User::Sessions::New < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ pass_return_to
10
+ form.input :email
11
+ form.input :password
12
+ remember_me if devise_mapping.rememberable?
13
+ end
14
+
15
+ def form_arguments
16
+ [resource, { :as => resource_name, :url => session_path(resource_name) }]
17
+ end
18
+
19
+ def remember_me
20
+ div :class => :checkbox_group do
21
+ form.check_box :remember_me
22
+ form.label :remember_me, :class => :inline
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ class User::Unlocks::New < User::Form
2
+ include do
3
+ def to_html
4
+ h2 :'.title'
5
+ super
6
+ end
7
+
8
+ def fields
9
+ form.input :email
10
+ end
11
+
12
+ def form_arguments
13
+ [resource, { :as => resource_name, :url => unlock_path(resource_name) }]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,54 @@
1
+ en:
2
+ user:
3
+ links:
4
+ sign_in: Sign in
5
+ sign_up: Sign up
6
+ forgot_password: Forgot password?
7
+ resend_confirmation: Resend confirmation
8
+ resend_unlock: Resend unlock
9
+ sessions:
10
+ new:
11
+ title: Sign in
12
+ submit: Sign in
13
+ registrations:
14
+ new:
15
+ title: Sign up
16
+ submit: Sign up
17
+ edit:
18
+ title: Edit account
19
+ submit: Update account
20
+ current_password_required: "We need your current password to confirm your changes."
21
+ confirmations:
22
+ new:
23
+ title: Resend confirmation instructions
24
+ submit: Resend instructions
25
+ passwords:
26
+ new:
27
+ title: Forgot your password?
28
+ submit: Send instructions
29
+ edit:
30
+ title: Change your password
31
+ submit: Change password
32
+ unlocks:
33
+ new:
34
+ title: Resend unlock instructions
35
+ submit: Send instructions
36
+
37
+ devise:
38
+ session:
39
+ user:
40
+ signed_in: 'Signed in successfully.'
41
+ signed_out: 'Signed out successfully.'
42
+
43
+ layouts:
44
+ default:
45
+ signed_in_as: "Signed in as %{user}"
46
+ sign_in: Sign in
47
+ sign_up: Sign up
48
+ sign_out: Sign out
49
+
50
+ admin:
51
+ header:
52
+ sign_in: Sign in
53
+ sign_up: Sign up
54
+ sign_out: Sign out %{user}
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ devise_for :user, :module => 'user'
3
+ end
data/lib/adva/user.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'adva/engine'
2
+ require 'devise'
3
+
4
+ module Adva
5
+ class User < ::Rails::Engine
6
+ include Adva::Engine
7
+
8
+ # TODO should probably happen in the client app
9
+ # for more devise options see http://bit.ly/bwxrGg
10
+ initializer 'adva-user.devise_setup' do |app|
11
+
12
+ # FIXME
13
+ app.config.action_mailer.default_url_options = { :host => 'www.example.com' }
14
+
15
+ Devise.setup do |config|
16
+ require 'devise/orm/active_record'
17
+ config.mailer_sender = 'please-change-me@config-initializers-devise.com'
18
+ config.encryptor = :bcrypt
19
+ config.password_length = 5..20
20
+ end
21
+
22
+ Devise::FailureApp.class_eval do
23
+ def redirect
24
+ flash[:alert] = i18n_message unless flash[:notice]
25
+ redirect_to send(:"new_#{scope}_session_path", :return_to => attempted_path)
26
+ end
27
+ end
28
+ end
29
+
30
+ initializer 'adva-user.register_asset_expansions' do
31
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion(
32
+ :user => %w()
33
+ )
34
+
35
+ ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion(
36
+ :user => %w( adva-core/default/forms
37
+ adva-core/admin/common
38
+ adva-user/user )
39
+ )
40
+ end
41
+ end
42
+ end
data/lib/adva-user.rb ADDED
@@ -0,0 +1 @@
1
+ require 'adva/user'
@@ -0,0 +1,11 @@
1
+ Factory.define :user, :class => User do |f|
2
+ f.sequence(:email) { |n| "user-#{n}@example.com" }
3
+ f.password 'password'
4
+ f.after_build { |user| User.deactivate_callbacks }
5
+ f.after_create { |user| user.confirm!; User.activate_callbacks }
6
+ end
7
+
8
+ Factory.define :admin, :parent => :user do |f|
9
+ f.email 'admin@admin.org'
10
+ f.password 'admin!'
11
+ end
@@ -0,0 +1,14 @@
1
+ module Adva::User::Paths
2
+ def path_to(page)
3
+ case page
4
+ when /^the sign in page$/
5
+ new_user_session_path
6
+ when /^the new registration page$/
7
+ new_user_registration_path
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
13
+
14
+ World(Adva::User::Paths)
@@ -0,0 +1,16 @@
1
+ Given /^I am signed in with "([^"]*)" and "([^"]*)"$/ do |email, password|
2
+ get new_user_session_path
3
+ fill_in 'Email', :with => email
4
+ fill_in 'Password', :with => password
5
+ click_button 'Sign in'
6
+ end
7
+
8
+ Given /a confirmed user with email "([^"]+)" and password "([^"]+)"/ do |email, password|
9
+ user = User.without_callbacks.create!(:email => email, :password => password)
10
+ user.confirm!
11
+ end
12
+
13
+ Then 'I should be signed in' do
14
+ When 'I go to the sign in page'
15
+ Then 'I should be on the homepage'
16
+ end
@@ -0,0 +1,30 @@
1
+ body {
2
+ font-size: 11pt;
3
+ }
4
+ #page {
5
+ border-top: 5px solid #c22222;
6
+ }
7
+ .main {
8
+ width: 400px;
9
+ margin: 0 auto;
10
+ padding-top: 0px;
11
+ }
12
+ #content {
13
+ padding: 20px 30px 30px 30px;
14
+ }
15
+
16
+ .links {
17
+ display: block !important;
18
+ margin-top: 30px;
19
+ }
20
+ .links li:first-child:before {
21
+ content: '';
22
+ }
23
+ .links .sign_in,
24
+ .links .sign_up,
25
+ .links .forgot_password,
26
+ .links .resend_confirmation,
27
+ .links .resend_unlock {
28
+ font-size: 9pt;
29
+ color: #999;
30
+ }
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adva-user
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ingo Weiss
14
+ - Sven Fuchs
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-29 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: adva-core
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: devise
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 1
48
+ - 2
49
+ version: 1.1.2
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: "[description]"
53
+ email: nobody@adva-cms.org
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - app/controllers/user/passwords_controller.rb
62
+ - app/controllers/user/sessions_controller.rb
63
+ - app/controllers/user/unlocks_controller.rb
64
+ - app/controllers/user/confirmations_controller.rb
65
+ - app/controllers/user/registrations_controller.rb
66
+ - app/controllers/installations_controller_slice.rb
67
+ - app/controllers/admin/base_controller_slice.rb
68
+ - app/views/layouts/user.rb
69
+ - app/views/layouts/admin/_header_slice.rb
70
+ - app/views/user/unlocks/new.html.rb
71
+ - app/views/user/sessions/new.html.rb
72
+ - app/views/user/passwords/edit.html.rb
73
+ - app/views/user/passwords/new.html.rb
74
+ - app/views/user/form.rb
75
+ - app/views/user/confirmations/new.html.rb
76
+ - app/views/user/registrations/edit.html.rb
77
+ - app/views/user/registrations/new.html.rb
78
+ - app/views/mailer/confirmation_instructions.html.erb
79
+ - app/views/mailer/unlock_instructions.html.erb
80
+ - app/views/mailer/reset_password_instructions.html.erb
81
+ - app/models/user.rb
82
+ - app/models/account_slice.rb
83
+ - config/routes.rb
84
+ - config/locales/en.yml
85
+ - lib/adva-user.rb
86
+ - lib/adva/user.rb
87
+ - lib/testing/factories.rb
88
+ - lib/testing/paths.rb
89
+ - lib/testing/step_definitions.rb
90
+ - public/stylesheets/adva-user/user.css
91
+ has_rdoc: true
92
+ homepage: http://github.com/svenfuchs/adva-cms2
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: "[none]"
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: "[summary]"
125
+ test_files: []
126
+