diff --git a/app/assets/javascripts/user_avatar.js.coffee b/app/assets/javascripts/user_avatar.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/user_avatar.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/user_avatar.css.scss b/app/assets/stylesheets/user_avatar.css.scss new file mode 100644 index 0000000..d7e24de --- /dev/null +++ b/app/assets/stylesheets/user_avatar.css.scss @@ -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/ diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb index ab0d9fe..e0beaa2 100644 --- a/app/controllers/callbacks_controller.rb +++ b/app/controllers/callbacks_controller.rb @@ -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) diff --git a/app/controllers/user_avatar_controller.rb b/app/controllers/user_avatar_controller.rb new file mode 100644 index 0000000..4209f3e --- /dev/null +++ b/app/controllers/user_avatar_controller.rb @@ -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 diff --git a/app/helpers/user_avatar_helper.rb b/app/helpers/user_avatar_helper.rb new file mode 100644 index 0000000..52a0ddd --- /dev/null +++ b/app/helpers/user_avatar_helper.rb @@ -0,0 +1,2 @@ +module UserAvatarHelper +end diff --git a/app/models/user.rb b/app/models/user.rb index 0add1a3..0b0fc17 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 } diff --git a/app/views/user_avatar/new.html.erb b/app/views/user_avatar/new.html.erb new file mode 100644 index 0000000..605dd68 --- /dev/null +++ b/app/views/user_avatar/new.html.erb @@ -0,0 +1,10 @@ +