tiny_core_users 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/lib/tiny_core/acts/user.rb +78 -0
  2. data/lib/tiny_core/controllers/admin_users.rb +18 -0
  3. data/lib/tiny_core/controllers/application.rb +70 -0
  4. data/lib/tiny_core/controllers/password_resets.rb +52 -0
  5. data/lib/tiny_core/controllers/user_sessions.rb +30 -0
  6. data/lib/tiny_core/controllers/users.rb +58 -0
  7. data/lib/tiny_core/mailers/password_resets_mailer.rb +9 -0
  8. data/lib/tiny_core/models/guest.rb +7 -0
  9. data/lib/tiny_core/role.rb +33 -0
  10. data/lib/tiny_core/role/admin.rb +17 -0
  11. data/lib/tiny_core/role/guest.rb +15 -0
  12. data/lib/tiny_core_users.rb +10 -0
  13. data/rails_generators/tiny_user/templates/admin/users/_index.html.erb +22 -0
  14. data/rails_generators/tiny_user/templates/admin/users/index.html.erb +11 -0
  15. data/rails_generators/tiny_user/templates/admin_users_controller.rb +3 -0
  16. data/rails_generators/tiny_user/templates/create_users.rb +29 -0
  17. data/rails_generators/tiny_user/templates/password_resets/edit.html.erb +17 -0
  18. data/rails_generators/tiny_user/templates/password_resets/index.html.erb +1 -0
  19. data/rails_generators/tiny_user/templates/password_resets/new.html.erb +12 -0
  20. data/rails_generators/tiny_user/templates/password_resets_controller.rb +3 -0
  21. data/rails_generators/tiny_user/templates/password_resets_mailer/password_reset_instructions.de.erb +10 -0
  22. data/rails_generators/tiny_user/templates/password_resets_mailer/password_reset_instructions.erb +10 -0
  23. data/rails_generators/tiny_user/templates/role/admin.rb +3 -0
  24. data/rails_generators/tiny_user/templates/role/guest.rb +3 -0
  25. data/rails_generators/tiny_user/templates/role/user.rb +3 -0
  26. data/rails_generators/tiny_user/templates/user.rb +3 -0
  27. data/rails_generators/tiny_user/templates/user_session.rb +2 -0
  28. data/rails_generators/tiny_user/templates/user_sessions/new.html.erb +19 -0
  29. data/rails_generators/tiny_user/templates/user_sessions_controller.rb +3 -0
  30. data/rails_generators/tiny_user/templates/users/edit.html.erb +18 -0
  31. data/rails_generators/tiny_user/templates/users/new.html.erb +34 -0
  32. data/rails_generators/tiny_user/templates/users/show.html.erb +36 -0
  33. data/rails_generators/tiny_user/templates/users_controller.rb +3 -0
  34. data/rails_generators/tiny_user/templates/users_de.yml +83 -0
  35. data/rails_generators/tiny_user/templates/users_en.yml +83 -0
  36. data/rails_generators/tiny_user/tiny_user_generator.rb +46 -0
  37. metadata +102 -0
@@ -0,0 +1,78 @@
1
+ module TinyCore
2
+ module Acts
3
+ module User
4
+ module ActsMethods
5
+ def acts_as_user
6
+ acts_as_authentic
7
+ validates_presence_of :full_name
8
+
9
+ attr_protected :role
10
+
11
+ extend ClassMethods
12
+ include InstanceMethods
13
+ end
14
+ end
15
+
16
+ module ClassMethods
17
+ def from_param!(param)
18
+ find(param)
19
+ end
20
+
21
+ def paginate_for_list(filter, options = {})
22
+ with_search_scope(filter) do
23
+ paginate(options.merge(:order => 'users.created_at DESC'))
24
+ end
25
+ end
26
+
27
+ protected
28
+ def with_search_scope(filter, &block)
29
+ conditions = filter.empty? ? nil : ['users.full_name LIKE ? OR users.email LIKE ?', "%#{filter.query}%", "%#{filter.query}%"]
30
+ with_scope :find => { :conditions => conditions } do
31
+ yield
32
+ end
33
+ end
34
+ end
35
+
36
+ module InstanceMethods
37
+ def after_initialize
38
+ if self.role.blank?
39
+ extend ::Role::User
40
+ else
41
+ extend "::Role::#{self.role.classify}".constantize
42
+ end
43
+ end
44
+
45
+ def deliver_password_reset_instructions!
46
+ reset_perishable_token!
47
+ PasswordResetsMailer.deliver_password_reset_instructions(self)
48
+ end
49
+
50
+ def reset_password!(password, password_confirmation)
51
+ # We need to check for blank password explicitly, because authlogic only performs that check on create.
52
+ if password.blank? || password_confirmation.blank?
53
+ errors.add(:password, I18n.t('authlogic.error_messages.password_blank'))
54
+ return false
55
+ else
56
+ self.password = password
57
+ self.password_confirmation = password_confirmation
58
+ save
59
+ end
60
+ end
61
+
62
+ def name
63
+ full_name
64
+ end
65
+
66
+ def guest?
67
+ false
68
+ end
69
+ end
70
+
71
+ def self.included(receiver)
72
+ receiver.extend ActsMethods
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ ActiveRecord::Base.send :include, TinyCore::Acts::User
@@ -0,0 +1,18 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module AdminUsers
4
+ def self.included(receiver)
5
+ receiver.before_filter :login_required
6
+ receiver.before_filter :can_see_all_users!
7
+ end
8
+
9
+ def index
10
+ @search_filter = SearchFilter.new(params[:search_filter])
11
+ @users = User.paginate_for_list(@search_filter, :page => params[:page])
12
+ render :update do |page|
13
+ page.replace_html 'users', :partial => 'index'
14
+ end if request.xhr?
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,70 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module Application
4
+ def self.included(receiver)
5
+ receiver.helper_method :current_user_session, :current_user, :logged_in?
6
+ end
7
+
8
+ protected
9
+ def method_missing(method, *args)
10
+ if method.to_s =~ /^can_.*\?$/
11
+ if current_user.send(method, *args)
12
+ yield if block_given?
13
+ true
14
+ else
15
+ false
16
+ end
17
+ elsif method.to_s =~ /^can_.*\!$/
18
+ if current_user.send(method.to_s.gsub(/\!$/, '?'), *args)
19
+ yield if block_given?
20
+ else
21
+ flash[:error] = t('flash.error.access_denied')
22
+ redirect_to root_path
23
+ false
24
+ end
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ def login_required
31
+ deny_access(I18n.t("flash.error.login_required"), login_path) unless logged_in?
32
+ end
33
+
34
+ def guest_required
35
+ deny_access(I18n.t("flash.error.guest_required")) if logged_in?
36
+ end
37
+
38
+ def deny_access(message = nil, path = root_path)
39
+ store_location
40
+ flash[:error] = message || I18n.t("flash.error.access_denied")
41
+ redirect_to path
42
+ return false
43
+ end
44
+
45
+ def store_location
46
+ session[:return_to] = request.request_uri
47
+ end
48
+
49
+ def redirect_back_or_default(default)
50
+ redirect_to(session[:return_to] || default)
51
+ session[:return_to] = nil
52
+ end
53
+
54
+ def logged_in?
55
+ !current_user.guest?
56
+ end
57
+
58
+ private
59
+ def current_user_session
60
+ return @current_user_session if defined?(@current_user_session)
61
+ @current_user_session = UserSession.find
62
+ end
63
+
64
+ def current_user
65
+ return @current_user if defined?(@current_user)
66
+ @current_user = (current_user_session && current_user_session.user) || Guest.new
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,52 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module PasswordResets
4
+ def self.included(receiver)
5
+ receiver.before_filter :load_user_using_perishable_token, :only => [:edit, :update]
6
+ receiver.before_filter :guest_required
7
+ end
8
+
9
+ def index
10
+ render
11
+ end
12
+
13
+ def new
14
+ render
15
+ end
16
+
17
+ def create
18
+ @user = User.find_by_email(params[:email])
19
+ if @user
20
+ @user.deliver_password_reset_instructions!
21
+ flash[:notice] = I18n.t("flash.notice.password_instructions_sent")
22
+ redirect_to password_resets_path
23
+ else
24
+ flash[:error] = I18n.t("flash.error.user_by_email_not_found")
25
+ render :action => :new
26
+ end
27
+ end
28
+
29
+ def edit
30
+ render
31
+ end
32
+
33
+ def update
34
+ if @user.reset_password!(params[:user][:password], params[:user][:password_confirmation])
35
+ flash[:notice] = I18n.t("flash.notice.password_updated")
36
+ redirect_to root_path
37
+ else
38
+ render :action => :edit
39
+ end
40
+ end
41
+
42
+ private
43
+ def load_user_using_perishable_token
44
+ @user = User.find_using_perishable_token(params[:id])
45
+ unless @user
46
+ flash[:error] = I18n.t("flash.error.user_could_not_be_located")
47
+ redirect_to login_path
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,30 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module UserSessions
4
+ def self.included(receiver)
5
+ receiver.before_filter :guest_required, :only => [ :new, :create ]
6
+ receiver.skip_before_filter :verify_authenticity_token, :only => :create
7
+ end
8
+
9
+ def new
10
+ @user_session = UserSession.new
11
+ end
12
+
13
+ def create
14
+ @user_session = UserSession.new(params[:user_session])
15
+ if @user_session.save
16
+ flash[:notice] = I18n.t("flash.notice.logged_in")
17
+ redirect_back_or_default root_path
18
+ else
19
+ render :action => :new
20
+ end
21
+ end
22
+
23
+ def destroy
24
+ current_user_session.destroy
25
+ flash[:notice] = I18n.t("flash.notice.logged_out")
26
+ redirect_to login_path
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module Users
4
+ def self.included(receiver)
5
+ receiver.before_filter :login_required, :only => [:index, :show, :edit, :update]
6
+ end
7
+
8
+ def index
9
+ redirect_to account_path(current_user.current_account)
10
+ end
11
+
12
+ def new
13
+ @user = User.new
14
+ end
15
+
16
+ def create
17
+ if logged_in? && current_user.respond_to?(:current_account)
18
+ @user = current_user.current_account.users.build(params[:user])
19
+ @user.current_account = current_user.current_account
20
+ else
21
+ @user = User.new(params[:user])
22
+ end
23
+
24
+ if @user.save
25
+ flash[:notice] = I18n.t('flash.notice.created_user')
26
+
27
+ if logged_in?
28
+ @user.accounts << current_user.current_account if current_user.respond_to?(:current_account)
29
+ redirect_to new_user_path
30
+ else
31
+ redirect_back_or_default root_path
32
+ end
33
+ else
34
+ render :action => :new
35
+ end
36
+ end
37
+
38
+ def show
39
+ @user = User.find(params[:id])
40
+ end
41
+
42
+ def edit
43
+ @user = User.find(params[:id])
44
+ end
45
+
46
+ def update
47
+ @user = User.find(params[:id])
48
+ if @user.update_attributes(params[:user])
49
+ flash[:notice] = I18n.t('flash.notice.updated_user')
50
+ redirect_to root_path
51
+ else
52
+ render :action => :edit
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,9 @@
1
+ class PasswordResetsMailer < ActionMailer::Base
2
+ def password_reset_instructions(user)
3
+ subject I18n.t("password_reset_mailer.subject")
4
+ from "#{TinyCore::Application.name} <#{TinyCore::Config.email_sender_address}>"
5
+ recipients user.email
6
+ sent_on Time.now
7
+ body :edit_password_reset_path => edit_password_reset_path(user.perishable_token)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class Guest
2
+ include Role::Guest
3
+
4
+ def guest?
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module TinyCore
2
+ module Role
3
+ module ClassMethods
4
+ def allow(*things)
5
+ things.each do |thing|
6
+ define_method "can_#{thing}?" do
7
+ true
8
+ end
9
+ end
10
+ end
11
+
12
+ def allow_if_owner(*things)
13
+ things.each do |thing|
14
+ define_method "can_#{thing}?" do |model|
15
+ model.user == self
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def method_missing(method, *args)
22
+ if method.to_s =~ /^can_.*\?$/
23
+ false
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ def self.included(base)
30
+ base.extend ClassMethods
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module TinyCore
2
+ module Role
3
+ module Admin
4
+ include TinyCore::Role
5
+
6
+ allow :assign_roles
7
+
8
+ def method_missing(method, *args)
9
+ if method.to_s =~ /^can_.*\?$/
10
+ true
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module TinyCore
2
+ module Role
3
+ module Guest
4
+ include TinyCore::Role
5
+
6
+ def method_missing(method, *args)
7
+ if method.to_s =~ /^can_.*\?$/
8
+ false
9
+ else
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # require all necessary files here
2
+
3
+ require File.dirname(__FILE__) + '/tiny_core/acts/user'
4
+ require File.dirname(__FILE__) + '/tiny_core/controllers/application'
5
+ require File.dirname(__FILE__) + '/tiny_core/controllers/admin_users'
6
+ require File.dirname(__FILE__) + '/tiny_core/controllers/password_resets'
7
+ require File.dirname(__FILE__) + '/tiny_core/controllers/user_sessions'
8
+ require File.dirname(__FILE__) + '/tiny_core/controllers/users'
9
+ require File.dirname(__FILE__) + '/tiny_core/mailers/password_resets_mailer'
10
+ require File.dirname(__FILE__) + '/tiny_core/models/guest'
@@ -0,0 +1,22 @@
1
+ <%= will_paginate @users %>
2
+
3
+ <table class="list">
4
+ <thead>
5
+ <tr>
6
+ <th><%= t('.name') %></th>
7
+ <th><%= t('.email') %></th>
8
+ <th><%= t('.options') %></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% @users.each do |user| %>
13
+ <tr>
14
+ <td><%= link_to highlight(user.full_name, @search_filter.query), user_path(user) %></td>
15
+ <td><%= mail_to user.email, highlight(user.email, @search_filter.query) %></td>
16
+ <td><%= link_to t(".edit"), edit_user_path(user) %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+
22
+ <%= will_paginate @users %>
@@ -0,0 +1,11 @@
1
+ <h2><%= t('.all_users') %></h2>
2
+
3
+ <% if @users.empty? %>
4
+ <p><%= t('.no_users') %></p>
5
+ <% else %>
6
+ <%= render :partial => "/shared/filter", :locals => { :url => admin_users_path } %>
7
+
8
+ <div id="users">
9
+ <%= render :partial => "index" %>
10
+ </div>
11
+ <% end %>
@@ -0,0 +1,3 @@
1
+ class Admin::UsersController < ApplicationController
2
+ include TinyCore::Controllers::AdminUsers
3
+ end
@@ -0,0 +1,29 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :full_name, :null => false
5
+ t.string :email, :null => false
6
+ t.string :crypted_password, :null => false
7
+ t.string :password_salt, :null => false
8
+ t.string :persistence_token, :null => false
9
+ t.string :single_access_token, :null => false
10
+ t.string :perishable_token, :null => false
11
+
12
+ t.integer :login_count, :null => false, :default => 0
13
+ t.integer :failed_login_count, :null => false, :default => 0
14
+ t.datetime :last_request_at
15
+ t.datetime :current_login_at
16
+ t.datetime :last_login_at
17
+ t.string :current_login_ip
18
+ t.string :last_login_ip
19
+
20
+ t.string :role
21
+
22
+ t.timestamps
23
+ end
24
+ end
25
+
26
+ def self.down
27
+ drop_table :users
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ <h2><%= t('.change_password') %></h2>
2
+
3
+ <% form_for @user, :url => password_reset_path, :method => :put, :html => { :class => 'form' } do |f| %>
4
+ <%= f.error_messages :header_message => t('.could_not_reset_password') %>
5
+
6
+ <p class="form_item">
7
+ <span class="label"><%= f.label :password, t('.password') %></span>
8
+ <%= f.password_field :password %>
9
+ </p>
10
+
11
+ <p class="form_item">
12
+ <span class="label"><%= f.label :password_confirmation, t('.password_confirmation') %></span>
13
+ <%= f.password_field :password_confirmation %>
14
+ </p>
15
+
16
+ <p><%= f.submit t('.update') %></p>
17
+ <% end %>
@@ -0,0 +1 @@
1
+ <p><%= t('.instructions') %></p>
@@ -0,0 +1,12 @@
1
+ <h2><%= t('.forgot_password') %></h2>
2
+
3
+ <p><%= t('.instructions') %></p>
4
+
5
+ <% form_tag password_resets_path do %>
6
+ <p class="form_item">
7
+ <span class="label"><label><%= t('.email') %></label></span>
8
+ <%= text_field_tag "email" %>
9
+ </p>
10
+
11
+ <p><%= submit_tag t('.reset') %></p>
12
+ <% end %>
@@ -0,0 +1,3 @@
1
+ class PasswordResetsController < ApplicationController
2
+ include TinyCore::Controllers::PasswordResets
3
+ end
@@ -0,0 +1,10 @@
1
+ Hallo,
2
+
3
+ Es wurde angefragt, Ihr <%= TinyCore::Application.name %> Passwort zu ändern. Falls Sie diese Anfrage nicht gestellt haben, ignorieren Sie bitte diese Mail. Falls Sie diese Anfrage gestellt haben, klicken Sie bitte auf folgenden Link:
4
+
5
+ http://<%= TinyCore::Config.host %><%= @edit_password_reset_path %>
6
+
7
+ Falls der Link nicht funktioniert, versuchen Sie bitte den Link in die Adressleiste Ihres Browsers zu kopieren.
8
+
9
+ Viele Grüße,
10
+ <%= TinyCore::Application.name %>
@@ -0,0 +1,10 @@
1
+ Hello,
2
+
3
+ A request to reset your <%= TinyCore::Application.name %> password has been made. If you did not make this request, simply ignore this email. If you did make this request just click the link below:
4
+
5
+ http://<%= TinyCore::Config.host %><%= @edit_password_reset_path %>
6
+
7
+ If the above URL does not work try copying and pasting it into your browser.
8
+
9
+ Sincerely,
10
+ <%= TinyCore::Application.name %>
@@ -0,0 +1,3 @@
1
+ module Role::Admin
2
+ include TinyCore::Role::Admin
3
+ end
@@ -0,0 +1,3 @@
1
+ module Role::Guest
2
+ include TinyCore::Role::Guest
3
+ end
@@ -0,0 +1,3 @@
1
+ module Role::User
2
+ include TinyCore::Role
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_user
3
+ end
@@ -0,0 +1,2 @@
1
+ class UserSession < Authlogic::Session::Base
2
+ end
@@ -0,0 +1,19 @@
1
+ <h2><%= t('.login') %></h2>
2
+
3
+ <% form_for @user_session, :url => login_path, :html => { :class => 'form' } do |f| %>
4
+ <%= f.error_messages :header_message => t('.could_not_login') %>
5
+ <p class="form_item">
6
+ <span class="label"><%= f.label :email, t('.email') %></span>
7
+ <%= f.text_field :email %>
8
+ </p>
9
+ <p class="form_item">
10
+ <span class="label"><%= f.label :password, t('.password') %></span>
11
+ <%= f.password_field :password %>
12
+ </p>
13
+
14
+ <p class="form_item">
15
+ <%= f.check_box :remember_me %><%= f.label :remember_me, t('.remember_me') %>
16
+ </p>
17
+
18
+ <p><%= f.submit t('.login') %> | <%= link_to t('.forgot_password'), new_password_reset_path %> | <%= link_to t('.register_instead'), new_user_path %></p>
19
+ <% end %>
@@ -0,0 +1,3 @@
1
+ class UserSessionsController < ApplicationController
2
+ include TinyCore::Controllers::UserSessions
3
+ end
@@ -0,0 +1,18 @@
1
+ <h2><%= t('.edit_users_profile', :full_name => @user.full_name) %></h2>
2
+
3
+ <% form_for @user, :html => { :class => 'form' } do |f| %>
4
+ <%= f.error_messages :header_message => t('.could_not_update_user') %>
5
+
6
+ <p class="form_item">
7
+ <span class="label"><%= f.label :full_name, t('.full_name'), :class => 'required' %></span>
8
+ <%= f.text_field :full_name %>
9
+ </p>
10
+
11
+ <p class="form_item">
12
+ <span class="label"><%= f.label :email, t('.email_address'), :class => 'required' %></span>
13
+ <span class="desc"><%= t('.the_email_address_is_used_for_notifications') %></span>
14
+ <%= f.text_field :email %>
15
+ </p>
16
+
17
+ <p><%= f.submit t('.update') %></p>
18
+ <% end %>
@@ -0,0 +1,34 @@
1
+ <h2><%= t('.create_new_account') %></h2>
2
+
3
+ <% form_for @user, :html => { :class => 'form' } do |f| %>
4
+ <%= f.error_messages :header_message => t('.could_not_register_user') %>
5
+
6
+ <p class="form_item">
7
+ <span class="label"><%= f.label :full_name, t('.full_name'), :class => 'required' %></span>
8
+ <%= f.text_field :full_name %>
9
+ </p>
10
+
11
+ <p class="form_item">
12
+ <span class="label"><%= f.label :email, t('.email_address'), :class => 'required' %></span>
13
+ <span class="desc"><%= t('.the_email_address_is_used_for_notifications') %></span>
14
+ <%= f.text_field :email %>
15
+ </p>
16
+
17
+ <p class="form_item">
18
+ <span class="label"><%= f.label :password, t('.password'), :class => 'required' %></span>
19
+ <%= f.password_field :password %>
20
+ </p>
21
+
22
+ <p class="form_item">
23
+ <span class="label"><%= f.label :password_confirmation, t('.password_confirmation'), :class => 'required' %></span>
24
+ <span class="desc"><%= t('.please_repeat_the_password_exactly_as_above') %></span>
25
+ <%= f.password_field :password_confirmation %>
26
+ </p>
27
+
28
+ <p>
29
+ <%= f.submit t('.create_account') %>
30
+ <% unless logged_in? %>
31
+ | <%= link_to t('.login_instead'), login_path %>
32
+ <% end %>
33
+ </p>
34
+ <% end %>
@@ -0,0 +1,36 @@
1
+ <h2><%= t('.users_profile', :full_name => @user.full_name) %></h2>
2
+
3
+ <dl>
4
+ <dt><%= t('.full_name') %></dt>
5
+ <dd><%= @user.full_name %></dd>
6
+ <% if current_user.can_see_email?(@user) %>
7
+ <dt><%= t('.email') %></dt>
8
+ <dd><%= @user.email %></dd>
9
+ <% end %>
10
+ <% if @user.respond_to?(:accounts) %>
11
+ <dt><%= t('.accounts') %></dt>
12
+ <dd>
13
+ <% if @user.accounts.empty? %>
14
+ <%= t('.no_accounts') %>
15
+ <% else %>
16
+ <ul>
17
+ <% @user.accounts.each do |account| %>
18
+ <li>
19
+ <% if current_user.can_see_account?(account) %>
20
+ <%= link_to account.name, account_path(account) %>
21
+ <% else %>
22
+ <%= account.name %>
23
+ <% end %>
24
+ </li>
25
+ <% end %>
26
+ </ul>
27
+ <% end %>
28
+ </dd>
29
+ <% end %>
30
+ </dl>
31
+
32
+ <% if current_user.can_edit_profile?(@user) %>
33
+ <ul class="action-list">
34
+ <li><%= link_to t('.edit_profile'), edit_user_path(@user) %></li>
35
+ </ul>
36
+ <% end %>
@@ -0,0 +1,3 @@
1
+ class UsersController < ApplicationController
2
+ include TinyCore::Controllers::Users
3
+ end
@@ -0,0 +1,83 @@
1
+ ---
2
+ de:
3
+ admin:
4
+ users:
5
+ index:
6
+ accounts: Konten
7
+ all_users: "Alle Benutzer"
8
+ email: E-Mail
9
+ name: Name
10
+ no_users: "Keine Benutzer gefunden."
11
+ options: Optionen
12
+ flash:
13
+ error:
14
+ access_denied: "Zugriff verweigert"
15
+ guest_required: "Sie müssen ausgeloggt sein, um auf diese Seite zuzugreifen"
16
+ login_required: "Sie müssen eingeloggt sein, um auf diese Seite zuzugreifen"
17
+ user_by_email_not_found: "Es wurde kein Benutzer mit dieser E-Mail-Adresse gefunden"
18
+ user_could_not_be_located: "Es tut uns leid, aber wir konnten den Benutzer nicht identifizieren. Bitte versuchen Sie die URL aus der E-Mail in die Adressleiste des Browsers zu kopieren oder starten Sie den Password-Vergessen-Prozess von vorne."
19
+ notice:
20
+ created_user: "Benutzer wurde erfolgreich erstellt"
21
+ logged_in: "Erfolgreich eingeloggt"
22
+ logged_out: "Erfolgreich ausgeloggt"
23
+ password_instructions_sent: "Anweisungen zur Änderung Ihres Passwortes wurden per E-Mail verschickt. Bitte prüfen Sie Ihren Posteingang."
24
+ password_updated: "Ihr Passwort wurde erfolgreich geändert"
25
+ updated_user: "Benutzer wurde erfolgreich aktualisiert"
26
+ password_reset_mailer:
27
+ subject: "Anweisungen zur Änderung Ihres Passwortes"
28
+ layouts:
29
+ accounts: Konten
30
+ admin: Admin
31
+ login: Login
32
+ logout: Logout
33
+ signup: Registrieren
34
+ user_greeter: "Willkommen, {{user}}"
35
+ password_resets:
36
+ edit:
37
+ change_password: "Passwort ändern"
38
+ could_not_reset_password: "Konnte Passwort nicht zurücksetzen"
39
+ password: Passwort
40
+ password_confirmation: "Passwort bestätigen"
41
+ update: "Passwort ändern"
42
+ index:
43
+ instructions: "Bitte prüfen Sie Ihren Posteingang für Anweisungen zur Änderung Ihres Passwortes."
44
+ new:
45
+ email: E-Mail-Adresse
46
+ forgot_password: "Passwort vergessen"
47
+ instructions: "Füllen Sie untenstehendes Formular aus, um Ihr Passwort zurückzusetzen."
48
+ reset: "Passwort zurücksetzen"
49
+ user_sessions:
50
+ new:
51
+ could_not_login: "Login war nicht erfolgreich"
52
+ email: E-Mail
53
+ forgot_password: "Passwort vergessen?"
54
+ login: Login
55
+ password: Passwort
56
+ register_instead: "Noch nicht registriert?"
57
+ remember_me: "Eingeloggt bleiben"
58
+ users:
59
+ edit:
60
+ could_not_update_user: "Konnte Benutzerprofil nicht aktualisieren"
61
+ edit_users_profile: "Benutzerprofil bearbeiten"
62
+ email_address: E-Mail-Adresse
63
+ full_name: "Voller Name"
64
+ the_email_address_is_used_for_notifications: "Die E-Mail-Adresse wird für Benachrichtigungen verwendet"
65
+ update: Aktualisieren
66
+ new:
67
+ could_not_register_user: "Konnte Benutzer nicht registrieren"
68
+ create_account: "Benutzer registrieren"
69
+ create_new_account: "Neuen Benutzer registrieren"
70
+ email_address: E-Mail-Adresse
71
+ full_name: "Voller Name"
72
+ login_instead: "Bereits registriert?"
73
+ password: Passwort
74
+ password_confirmation: "Passwort wiederholen"
75
+ please_repeat_the_password_exactly_as_above: "Bitte wiederholen Sie das Passwort exakt wie oben"
76
+ the_email_address_is_used_for_notifications: "Die E-Mail-Adresse wird für Benachrichtigungen verwendet"
77
+ show:
78
+ accounts: Konten
79
+ edit_profile: "Profil bearbeiten"
80
+ email: E-Mail-Adresse
81
+ full_name: "Voller Name"
82
+ no_accounts: "bisher keine"
83
+ users_profile: "{{full_name}}s Profil"
@@ -0,0 +1,83 @@
1
+ ---
2
+ en:
3
+ admin:
4
+ users:
5
+ index:
6
+ accounts: Accounts
7
+ all_users: "All Users"
8
+ email: Email
9
+ name: Name
10
+ no_users: "No users found."
11
+ options: Options
12
+ flash:
13
+ error:
14
+ access_denied: "Access denied"
15
+ guest_required: "You must be logged out to access this page"
16
+ login_required: "You must be logged in to access this page"
17
+ user_by_email_not_found: "No user was found with that email address"
18
+ user_could_not_be_located: "We're sorry, but we could not locate your account. If you are having issues try copying and pasting the URL from your email into your browser or restarting the reset password process."
19
+ notice:
20
+ created_user: "Successfully created user"
21
+ logged_in: "Successfully logged in"
22
+ logged_out: "Successfully logged out"
23
+ password_instructions_sent: "Instructions to reset your password have been emailed to you. Please check your email."
24
+ password_updated: "Password successfully updated"
25
+ updated_user: "Successfully updated user"
26
+ password_reset_mailer:
27
+ subject: "Password Reset Instructions"
28
+ layouts:
29
+ accounts: Accounts
30
+ admin: Admin
31
+ login: Login
32
+ logout: Logout
33
+ signup: Signup
34
+ user_greeter: "Welcome, {{user}}"
35
+ password_resets:
36
+ edit:
37
+ change_password: "Change My Password"
38
+ could_not_reset_password: "Could not reset password"
39
+ password: Password
40
+ password_confirmation: "Confirm password"
41
+ update: "Update my password and log me in"
42
+ index:
43
+ instructions: "Please check your email for instructions how to change your password."
44
+ new:
45
+ email: "E-mail address"
46
+ forgot_password: "Forgot Password"
47
+ instructions: "Fill out the form below and instructions to reset your password will be emailed to you."
48
+ reset: "Reset my password"
49
+ user_sessions:
50
+ new:
51
+ could_not_login: "Login failed"
52
+ email: E-Mail
53
+ forgot_password: "Forgot password?"
54
+ login: Login
55
+ password: Password
56
+ register_instead: "Not registered yet?"
57
+ remember_me: "Remember me"
58
+ users:
59
+ edit:
60
+ could_not_update_user: "Could not update user"
61
+ edit_users_profile: "Edit user's profile"
62
+ email_address: "E-mail address"
63
+ full_name: "Full name"
64
+ the_email_address_is_used_for_notifications: "The e-mail address is used for notifications"
65
+ update: Update
66
+ new:
67
+ could_not_register_user: "Could not register user"
68
+ create_account: "Create account"
69
+ create_new_account: "Create new account"
70
+ email_address: "E-mail address"
71
+ full_name: "Full name"
72
+ login_instead: "Already registered?"
73
+ password: Password
74
+ password_confirmation: "Password confirmation"
75
+ please_repeat_the_password_exactly_as_above: "Please repeat the password exactly as above"
76
+ the_email_address_is_used_for_notifications: "The e-mail address is used for notifications"
77
+ show:
78
+ accounts: Accounts
79
+ edit_profile: "Edit profile"
80
+ email: "Email address"
81
+ full_name: "Full name"
82
+ no_accounts: "none yet"
83
+ users_profile: "{{full_name}}'s profile"
@@ -0,0 +1,46 @@
1
+ class TinyUserGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions "User", "UserSession", "UsersController", "UserSessionsController", "PasswordResetsController", "Admin::UsersController", "Role::Admin", "Role::User"
6
+
7
+ # Model, controller, view and test directories.
8
+ m.directory 'app/models'
9
+ m.directory 'app/models/role'
10
+ m.directory 'app/controllers'
11
+ m.directory 'app/controllers/admin'
12
+ m.directory 'app/views/admin/users'
13
+ m.directory 'app/views/password_resets'
14
+ m.directory 'app/views/password_resets_mailer'
15
+ m.directory 'app/views/user_sessions'
16
+ m.directory 'app/views/users'
17
+ m.directory 'config/locales'
18
+ m.directory 'test/unit'
19
+ m.directory 'test/functional'
20
+
21
+ # Classes and tests.
22
+ m.file "admin_users_controller.rb", 'app/controllers/admin/users_controller.rb'
23
+ m.file "password_resets_controller.rb", 'app/controllers/password_resets_controller.rb'
24
+ m.file "role/admin.rb", 'app/models/role/admin.rb'
25
+ m.file "role/user.rb", 'app/models/role/user.rb'
26
+ m.file "user.rb", 'app/models/user.rb'
27
+ m.file "user_session.rb", 'app/models/user_session.rb'
28
+ m.file "user_sessions_controller.rb", 'app/controllers/user_sessions_controller.rb'
29
+ m.file "users_controller.rb", 'app/controllers/users_controller.rb'
30
+
31
+ # Locales
32
+ m.file "users_en.yml", 'config/locales/users_en.yml'
33
+ m.file "users_de.yml", 'config/locales/users_de.yml'
34
+
35
+ # Views
36
+ base_dir = File.dirname(__FILE__) + '/templates'
37
+ Dir.glob("#{base_dir}/**/*.html.erb") do |template|
38
+ relative_path = template.gsub("#{base_dir}/", '')
39
+ m.file relative_path, "app/views/#{relative_path}"
40
+ end
41
+
42
+ # Migrations
43
+ m.migration_template 'create_users.rb', 'db/migrate', :migration_file_name => 'create_users.rb'
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_core_users
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
+ - Thomas Kadauke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-30 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: tkadauke@imedo.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/tiny_core/acts/user.rb
32
+ - lib/tiny_core/controllers/admin_users.rb
33
+ - lib/tiny_core/controllers/application.rb
34
+ - lib/tiny_core/controllers/password_resets.rb
35
+ - lib/tiny_core/controllers/user_sessions.rb
36
+ - lib/tiny_core/controllers/users.rb
37
+ - lib/tiny_core/mailers/password_resets_mailer.rb
38
+ - lib/tiny_core/models/guest.rb
39
+ - lib/tiny_core/role/admin.rb
40
+ - lib/tiny_core/role/guest.rb
41
+ - lib/tiny_core/role.rb
42
+ - lib/tiny_core_users.rb
43
+ - rails_generators/tiny_user/templates/admin/users/_index.html.erb
44
+ - rails_generators/tiny_user/templates/admin/users/index.html.erb
45
+ - rails_generators/tiny_user/templates/admin_users_controller.rb
46
+ - rails_generators/tiny_user/templates/create_users.rb
47
+ - rails_generators/tiny_user/templates/password_resets/edit.html.erb
48
+ - rails_generators/tiny_user/templates/password_resets/index.html.erb
49
+ - rails_generators/tiny_user/templates/password_resets/new.html.erb
50
+ - rails_generators/tiny_user/templates/password_resets_controller.rb
51
+ - rails_generators/tiny_user/templates/password_resets_mailer/password_reset_instructions.de.erb
52
+ - rails_generators/tiny_user/templates/password_resets_mailer/password_reset_instructions.erb
53
+ - rails_generators/tiny_user/templates/role/admin.rb
54
+ - rails_generators/tiny_user/templates/role/guest.rb
55
+ - rails_generators/tiny_user/templates/role/user.rb
56
+ - rails_generators/tiny_user/templates/user.rb
57
+ - rails_generators/tiny_user/templates/user_session.rb
58
+ - rails_generators/tiny_user/templates/user_sessions/new.html.erb
59
+ - rails_generators/tiny_user/templates/user_sessions_controller.rb
60
+ - rails_generators/tiny_user/templates/users/edit.html.erb
61
+ - rails_generators/tiny_user/templates/users/new.html.erb
62
+ - rails_generators/tiny_user/templates/users/show.html.erb
63
+ - rails_generators/tiny_user/templates/users_controller.rb
64
+ - rails_generators/tiny_user/templates/users_de.yml
65
+ - rails_generators/tiny_user/templates/users_en.yml
66
+ - rails_generators/tiny_user/tiny_user_generator.rb
67
+ has_rdoc: true
68
+ homepage:
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Simple reusable user management with generator based on authlogic
101
+ test_files: []
102
+