put back database_authenticatable to users, fix empty avatar form bug
This commit is contained in:
parent
63e9b81754
commit
e4e717084b
3
app/assets/javascripts/welcome.js.coffee
Normal file
3
app/assets/javascripts/welcome.js.coffee
Normal 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/
|
3
app/assets/stylesheets/welcome.css.scss
Normal file
3
app/assets/stylesheets/welcome.css.scss
Normal 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/
|
|
@ -1,9 +0,0 @@
|
||||||
class SessionsController < Devise::SessionsController
|
|
||||||
def new
|
|
||||||
if session[:id]
|
|
||||||
redirect_to new_user_avatar_path
|
|
||||||
return
|
|
||||||
end
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -27,7 +27,8 @@ class UsersController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
if @user.update_attributes(user_params)
|
if @user.update_attributes(user_params)
|
||||||
redirect_to @user, success: "Successfully updated!"
|
flash[:success] = "Successfully updated!"
|
||||||
|
redirect_to @user
|
||||||
else
|
else
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
|
@ -78,6 +79,10 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:avatar)
|
if params[:user]
|
||||||
|
params.require(:user).permit(:avatar)
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
4
app/controllers/welcome_controller.rb
Normal file
4
app/controllers/welcome_controller.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class WelcomeController < ApplicationController
|
||||||
|
def index
|
||||||
|
end
|
||||||
|
end
|
2
app/helpers/welcome_helper.rb
Normal file
2
app/helpers/welcome_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module WelcomeHelper
|
||||||
|
end
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
require 'identicon'
|
require 'identicon'
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
devise :trackable, :omniauthable, :omniauth_providers => [:zeuswpi]
|
devise :database_authenticatable, :trackable, :omniauthable, :omniauth_providers => [:zeuswpi]
|
||||||
|
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium
|
has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
<h2>Login</h2>
|
<h2>Sign in</h2>
|
||||||
<%= render 'flash' %>
|
<%= render partial: 'flash' %>
|
||||||
If this is the first time you log in, an account will be created for you.
|
|
||||||
|
|
||||||
<div>
|
<div class="sign-in">
|
||||||
<br />
|
<%= f_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||||
<%= render 'devise/shared/links' %>
|
<%= f.text_field :uid %>
|
||||||
|
<%= f.password_field :password %>
|
||||||
|
|
||||||
|
<% if devise_mapping.rememberable? %>
|
||||||
|
<%= f.check_box :remember_me %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= f.submit "Sign in" %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= render "devise/shared/links" %>
|
||||||
|
|
8
app/views/welcome/index.html.erb
Normal file
8
app/views/welcome/index.html.erb
Normal 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>
|
|
@ -30,7 +30,7 @@ Devise.setup do |config|
|
||||||
# session. If you need permissions, you should implement that in a before filter.
|
# 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
|
# 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.
|
# 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
|
# 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
|
# given should be a request method and it will automatically be passed to the
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
devise_for :users, controllers: {
|
devise_for :users, controllers: {
|
||||||
omniauth_callbacks: "callbacks",
|
omniauth_callbacks: "callbacks"
|
||||||
sessions: "sessions"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
unauthenticated :user do
|
unauthenticated :user do
|
||||||
root to: 'sessions#new'
|
root to: 'welcome#index'
|
||||||
end
|
end
|
||||||
|
|
||||||
authenticated :user, ->(u) { u.koelkast? } do
|
authenticated :user, ->(u) { u.koelkast? } do
|
||||||
|
@ -16,7 +15,6 @@ 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
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddEncryptedPasswordToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :encrypted_password, :string, null: false, default: ""
|
||||||
|
end
|
||||||
|
end
|
|
@ -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: 20150321161136) do
|
ActiveRecord::Schema.define(version: 20150325154600) 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,6 +63,7 @@ ActiveRecord::Schema.define(version: 20150321161136) 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", default: "", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["koelkast"], name: "index_users_on_koelkast"
|
add_index "users", ["koelkast"], name: "index_users_on_koelkast"
|
||||||
|
|
|
@ -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]
|
Product.create name: attr[:name], price: attr[:price], category: attr[:category], stock: attr[:stock], avatar: attr[:avatar]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
User.create(
|
||||||
|
uid: "koelkast",
|
||||||
|
password: "password",
|
||||||
|
password_confirmation: "password",
|
||||||
|
avatar: Identicon.data_url_for("koelkast"),
|
||||||
|
koelkast: true
|
||||||
|
)
|
||||||
|
|
||||||
20.times do |i|
|
20.times do |i|
|
||||||
name = Faker::Name.name
|
name = Faker::Name.name
|
||||||
User.create(
|
User.create(
|
||||||
|
|
7
test/controllers/welcome_controller_test.rb
Normal file
7
test/controllers/welcome_controller_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class WelcomeControllerTest < ActionController::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in a new issue