Commit dc51f973 authored by Hermann Mayer's avatar Hermann Mayer

[User Management] Merged user with player model to combine functionality. Added…

[User Management] Merged user with player model to combine functionality. Added admin flag to player.
parent 9e2094cb
class RegistrationsController < Devise::RegistrationsController
def edit
@teams = Team.all
super
end
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
resource.team = Team.find_by_id(params[:team][:team_id])
@teams = Team.all
if resource.update_with_password(resource_params)
if is_navigational_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords resource
respond_with resource
end
end
end
class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
respond_to do |format|
format.html # index.html.erb
format.json { render json: @teams }
end
end
end
module RegistrationsHelper
end
class Player < ActiveRecord::Base
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
belongs_to :team
attr_accessible :name
# attr_accessible :name
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end
<% if user_signed_in? %>
<% if player_signed_in? %>
<li>
<%= link_to destroy_user_session_path, :method => :delete do %>
<%= link_to destroy_player_session_path, :method => :delete do %>
<i class="icon-off icon-white"></i> Ausloggen
<% end %>
</li>
<% else %>
<li>
<%= link_to new_user_session_path do %>
<%= link_to new_player_session_path do %>
<i class="icon-share-alt icon-white"></i> Einloggen
<% end %>
</li>
......
<% if user_signed_in? %>
<% if player_signed_in? %>
<li>
<%= link_to edit_user_registration_path do %>
<%= link_to edit_player_registration_path do %>
<i class="icon-edit icon-white"></i> Profil bearbeiten
<% end %>
</li>
<% else %>
<li>
<%= link_to new_user_registration_path do %>
<%= link_to new_player_registration_path do %>
<i class="icon-asterisk icon-white"></i> Registrieren
<% end %>
</li>
......
......@@ -50,6 +50,13 @@
</div>
</div>
<div class="control-group">
<%= f.label :team_id, :class => "control-label" %>
<div class="controls">
<%= collection_select(:team, :team_id, @teams, :id, :name, {:prompt => false}) %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit 'Aktualisieren', :class => "btn btn-primary" %>
......
......@@ -4,10 +4,17 @@
<%= devise_error_messages! %>
<div class="control-group">
<%= f.label :name, :class => "control-label" %>
<div class="controls">
<%= f.text_field :name, :autofocus => true %>
</div>
</div>
<div class="control-group">
<%= f.label :email, :class => "control-label" %>
<div class="controls">
<%= f.email_field :email, :autofocus => true %>
<%= f.email_field :email %>
</div>
</div>
......
......@@ -49,7 +49,7 @@
<li class="dropdown <%= 'active' if params[:controller] == 'users' or params[:controller] =~ /devise/ %>">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="icon icon-hand-right"></i> Mitmachen
<i class="icon icon-hand-right"></i> <%= (player_signed_in?) ? current_player.name : 'Mitmachen' %>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
......
......@@ -3,7 +3,7 @@
<div>
<h2 class="">
Matches Auflistung
<% if user_signed_in? %>
<% if player_signed_in? %>
<%= link_to new_match_path, :class => "btn btn-primary pull-right" do %>
<i class="icon-pencil icon-white"></i> Neues Match anlegen
<% end %>
......@@ -30,7 +30,7 @@
<%= link_to match, :class => "btn" do %>
<i class="icon-search icon-white"></i> Anzeigen
<% end %>
<% if user_signed_in? %>
<% if player_signed_in? %>
<%= link_to edit_match_path(match), :class => "btn btn-primary" do %>
<i class="icon-edit icon-white"></i> Bearbeiten
<% end %>
......
......@@ -20,7 +20,7 @@
<%= link_to(@match.winner.name, @match.winner) %>
</p>
<% if user_signed_in? %>
<% if player_signed_in? %>
<%= link_to edit_match_path(@match), :class => "btn" do %>
<i class="icon-edit icon-white"></i> Bearbeiten
<% end %>
......
<div>
<h2 class="">
Spieler Auflistung
<% if user_signed_in? %>
<% if player_signed_in? and current_player.try(:admin?) %>
<%= link_to new_player_path, :class => "btn btn-primary pull-right" do %>
<i class="icon-pencil icon-white"></i> Neuen Spieler anlegen
<% end %>
......@@ -24,7 +24,7 @@
<%= link_to player, :class => "btn" do %>
<i class="icon-search icon-white"></i> Anzeigen
<% end %>
<% if user_signed_in? %>
<% if player_signed_in? and current_player.try(:admin?) %>
<%= link_to edit_player_path(player), :class => "btn btn-primary" do %>
<i class="icon-edit icon-white"></i> Bearbeiten
<% end %>
......
......@@ -10,7 +10,7 @@
<%= @player.team.blank? ? 'Keinem Team zugeordnet' : link_to(@player.team.name, @player.team) %>
</p>
<% if user_signed_in? %>
<% if player_signed_in? %>
<%= link_to edit_player_path(@player), :class => "btn" do %>
<i class="icon-edit icon-white"></i> Bearbeiten
<% end %>
......
<div>
<h2 class="">
Teams Auflistung
<% if user_signed_in? %>
<% if player_signed_in? %>
<%= link_to new_team_path, :class => "btn btn-primary pull-right" do %>
<i class="icon-pencil icon-white"></i> Neues Team anlegen
<% end %>
......@@ -22,7 +22,7 @@
<%= link_to team, :class => "btn" do %>
<i class="icon-search icon-white"></i> Anzeigen
<% end %>
<% if user_signed_in? %>
<% if player_signed_in? and current_player.try(:admin?) %>
<%= link_to edit_team_path(team), :class => "btn btn-primary" do %>
<i class="icon-edit icon-white"></i> Bearbeiten
<% end %>
......
......@@ -18,7 +18,7 @@
<caption>Angehörige Spieler</caption>
</table>
<% if user_signed_in? %>
<% if player_signed_in? %>
<%= link_to edit_team_path(@team), :class => "btn" do %>
<i class="icon-edit icon-white"></i> Bearbeiten
<% end %>
......
KickerTracker::Application.routes.draw do
resources :matches
resources :players
resources :teams
devise_for :users
resources :users
devise_for :players, :controllers => {:registrations => "registrations"}
resources :players
# devise_for :users
# resources :users
# The priority is based upon order of creation:
......
class CreatePlayers < ActiveRecord::Migration
def change
create_table :players do |t|
t.string :name
create_table(:players) do |t|
t.string :name, :null => false
t.integer :team_id
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
t.boolean :admin, :default => false
t.timestamps
end
add_index :players, :email, :unique => true
add_index :players, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
end
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130305194407) do
ActiveRecord::Schema.define(:version => 20130302145601) do
create_table "matches", :force => true do |t|
t.date "date"
......@@ -23,21 +23,10 @@ ActiveRecord::Schema.define(:version => 20130305194407) do
end
create_table "players", :force => true do |t|
t.string "name"
t.string "name", :null => false
t.integer "team_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "teams", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
......@@ -46,11 +35,18 @@ ActiveRecord::Schema.define(:version => 20130305194407) do
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "admin", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "players", ["email"], :name => "index_players_on_email", :unique => true
add_index "players", ["reset_password_token"], :name => "index_players_on_reset_password_token", :unique => true
create_table "teams", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
require 'test_helper'
class RegistrationsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class RegistrationsHelperTest < ActionView::TestCase
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment