Merge pull request #34 from ZeusWPI/clean_user_registration

Replace multistep registration by default avatar from identicon
This commit is contained in:
benji 2015-03-23 12:01:34 +01:00
commit c58c8781b6
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 'coveralls', require: false
gem 'omniauth-oauth2' gem 'omniauth-oauth2'
gem 'identicon'

View file

@ -79,6 +79,7 @@ GEM
rack (>= 1.0.0) rack (>= 1.0.0)
rack-test (>= 0.5.4) rack-test (>= 0.5.4)
xpath (~> 2.0) xpath (~> 2.0)
chunky_png (1.3.4)
climate_control (0.0.3) climate_control (0.0.3)
activesupport (>= 3.0) activesupport (>= 3.0)
cocaine (0.5.5) cocaine (0.5.5)
@ -121,6 +122,8 @@ GEM
hashie (3.4.0) hashie (3.4.0)
hike (1.2.3) hike (1.2.3)
i18n (0.7.0) i18n (0.7.0)
identicon (0.0.3)
chunky_png
jbuilder (2.2.6) jbuilder (2.2.6)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
@ -286,6 +289,7 @@ DEPENDENCIES
coveralls coveralls
devise devise
faker (= 1.4.2) faker (= 1.4.2)
identicon
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
launchy 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 class CallbacksController < Devise::OmniauthCallbacksController
def zeuswpi def zeuswpi
@user = User.from_omniauth(request.env["omniauth.auth"]) @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 sign_in_and_redirect @user
else
flash[:error] = "Please complete your profile first."
session[:id] = @user.id
redirect_to new_user_avatar_path
end
end end
def after_omniauth_failure_path_for(scope) 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 # encrypted_password :string
# #
require 'identicon'
class User < ActiveRecord::Base class User < ActiveRecord::Base
devise :trackable, :omniauthable, :omniauth_providers => [:zeuswpi] 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_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium
has_many :orders, -> { includes :products } 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| where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider user.provider = auth.provider
user.uid = auth.uid user.uid = auth.uid
user.avatar = Identicon.data_url_for auth.uid
end end
end end
@ -53,10 +54,6 @@ class User < ActiveRecord::Base
self.uid self.uid
end end
def nickname=(name)
self.uid = name
end
def debt def debt
self.debt_cents / 100.0 self.debt_cents / 100.0
end 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. # providers.
uid{ raw_info['username'] } uid{ raw_info['username'] }
info do
{
# :nickname => raw_info['username'],
}
end
extra do extra do
{ {
'raw_info' => raw_info 'raw_info' => raw_info

View file

@ -5,6 +5,8 @@
# #
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first) # Mayor.create(name: 'Emanuel', city: cities.first)
require 'faker'
require 'identicon'
DEFAULT_PASSWORD = "password" DEFAULT_PASSWORD = "password"
products = [ 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] Product.create name: attr[:name], price: attr[:price], category: attr[:category], stock: attr[:stock], avatar: attr[:avatar]
end end
users = [ 20.times do |i|
{ name = Faker::Name.name
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|
User.create( User.create(
uid: attr[:uid], uid: name,
provider: attr[:provider], avatar: Identicon.data_url_for(name)
avatar: attr[:avatar],
dagschotel: attr[:dagschotel],
admin: attr[:admin] || false,
koelkast: attr[:koelkast] || false
) )
end 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