put back database_authenticatable to users, fix empty avatar form bug

This commit is contained in:
benji 2015-03-25 17:49:37 +01:00
parent 63e9b81754
commit e4e717084b
15 changed files with 68 additions and 24 deletions

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -1,9 +0,0 @@
class SessionsController < Devise::SessionsController
def new
if session[:id]
redirect_to new_user_avatar_path
return
end
super
end
end

View file

@ -27,7 +27,8 @@ class UsersController < ApplicationController
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
redirect_to @user, success: "Successfully updated!"
flash[:success] = "Successfully updated!"
redirect_to @user
else
render 'edit'
end
@ -78,6 +79,10 @@ class UsersController < ApplicationController
end
def user_params
params.require(:user).permit(:avatar)
if params[:user]
params.require(:user).permit(:avatar)
else
{}
end
end
end

View file

@ -0,0 +1,4 @@
class WelcomeController < ApplicationController
def index
end
end

View file

@ -0,0 +1,2 @@
module WelcomeHelper
end

View file

@ -27,7 +27,7 @@
require 'identicon'
class User < ActiveRecord::Base
devise :trackable, :omniauthable, :omniauth_providers => [:zeuswpi]
devise :database_authenticatable, :trackable, :omniauthable, :omniauth_providers => [:zeuswpi]
has_paper_trail
has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium

View file

@ -1,8 +1,17 @@
<h2>Login</h2>
<%= render 'flash' %>
If this is the first time you log in, an account will be created for you.
<h2>Sign in</h2>
<%= render partial: 'flash' %>
<div>
<br />
<%= render 'devise/shared/links' %>
<div class="sign-in">
<%= f_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.text_field :uid %>
<%= f.password_field :password %>
<% if devise_mapping.rememberable? %>
<%= f.check_box :remember_me %>
<% end %>
<%= f.submit "Sign in" %>
<% end %>
</div>
<%= render "devise/shared/links" %>

View file

@ -0,0 +1,8 @@
<h2>Login</h2>
<%= render 'flash' %>
If this is the first time you log in, an account will be created for you.
<div>
<br />
<%= link_to "Sign in with Zeus WPI account.", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-large btn-primary" %><br />
</div>

View file

@ -30,7 +30,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
config.authentication_keys = [ :nickname ]
config.authentication_keys = [ :uid ]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the

View file

@ -1,12 +1,11 @@
Rails.application.routes.draw do
devise_for :users, controllers: {
omniauth_callbacks: "callbacks",
sessions: "sessions"
omniauth_callbacks: "callbacks"
}
devise_scope :user do
unauthenticated :user do
root to: 'sessions#new'
root to: 'welcome#index'
end
authenticated :user, ->(u) { u.koelkast? } do
@ -16,7 +15,6 @@ Rails.application.routes.draw do
authenticated :user, ->(u) { !u.koelkast? } do
root to: 'users#show', as: :user_root
end
get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end
resources :users do

View file

@ -0,0 +1,5 @@
class AddEncryptedPasswordToUsers < ActiveRecord::Migration
def change
add_column :users, :encrypted_password, :string, null: false, default: ""
end
end

View file

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

View file

@ -37,6 +37,14 @@ products.each do |attr|
Product.create name: attr[:name], price: attr[:price], category: attr[:category], stock: attr[:stock], avatar: attr[:avatar]
end
User.create(
uid: "koelkast",
password: "password",
password_confirmation: "password",
avatar: Identicon.data_url_for("koelkast"),
koelkast: true
)
20.times do |i|
name = Faker::Name.name
User.create(

View file

@ -0,0 +1,7 @@
require 'test_helper'
class WelcomeControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end