diff --git a/app/assets/javascripts/welcome.js.coffee b/app/assets/javascripts/welcome.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/welcome.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/welcome.css.scss b/app/assets/stylesheets/welcome.css.scss new file mode 100644 index 0000000..77ce11a --- /dev/null +++ b/app/assets/stylesheets/welcome.css.scss @@ -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/ diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb deleted file mode 100644 index c5399c7..0000000 --- a/app/controllers/sessions_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SessionsController < Devise::SessionsController - def new - if session[:id] - redirect_to new_user_avatar_path - return - end - super - end -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6695eed..a88c3c9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000..f9b859b --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,4 @@ +class WelcomeController < ApplicationController + def index + end +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000..eeead45 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/app/models/user.rb b/app/models/user.rb index b6622e6..4eb0cd5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index f36a0ac..13da1a0 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,8 +1,17 @@ -

Login

-<%= render 'flash' %> -If this is the first time you log in, an account will be created for you. +

Sign in

+<%= render partial: 'flash' %> -
-
- <%= render 'devise/shared/links' %> +
+ <%= 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 %>
+ +<%= render "devise/shared/links" %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 0000000..6babaa1 --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,8 @@ +

Login

+<%= render 'flash' %> +If this is the first time you log in, an account will be created for you. + +
+
+ <%= link_to "Sign in with Zeus WPI account.", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-large btn-primary" %>
+
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 3a4f493..367a4b4 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 7c3e7b9..9fb2ba4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20150325154600_add_encrypted_password_to_users.rb b/db/migrate/20150325154600_add_encrypted_password_to_users.rb new file mode 100644 index 0000000..9772967 --- /dev/null +++ b/db/migrate/20150325154600_add_encrypted_password_to_users.rb @@ -0,0 +1,5 @@ +class AddEncryptedPasswordToUsers < ActiveRecord::Migration + def change + add_column :users, :encrypted_password, :string, null: false, default: "" + end +end diff --git a/db/schema.rb b/db/schema.rb index a7231b6..6fe7769 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/db/seeds.rb b/db/seeds.rb index 02a9019..0d37028 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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( diff --git a/test/controllers/welcome_controller_test.rb b/test/controllers/welcome_controller_test.rb new file mode 100644 index 0000000..fb50856 --- /dev/null +++ b/test/controllers/welcome_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class WelcomeControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end