diff --git a/Gemfile b/Gemfile index b8cc48b..4a4ed75 100644 --- a/Gemfile +++ b/Gemfile @@ -78,3 +78,5 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] gem 'coveralls', require: false gem 'omniauth-oauth2' + +gem 'identicon' diff --git a/Gemfile.lock b/Gemfile.lock index d6f2c89..9477b4f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,6 +79,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + chunky_png (1.3.4) climate_control (0.0.3) activesupport (>= 3.0) cocaine (0.5.5) @@ -121,6 +122,8 @@ GEM hashie (3.4.0) hike (1.2.3) i18n (0.7.0) + identicon (0.0.3) + chunky_png jbuilder (2.2.6) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) @@ -286,6 +289,7 @@ DEPENDENCIES coveralls devise faker (= 1.4.2) + identicon jbuilder (~> 2.0) jquery-rails launchy diff --git a/app/assets/javascripts/user_avatar.js.coffee b/app/assets/javascripts/user_avatar.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/user_avatar.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# 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/user_avatar.css.scss b/app/assets/stylesheets/user_avatar.css.scss deleted file mode 100644 index d7e24de..0000000 --- a/app/assets/stylesheets/user_avatar.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the user_avatar 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/callbacks_controller.rb b/app/controllers/callbacks_controller.rb index e0beaa2..dcd8663 100644 --- a/app/controllers/callbacks_controller.rb +++ b/app/controllers/callbacks_controller.rb @@ -1,15 +1,7 @@ class CallbacksController < Devise::OmniauthCallbacksController def zeuswpi @user = User.from_omniauth(request.env["omniauth.auth"]) - @user.save!(validate: false) - if @user.valid? - flash[:success] = "You are now logged in." - sign_in_and_redirect @user - else - flash[:error] = "Please complete your profile first." - session[:id] = @user.id - redirect_to new_user_avatar_path - end + sign_in_and_redirect @user end def after_omniauth_failure_path_for(scope) diff --git a/app/controllers/user_avatar_controller.rb b/app/controllers/user_avatar_controller.rb deleted file mode 100644 index d1dda6a..0000000 --- a/app/controllers/user_avatar_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -class UserAvatarController < ApplicationController - before_action :authenticate_session_user! - - def new - end - - def create - if @user.update_attributes(user_params) - flash[:success] = "Your profile is complete. You are now logged in." - reset_session - sign_in_and_redirect @user - else - render 'new' - end - end - - def destroy - reset_session - redirect_to root_path - end - - private - - def authenticate_session_user! - redirect_to root_path unless session[:id] - @user = User.find session[:id] - unless @user - reset_session - redirect_to root_path - end - end - - def user_params - params.require(:user).permit(:avatar) - end -end diff --git a/app/helpers/user_avatar_helper.rb b/app/helpers/user_avatar_helper.rb deleted file mode 100644 index 52a0ddd..0000000 --- a/app/helpers/user_avatar_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module UserAvatarHelper -end diff --git a/app/models/user.rb b/app/models/user.rb index 1135dd2..b6622e6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,11 +25,11 @@ # encrypted_password :string # +require 'identicon' class User < ActiveRecord::Base devise :trackable, :omniauthable, :omniauth_providers => [:zeuswpi] - has_paper_trail only: [:debt_cents, :admin, :orders_count, :koelkast] - + has_paper_trail has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium has_many :orders, -> { includes :products } @@ -46,6 +46,7 @@ class User < ActiveRecord::Base where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.provider = auth.provider user.uid = auth.uid + user.avatar = Identicon.data_url_for auth.uid end end @@ -53,10 +54,6 @@ class User < ActiveRecord::Base self.uid end - def nickname=(name) - self.uid = name - end - def debt self.debt_cents / 100.0 end diff --git a/app/views/user_avatar/new.html.erb b/app/views/user_avatar/new.html.erb deleted file mode 100644 index b331197..0000000 --- a/app/views/user_avatar/new.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -