remove database_authenticatable from user and fix paths

This commit is contained in:
benji 2015-03-21 17:58:49 +01:00
parent d687213834
commit 33ffcfdb9b
8 changed files with 20 additions and 19 deletions

View file

@ -23,7 +23,7 @@ class UserAvatarController < ApplicationController
def authenticate_session_user! def authenticate_session_user!
redirect_to root_path unless session[:id] redirect_to root_path unless session[:id]
@user = User.find_by session[:id] @user = User.find session[:id]
unless @user unless @user
reset_session reset_session
redirect_to root_path redirect_to root_path

View file

@ -26,7 +26,7 @@
# #
class User < ActiveRecord::Base class User < ActiveRecord::Base
devise :database_authenticatable, :trackable, :omniauthable, :omniauth_providers => [:zeuswpi] devise :trackable, :omniauthable, :omniauth_providers => [:zeuswpi]
has_paper_trail only: [:debt_cents, :admin, :orders_count, :koelkast] has_paper_trail only: [:debt_cents, :admin, :orders_count, :koelkast]
@ -43,12 +43,10 @@ class User < ActiveRecord::Base
scope :members, -> { where koelkast: false } scope :members, -> { where koelkast: false }
def self.from_omniauth(auth) def self.from_omniauth(auth)
newuser = where(provider: auth.provider, uid: auth.uid).first_or_create do |user| where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider user.provider = auth.provider
user.uid = auth.uid user.uid = auth.uid
end end
newuser.password = Devise.friendly_token[0,20]
newuser
end end
def nickname def nickname

View file

@ -16,11 +16,11 @@
<div class="hidden-xs navbar-form navbar-right"> <div class="hidden-xs navbar-form navbar-right">
<div class="form-group"> <div class="form-group">
<% if user_signed_in? %> <% if user_signed_in? %>
<%= button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete %> <%= link_to "Logout", destroy_user_session_path, class: "btn btn-default form-control" %>
<% elsif session[:id] %> <% elsif session[:id] %>
<%= button_to "Logout", user_avatar_path(session[:id]), class: "btn btn-default form-control", method: :delete %> <%= button_to "Logout", user_avatar_path(session[:id]), class: "btn btn-default form-control", method: :delete %>
<% else %> <% else %>
<%= link_to "Login", new_user_session_path, class: "btn btn-success form-control" %> <%= link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control" %>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -62,7 +62,7 @@
<% if user_signed_in? %> <% if user_signed_in? %>
<%= button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete %> <%= button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete %>
<% else %> <% else %>
<%= link_to "Login", new_user_session_path, class: "btn btn-success form-control" %> <%= link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control" %>
<% end %> <% end %>
</div> </div>
</div> </div>

View file

@ -228,7 +228,7 @@ Devise.setup do |config|
# config.navigational_formats = ['*/*', :html] # config.navigational_formats = ['*/*', :html]
# The default HTTP method used to sign out a resource. Default is :delete. # The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete config.sign_out_via = :get
# ==> OmniAuth # ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting # Add a new OmniAuth provider. Check the wiki for more information on setting

View file

@ -16,6 +16,7 @@ Rails.application.routes.draw do
authenticated :user, ->(u) { !u.koelkast? } do authenticated :user, ->(u) { !u.koelkast? } do
root to: 'users#show', as: :user_root root to: 'users#show', as: :user_root
end end
get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end end
resources :users do resources :users do

View file

@ -0,0 +1,5 @@
class RemoveEncryptedPasswordFromUsers < ActiveRecord::Migration
def change
remove_column :users, :encrypted_password, :string
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150320001338) do ActiveRecord::Schema.define(version: 20150321161136) do
create_table "order_items", force: :cascade do |t| create_table "order_items", force: :cascade do |t|
t.integer "order_id" t.integer "order_id"
@ -63,7 +63,6 @@ ActiveRecord::Schema.define(version: 20150320001338) do
t.boolean "koelkast", default: false t.boolean "koelkast", default: false
t.string "provider" t.string "provider"
t.string "uid" t.string "uid"
t.string "encrypted_password"
end end
add_index "users", ["koelkast"], name: "index_users_on_koelkast" add_index "users", ["koelkast"], name: "index_users_on_koelkast"

View file

@ -67,16 +67,14 @@ users.each do |attr|
provider: attr[:provider], provider: attr[:provider],
avatar: attr[:avatar], avatar: attr[:avatar],
dagschotel: attr[:dagschotel], dagschotel: attr[:dagschotel],
password: DEFAULT_PASSWORD,
admin: attr[:admin] || false, admin: attr[:admin] || false,
koelkast: attr[:koelkast] || false koelkast: attr[:koelkast] || false
) )
end end
50.times do |i| # 50.times do |i|
User.create( # User.create(
uid: "testUser#{i}", # uid: "testUser#{i}",
avatar: users[0][:avatar], # avatar: users[0][:avatar],
password: DEFAULT_PASSWORD, # )
) # end
end