Add user avatar after user creation
This commit is contained in:
parent
7a5b1f20dd
commit
3ecb2b53d8
10 changed files with 91 additions and 5 deletions
3
app/assets/javascripts/user_avatar.js.coffee
Normal file
3
app/assets/javascripts/user_avatar.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/user_avatar.css.scss
Normal file
3
app/assets/stylesheets/user_avatar.css.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// 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/
|
|
@ -1,8 +1,15 @@
|
|||
class CallbacksController < Devise::OmniauthCallbacksController
|
||||
def zeuswpi
|
||||
@user = User.from_omniauth(request.env["omniauth.auth"])
|
||||
flash[:success] = "Logged in successfuly"
|
||||
sign_in_and_redirect @user
|
||||
@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
|
||||
end
|
||||
|
||||
def after_omniauth_failure_path_for(scope)
|
||||
|
|
26
app/controllers/user_avatar_controller.rb
Normal file
26
app/controllers/user_avatar_controller.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
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."
|
||||
sign_in_and_redirect @user
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticate_session_user!
|
||||
redirect_to root_path unless session[:id]
|
||||
@user = User.find session[:id]
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:avatar)
|
||||
end
|
||||
end
|
2
app/helpers/user_avatar_helper.rb
Normal file
2
app/helpers/user_avatar_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module UserAvatarHelper
|
||||
end
|
|
@ -36,9 +36,9 @@ class User < ActiveRecord::Base
|
|||
has_many :products, through: :orders
|
||||
belongs_to :dagschotel, class_name: 'Product'
|
||||
|
||||
# validates_attachment :avatar,
|
||||
# presence: true,
|
||||
# content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
||||
validates_attachment :avatar,
|
||||
presence: true,
|
||||
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
||||
|
||||
scope :members, -> { where koelkast: false }
|
||||
|
||||
|
|
10
app/views/user_avatar/new.html.erb
Normal file
10
app/views/user_avatar/new.html.erb
Normal file
|
@ -0,0 +1,10 @@
|
|||
<h2>Add avatar to <%= @user.uid %></h2>
|
||||
<%= render 'flash' %>
|
||||
|
||||
<%= f_form_for @user, url: '/user_avatar', method: :post do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<%= f.file_field :avatar %>
|
||||
|
||||
<%= f.submit "Update" %>
|
||||
<% end %>
|
|
@ -22,6 +22,8 @@ Rails.application.routes.draw do
|
|||
get 'dagschotel/:product_id' => 'users#update_dagschotel', as: 'dagschotel'
|
||||
end
|
||||
|
||||
resources :user_avatar
|
||||
|
||||
resources :products do
|
||||
collection do
|
||||
get 'stock' => 'products#stock', as: 'stock'
|
||||
|
|
26
config/secrets.yml
Normal file
26
config/secrets.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Your secret key is used for verifying the integrity of signed cookies.
|
||||
# If you change this key, all old signed cookies will become invalid!
|
||||
|
||||
# Make sure the secret is at least 30 characters and all random,
|
||||
# no regular words or you'll be exposed to dictionary attacks.
|
||||
# You can use `rake secret` to generate a secure secret key.
|
||||
|
||||
# Make sure the secrets in this file are kept private
|
||||
# if you're sharing your code publicly.
|
||||
|
||||
development:
|
||||
secret_key_base: 5d40610321e19e4f71ee2ba8af4f426fe15096c405da3800c6b33bed6779f2d11f55a0edc455974b19a01fd71f6cd508dba980305dbc55ff82521a2d12f891d8
|
||||
omniauth_client_id: tomtest
|
||||
omniauth_client_secret: blargh
|
||||
|
||||
test:
|
||||
secret_key_base: 961437e28e7d6055ffaad9cf1f8d614354f57f10cb2d7601c9d6ede72a03b9c9535ad9e63507e3eb31252c4895970a63117493408f2e9a46c7a0c4a5a7836b81
|
||||
|
||||
# Do not keep production secrets in the repository,
|
||||
# instead read values from the environment.
|
||||
production:
|
||||
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
||||
omniauth_client_id: ""
|
||||
omniauth_client_secret: ""
|
7
test/controllers/user_avatar_controller_test.rb
Normal file
7
test/controllers/user_avatar_controller_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UserAvatarControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in a new issue