Replace multistep registration by default avatar from identicon

This commit is contained in:
benji 2015-03-23 11:54:15 +01:00
parent 33ffcfdb9b
commit efd4dcbb2c
12 changed files with 16 additions and 125 deletions

View file

@ -78,3 +78,5 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
gem 'coveralls', require: false
gem 'omniauth-oauth2'
gem 'identicon'

View file

@ -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

View file

@ -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/

View file

@ -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/

View file

@ -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)

View file

@ -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

View file

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

View file

@ -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

View file

@ -1,13 +0,0 @@
<h2>Add avatar to <%= @user.uid %></h2>
<%= render 'flash' %>
<%= f_form_for @user, url: url_for(controller: 'user_avatar', action: 'create'), method: :post do |f| %>
<%= f.error_messages %>
<!-- To prevent an empty form submit from crashing -->
<%= f.hidden_field :generate_form, value: '1' %>
<%= f.file_field :avatar %>
<%= f.submit "Update" %>
<% end %>

View file

@ -24,12 +24,6 @@ module OmniAuth
# providers.
uid{ raw_info['username'] }
info do
{
# :nickname => raw_info['username'],
}
end
extra do
{
'raw_info' => raw_info

View file

@ -5,6 +5,8 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
require 'faker'
require 'identicon'
DEFAULT_PASSWORD = "password"
products = [
@ -35,46 +37,10 @@ products.each do |attr|
Product.create name: attr[:name], price: attr[:price], category: attr[:category], stock: attr[:stock], avatar: attr[:avatar]
end
users = [
{
uid: 'admin',
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
admin: true
},
{
uid: 'koelkast',
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
koelkast: true
},
{
uid: 'benji',
# avatar: File.new('public/seeds/users/benji.jpg', 'r'),
dagschotel: Product.first,
},
{
uid: 'don',
avatar: File.new('public/seeds/users/don.jpg', 'r')
},
{
uid: 'silox',
avatar: File.new('public/seeds/users/silox.jpg', 'r')
}
]
users.each do |attr|
20.times do |i|
name = Faker::Name.name
User.create(
uid: attr[:uid],
provider: attr[:provider],
avatar: attr[:avatar],
dagschotel: attr[:dagschotel],
admin: attr[:admin] || false,
koelkast: attr[:koelkast] || false
uid: name,
avatar: Identicon.data_url_for(name)
)
end
# 50.times do |i|
# User.create(
# uid: "testUser#{i}",
# avatar: users[0][:avatar],
# )
# end

View file

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